Hdu--1556--Color the ball(树状数组最简单运用)
来源:互联网 发布:兴趣部落签到软件 编辑:程序博客网 时间:2024/06/04 04:54
Color the ball
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 5851 Accepted Submission(s): 3116
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#include<iostream> #include<cstring>using namespace std; int tree[100100]; int maxn; void update(int k,int v) //(1,1) { while(k<=maxn) { tree[k]+=v; int t=tree[k]; // printf("tree[%d]=%d\n",k,t); k+=k&-k; // k = k*2; //printf("k=%d\n",k); // printf("\n"); } } int read(int k)//ÇóÇø¼ä1µ½kµÄºÍÖµ { int sum=0; while(k>0) { //printf("k111111=%d\n",k); sum+=tree[k]; // printf("summmmmm=%d\n",sum); k-=k&-k; // printf("k2222222=%d\n",k); // printf("\n"); } return sum; } int main() { int i,a,b,temp; while(scanf("%d",&maxn)&&maxn) { temp=maxn; memset(tree,0,sizeof(tree)); while(temp--) { scanf("%d%d",&a,&b); update(a,1); update(b+1,-1); } for(i=1;i<=maxn;i++) { printf("%d",read(i)); if(i!=maxn) printf(" "); else printf("\n"); } } return 0; }
- Hdu--1556--Color the ball(树状数组最简单运用)
- HDU-1556 Color the ball 简单树状数组
- Color the ball - HDU 1556 简单树状数组
- 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 the ball(树状数组)
- HDU I NEED A OFFER!
- 自动装箱和拆箱 枚举 反射 数组反射的应用。ArrayList和HashSet
- 关于VMware虚拟机下ubuntu的安装
- 编译Eclipse hadoop插件
- conv2,filter2,imfilter的区别
- Hdu--1556--Color the ball(树状数组最简单运用)
- 解决Hadoop0.21.0 HDFS/MapReduce编译错误(ivy-resolve-common does not find hadoop-commo)
- 替换Android主界面
- UVa 10050 Hartals(优先队列)
- Sprite Kit编程指南(2)-使用精灵
- RCP 视图间通信:SWT Canvas向JFace ViewPart发送消息
- Android平台Native开发与JNI机制详解
- tomcat下集成quartz任务调度
- ORACLE的锁机制