【HDU1556-color the ball】(树状数组)
来源:互联网 发布:梦幻西游数据错误 编辑:程序博客网 时间:2024/06/07 10:38
N个气球排成一排,从左到右依次编号为1,2,3….N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽”牌电动车从气球a开始到气球b依次给每个气球涂一次颜色。但是N次以后lele已经忘记了第I个气球已经涂过几次颜色了,你能帮他算出每个气球被涂过几次颜色吗?
Input
每个测试实例第一行为一个整数N,(N <= 100000).接下来的N行,每行包括2个整数a b(1 <= a <= b <= N)。
当N = 0,输入结束。
Output
每个测试实例输出一行,包括N个整数,第I个数代表第I个气球总共被涂色的次数。
Sample Input
3
1 1
2 2
3 3
3
1 1
1 2
1 3
0
Sample Output
1 1 1
3 2 1
#include<stdio.h> #include<string.h>#define lowerBit(x) (x&(-x))int num[100010];int N;void Add(int x,int y){ while(x<=N) { num[x]+=y; x=x+lowerBit(x); }}int Sum(int x){ int sum=0; while(x>0) { sum+=num[x]; x-=lowerBit(x); } return sum;}int main(){ int a,b; int m; while(scanf("%d",&N),N) { memset(num,0,sizeof(num)); m=N; while(m--) { scanf("%d%d",&a,&b); Add(a,1); Add(b+1,-1); } for(int i=1;i<=N;i++) { printf("===%d===\n",num[i]); } for(int i=1;i<N;i++) { printf("%d ",Sum(i)); } printf("%d\n",Sum(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 (树状数组)
- 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
- Axure RP8 教程 :基础元件
- 代理模式
- 最长公共子序列学习篇。动态规划
- spring mvc 内外部视图
- xxxxxxxxxx
- 【HDU1556-color the ball】(树状数组)
- A. Counting Kangaroos is Fun----暴力
- (原创)clang的python接口(一)
- spark-1.2.0 集群环境搭建(完整一套)
- wordpress开发
- spring事务的更新丢失
- [编程题] 消除重复元素
- codeforces 831A Unimodal Array
- Android Selector选择器点击按下之后没有出现预想的效果