Color the ball(树状数组之插点问线问题)
来源:互联网 发布:js如何验证手机号码 编辑:程序博客网 时间:2024/05/18 02:26
Color the ball
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 11734 Accepted Submission(s): 5872
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
Source
HDU 2006-12 Programming Contest
#include<cstdio>#include<iostream>#include<cstring>using namespace std;int maxn[100010],n;int lowbit(int n){ return n&(-n);}void add(int i,int value){ while(i<=n) { maxn[i]+=value; i+=lowbit(i); }}int sum(int x){ int s=0; while(x>0)//注意 { s+=maxn[x]; x-=lowbit(x); } return s;}int main(){ int a,b,i; while(cin>>n&&n) { memset(maxn,0,sizeof(maxn)); for(i=0;i<n;i++) { cin>>a>>b; add(a,1); add(b+1,-1); } for(i=1;i<n;i++) { cout<<sum(i)<<" "; }//从1开始 cout<<sum(n)<<endl; }}
0 0
- Color the ball(树状数组之插点问线问题)
- Color the ball 树状数组水之
- Color the ball (树状数组)
- Color the ball(树状数组)
- Color the ball(树状数组)
- hdu1556 Color the ball(树状数组)
- Color the ball(树状数组)
- 【HDU1556】Color the ball(树状数组)
- 【HDU1556-color the ball】(树状数组)
- HDU1556 color the ball (树状数组)
- 树状数组&&Color the ball
- (树状数组)Color the ball
- hdu 1556 Color the ball(树状数组)
- HDOJ 题目1556Color the ball(树状数组)
- 杭电1556 Color the ball(树状数组)
- HDU 1556 Color the ball(树状数组)(填坑)
- hdoj 1556 Color the ball(线段树||树状数组)
- HDU 1556 Color the ball (树状数组简单应用)
- 【动态规划】【多重背包】[HDU 1291]悼念512汶川大地震遇难同胞――珍惜现在,感恩生活
- [一起学Hive]之七-向Hive表中加载数据
- 对于return new A();
- UICollectionViewController简单操作
- sgu-264. Travel
- Color the ball(树状数组之插点问线问题)
- 算法准备
- c语言中通过指针将数值赋值到制定内存地址
- delphi 控件 combobox常识
- 深入理解HTTP Session
- C常用的对数组操作的几个方法
- Git使用技巧(整理)三 实战
- Keil4 断点按钮为灰色解决方法
- [一起学Hive]之八-使用Hive命令行