HDU-1556-Color the ball-线段树+区间更新+单点查询
来源:互联网 发布:农业大数据应用 编辑:程序博客网 时间:2024/05/01 07:25
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1556
好吧,一道这么简单的题结果因为我的粗心卡了一下午。。。orz....
#include<iostream>#include<string>#include<cstdio>#include<cstring>#include<queue>#include<map>#include<cmath>#include<stack>#include<set>#include<vector>#include<algorithm>#define LL long long#define inf 1<<30using namespace std;const int N=200005;int n;struct node{ int l,r; int v,lazy;}node[N<<2];void PushDown(int rt){ node[rt<<1|1].v+=node[rt].lazy; node[rt<<1].v+=node[rt].lazy; node[rt<<1|1].lazy+=node[rt].lazy; node[rt<<1].lazy+=node[rt].lazy; node[rt].lazy=0;}void build(int l,int r,int rt){ node[rt].l=l; node[rt].r=r; node[rt].v=0; node[rt].lazy=0; if(l==r) return; int mid=(l+r)>>1; build(l,mid,rt<<1); build(mid+1,r,rt<<1|1);}void Insert(int l,int r,int rt){ int ll=node[rt].l,rr=node[rt].r; if(ll==l&&rr==r){ node[rt].v+=1; node[rt].lazy+=1; return; } if(node[rt].lazy) PushDown(rt); int mid=(ll+rr)>>1; if(r<=mid) Insert(l,r,rt<<1); else if(l>mid) Insert(l,r,rt<<1|1); else{ Insert(l,mid,rt<<1); Insert(mid+1,r,rt<<1|1); }}LL query(int p,int rt){ int ll=node[rt].l,rr=node[rt].r; if(ll==rr&&ll==p){ return node[rt].v; } if(node[rt].lazy) PushDown(rt); int mid=(ll+rr)>>1; if(p>mid) return query(p,rt<<1|1); else if(p<=mid) return query(p,rt<<1);}int main(){ int a,b; while(~scanf("%d",&n)&&n){ build(1,n,1); for(int i=0;i<n;i++){ scanf("%d%d",&a,&b); Insert(a,b,1); } for(int i=1;i<n;i++){ printf("%lld ",query(i,1)); } printf("%lld\n",query(n,1)); } return 0;}
0 0
- HDU-1556-Color the ball-线段树+区间更新+单点查询
- hdu 1556 Color the ball(线段树 区间更新单点查询)
- HDu 1556 Color the ball【线段树&&树状数组】区间更新,单点查询
- HDU.1556 Color the ball (线段树 区间更新 单点查询)
- hdu 1556 Color the ball(线段树区间更新单点查询+懒惰标记)
- HDU 1556 Color the ball [区间更新+单点查询]
- HDU 1556 Color the ball(线段树区间更新区间查询模板)
- HDU 1556 Color the ball 线段树更新区间查点
- HDU - 1556 Color the ball (线段树 + 区间更新)
- HDU 1556 Color the ball 线段树 区间更新
- HDU 1556 Color the ball(线段树区间更新)
- HDU 1556 Color the ball(线段树区间更新)
- HDU 1556-Color the ball(线段树区间更新)
- HDU 1556 Color the ball【线段树区间更新,一次查询+数组模拟】
- hdu 1556 Color the ball (区间跟新,单点查询)
- 线段树 (更新区间查询点)Color the ball
- hdu 1566 Color the ball(线段树区间更新)
- HDU 1156 Color the ball (线段树 区间更新)
- QGIS python开发手册
- 关于随机初始化局面BUG的改善探讨
- 【Android】Service学习之本地服务
- 常用网址
- linux安装安卓开发工具android studio
- HDU-1556-Color the ball-线段树+区间更新+单点查询
- log4j 配置文件 详解 + 实例 分析
- IOS视图位置可能变化解决问题
- 深入 char * ,char ** ,char a[ ] ,char *a[] 内核
- Linux设置共享目录
- JavaScript之验证提醒【升级版,高大上】
- MSRCR(Multi-Scale Retinex with Color Restore)多尺度Retinex图像增强
- 【Android】开机自启动Service
- java定时任务嵌套