Color the ball
来源:互联网 发布:数据库行业前景 编辑:程序博客网 时间:2024/06/06 02:54
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): 13386 Accepted Submission(s): 6721
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,输入结束。
当N = 0,输入结束。
Output
每个测试实例输出一行,包括N个整数,第I个数代表第I个气球总共被涂色的次数。
Sample Input
31 12 23 331 11 21 30
Sample Output
1 1 13 2 1
Author
8600
#include <cstdio>//区间更新,求单点的值,树状数组的变形#include <cstring>int N;int d[100010];//d[x]数组用来存储a[x]-a[n]的刷新次数;此时的Sum(i)为d[1]+....+d[i];int bit(int t){ return t&(-t);}void update(int pos,int num){ while(pos<=N){ d[pos]+=num; pos+=bit(pos); }}int Sum(int pos){ int sum=0; while(pos>0){ sum+=d[pos]; pos-=bit(pos); } return sum;}int main(){ while(scanf("%d",&N)!=EOF){ if(N==0)break; memset(d,0,sizeof(d)); int a,b; for(int i=0;i<N;i++){ scanf("%d%d",&a,&b); update(a,1); update(b+1,-1); } printf("%d",Sum(1)); for(int i=2;i<=N;i++) printf(" %d",Sum(i)); printf("\n"); }}AC之路,我选择坚持~~
0 0
- hdu1556 color the ball
- HDOJ Color the ball
- Color the ball
- Color the Ball
- hdu1556 Color the ball
- hdu1556 Color the ball
- hdu_1556 Color the ball
- hdu1556 Color the ball
- Color the ball----HDOJ1556
- HDU1556 Color the ball
- Color the ball
- Color the ball
- hdu1556 Color the ball
- hdu1556--Color the ball
- HDU_1556 Color the ball
- Color the ball HDU1556
- HDU1556 Color the ball
- Color the ball
- 全景:RANSAC算法入门
- tableView的几种注册方式
- 汉诺塔之递归算法
- LineNumberReader的简单实例
- 404错误设置
- Color the ball
- Mysql字符串处理函数详细介绍、总结
- 设置窗体控件的透明度
- linux——创建用户及所属组总结
- 绝对像素px和相对像素dp的转换
- 动态代理
- android studio 常用快捷键集合
- Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment vari
- 查找(顺序,有序)总结