hdoj 1556 Color the ball
来源:互联网 发布:bet数据 作图 编辑:程序博客网 时间:2024/05/22 02:01
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): 9737 Accepted Submission(s): 5012
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<stdio.h>#include<string.h>int N,tree[100010];int lowbit(int n){return n&(-n);}void change_sum(int k,int num){ while(k<=N){ tree[k]+=num; k+=lowbit(k);}}int Sum(int k){int sum=0;while(k>0){sum+=tree[k];k-=lowbit(k);}return sum;}int main(){int i,j,k,a,b;while(scanf("%d",&N)&&N!=0){memset(tree,0,sizeof(tree));for(i=1;i<=N;i++){scanf("%d %d",&a,&b);change_sum(a,1);//关键是这里 change_sum(b+1,-1);//关键是这里 }for(i=1;i<=N;i++){printf("%d",Sum(i));if(i!=N)printf(" ");}printf("\n");}return 0;}
0 0
- HDOJ 1556 Color the ball
- HDOJ 1556 Color the ball
- HDOJ 1556 Color the ball
- Color the ball HDOJ--1556
- hdoj 1556 Color the ball
- HDOJ 1556 Color the ball
- HDOJ-1556 Color the ball
- HDOJ 1556 Color the ball
- hdoj-1556-Color the ball
- HDOJ Color the ball
- hdoj Color the ball
- HDoj-1556-Color the ball-树状数组
- hdoj 1556 Color the ball 【树状数组】
- hdoj 1556 Color the ball(树状数组)
- HDOJ Color the ball 1556【树状数组】
- hdoj 1556 Color the ball 【线段树】
- hdoj 1556 Color the ball <区间问题,>
- [HDOJ 1556] Color the ball(线段树成段更新入门)
- webbench 源码剖析
- Python set path
- 递归与分治
- Hibernate常见的集合映射 Set,List,Array,Map,Bag
- WinCE支持远程桌面功能
- hdoj 1556 Color the ball
- 国内最专业的三亚婚纱摄影工作室
- 【LeetCode】Search in Rotated Sorted Array 解题报告
- 感谢那一刻的安排
- 国外程序员整理的 C++ 资源大全
- EAS后台事物调度时间间隔所用的QuartZ Cron表达式解析。
- 排列组合
- javaweb中添加过滤器,限制访问某些页面
- 杭州小记 七 ——有道面试 第五天