HDU 1556 Color the ball
来源:互联网 发布:建一个淘宝白菜群佣金 编辑:程序博客网 时间:2024/05/01 22:48
Color the ball
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 8271 Accepted Submission(s): 4239
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 <iostream>#include <cstdio>#include <cstring>#define lowbit(x) x&(-x)#define Maxn 100005using namespace std;int tree[Maxn];void add(int pos,int n,int c){for(int i=pos;i<=n;i+=lowbit(i))tree[i]+=c;}int sum(int pos){int ans=0;for(int i=pos;i>0;i-=lowbit(i))ans+=tree[i];return ans;}int main(){int a,b,n;freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);while(scanf("%d",&n),n){memset(tree,0,sizeof(tree));for(int i=0;i<n;i++){scanf("%d%d",&a,&b);add(a,n,1),add(b+1,n,-1);}for(int i=1;i<=n;i++)printf("%d%c",sum(i),i==n?'\n':' ');}return 0;}
0 0
- hdu 1556 color the ball
- hdu 1556Color 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 ball
- HDU 1556 Color the ball
- HDU 1556 Color the ball
- Linux file system events with C, Python and Ruby
- 9.0 看门狗定时器WDT
- PopupWindow(一)
- 【HDU】1827 Summer Holiday 强连通缩点
- 编译原理 (预处理>编译>汇编>链接)
- HDU 1556 Color the ball
- Sicily.1264. Atomic Car Race
- Candy
- C#并行开发中的任务并行(一)
- Floyd 算法
- 算法导论——lec 06 堆排序
- import com.google.android.maps.MapView报错
- 快速排序时间复杂度数学证明
- 计数排序、基数排序与桶排序