hdu1556 Color the ball (区间修改)
来源:互联网 发布:粒子群算法代码 编辑:程序博客网 时间:2024/06/06 03:49
#include<algorithm>#include<string.h>#include<stdio.h>#define N 100000+20using namespace std;struct Nodes{ int l,r,sum,inc;}node[N<<2];void Build(int root,int l,int r){ node[root].l=l; node[root].r=r; node[root].sum=node[root].inc=0; if(l==r)return ; int mid=(l+r)>>1; Build(root<<1,l,mid); Build((root<<1)+1,mid+1,r);}void Update(int root,int l,int r,int inc){ if(l>node[root].r||r<node[root].l)return ; l=max(l,node[root].l); r=min(r,node[root].r); if(l==node[root].l&&r==node[root].r) { node[root].inc+=inc; return ; } node[root].sum+=(r-l+1)*inc; Update(root<<1,l,r,inc); Update((root<<1)+1,l,r,inc);}int Query(int root,int l,int r){ if(l>node[root].r||r<node[root].l)return 0; l=max(l,node[root].l); r=min(r,node[root].r); if(l==node[root].l&&r==node[root].r) return node[root].sum+node[root].inc*(r-l+1); int v=node[root].inc*(r-l+1); return Query(root<<1,l,r)+Query((root<<1)+1,l,r)+v;}int main(){ int n,t,l,r; while(scanf("%d",&n)&&n) { Build(1,1,n); t=n; while(t--) { scanf("%d%d",&l,&r); Update(1,l,r,1); } for(int i=1;i<=n-1;i++) printf("%d ",Query(1,i,i)); printf("%d\n",Query(1,n,n)); } return 0;}
0 0
- hdu1556 Color the ball (区间修改)
- hdu1556 Color the ball(树状数组 修改区间,查找值)
- hdu1556 Color the ball(线段树区间修改)
- hdu1556 color the ball
- hdu1556 Color the ball
- hdu1556 Color the ball
- hdu1556 Color the ball
- HDU1556 Color the ball
- hdu1556 Color the ball
- hdu1556--Color the ball
- Color the ball HDU1556
- HDU1556 Color the ball
- hdu1556 Color the ball
- HDU1556-----Color the ball
- hdu1556 Color the Ball
- HDU1556-color the ball
- HDU1556 Color the ball
- hdu1556 Color the ball
- 环境变量
- jprofiler安装图解及破解码
- C++中explicit关键字的作用
- C#中常用日期函数方法
- MySQL触发器的语法
- hdu1556 Color the ball (区间修改)
- Lucene实战
- 基于角色的权限设计(二)
- 小题
- memset(将一段内存空间填入某值)
- uCOS里的信号量错误笔记
- 《雨霖铃·寒蝉凄切》 柳永
- WPF应用Binding之数据转换
- Java Float与float的区别及instanceof的作用