HDOJ 1556 Color the ball
来源:互联网 发布:php数据统计模板 编辑:程序博客网 时间:2024/05/19 19:58
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<vector>using namespace std;int n;int a[100010];int lowbit(int t){ return t&(-t);}void update(int t, int d)//向下修改{ while (t<=n) { a[t] += d; t += lowbit(t);//得到改点t的父结点的值 }}long long getsum(int t)//向上统计{ long long sum(0); while (t>0) { sum += a[t]; t -= lowbit(t); } return sum;}//这种修改一个区间,而求每个点的修改次数的,一般都是向下修改,向上统计int main(){#ifdef ONLINE_JUDGE#else freopen("D:\\in.txt", "r", stdin); freopen("D:\\out.txt", "w", stdout);#endif int t1(0), t2(0); while (cin >> n) { if (n == 0) break; memset(a, 0, sizeof(a)); int m = n; while (m--) { cin >> t1 >> t2; update(t1, 1); update(t2+1, -1); } for (int i = 1; i < n; i++) cout << getsum(i) << " "; cout << getsum(n) << endl; } 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(线段树成段更新入门)
- 系统标准全局变量的使用-默认屏幕
- linux shell 延时
- XP任务管理器显示程序路径,显示进程路径的任务管理器
- Webbench安装
- 图片+文字水印
- HDOJ 1556 Color the ball
- UIButton 中,文字和图片共存
- php Socket 基础
- Linux基础------Shell数值计算的几种方法
- 做一个成功的研究生
- 教你如何识别黑心建站商家
- [置顶] 为自己加油!!!--ThoughtWorks面试后感
- Editor------------------PreferenceItem
- Spring的Annotation配置