【HDU1556】Color the ball(树状数组)
来源:互联网 发布:天刀的策划和美工 编辑:程序博客网 时间:2024/06/06 14:06
题:http://acm.hdu.edu.cn/showproblem.php?pid=1556
Color the ball
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 23119 Accepted Submission(s): 11224
Problem Description
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>int num[100010];int a,b,n;void UpDate(int x,int y){ while(x<=n) { num[x]+=y; x+=x&(-x); }}int Sum(int x){ int sum=0; while(x>0) { sum+=num[x]; x-=x&(-x); } return sum;}int main(){ while(~scanf("%d",&n),n) { memset(num,0,sizeof(num)); for(int i=1;i<=n;i++) { scanf("%d%d",&a,&b); UpDate(a,1); //从a到n都加一 UpDate(b+1,-1); //只要到b加一,所以b之后的都减一 } 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
- js添加删除文本框
- Java常用十种设计模式及总结
- PageRank算法与特征向量和特征值(eigenvector和eigenvalue)
- VS中后期生成事件简单示例
- caffe学习:绘制网络模型
- 【HDU1556】Color the ball(树状数组)
- spring MVC form表单提交用RequestMethod.POST报错 : Request method 'GET' not supported
- PlayerPrefs的使用
- 钢笔、电梯、纸杯、桌子、洗衣机测试
- 使用alter命令向sqlite中添加外键
- redis的事务和watch
- unity 中Deferred Lighting (延迟光照)
- 多线程并发下载
- SQL 92连表99连表