ACM- Color the ball
来源:互联网 发布:js获取所有a标签 编辑:程序博客网 时间:2024/06/05 20:45
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,输入结束。 Output 每个测试实例输出一行,包括N个整数,第I个数代表第I个气球总共被涂色的次数。 Sample Input Sample Output
当N = 0,输入结束。
31 12 23 331 11 21 30
1 1 13 2 1
#include <iostream>#include <stdio.h>#include<string.h>using namespace std;struct node{int l, r, mark;}a[500000];int k, n;void set(int l,int r,int i){a[i].l = l;a[i].r = r;a[i].mark = 0;if (l == r){return;}int mid = (l + r) / 2;set(l, mid, i * 2);set(mid + 1, r, i * 2 + 1);}void move(int i){a[2 * i].mark += a[i].mark;a[i * 2 + 1].mark += a[i].mark;//要向下加,直接覆盖会错a[i].mark = 0;}void add(int l, int r, int i){if (a[i].r == a[i].l){a[i].mark += 1;return;}if (a[i].r == r&&a[i].l==l){a[i].mark += 1;return;}if (a[i].mark)move(i);//下移int mid = (a[i].r + a[i].l) / 2;if (mid >= r)add(l, r, i * 2);else if (mid < l)add(l, r, i * 2 + 1);else add(l, mid, i * 2), add(mid + 1, r, i * 2 + 1);}void find(int l, int r, int i){if (a[i].r == a[i].l){k++;cout <<a[i].mark;if (k != n)cout << " ";return;}if (a[i].mark)move(i);int mid = (a[i].r + a[i].l) / 2;if (mid >= r)find(l, r, i * 2);else if (mid < l)find(l, r, i * 2 + 1);else find(l, mid, i * 2), find(mid + 1, r, i * 2 + 1);}int main(){while (cin >> n, n){set(1, n, 1);k = 0;for (int i = 0; i < n; i++){int x, y;cin >> x >> y;add(x, y, 1);}find(1, n, 1);cout << endl;}return 0;}
1 0
- ACM- Color the ball
- hdu1556 color the ball
- HDOJ Color the ball
- Color the ball
- Color the Ball
- hdu1556 Color the ball
- hdu1556 Color the ball
- hdu_1556 Color the ball
- hdu1556 Color the ball
- Color the ball----HDOJ1556
- HDU1556 Color the ball
- Color the ball
- Color the ball
- hdu1556 Color the ball
- hdu1556--Color the ball
- HDU_1556 Color the ball
- Color the ball HDU1556
- HDU1556 Color the ball
- MyBatis初识
- LeetCode 461 Hamming Distance
- Linux——死锁
- fullcalendar在dayclick中获取当前点击日期中的events
- poj 2299 Ultra-QuickSort(归并排序)||(树状数组+离散化)
- ACM- Color the ball
- win10下运行.sh文件
- java线程中run和start的区别
- 局部权重线性回归(Locally weighted linear regression)
- CodeForces
- git 使用——关于使用指令hexo d 出现一大串waring以及无法成功部署到github的解决办法
- javascript基本概念的联系与区别
- Doctype作用?DTD是啥?标准模式与兼容模式各有什么区别-
- nyoj 42 一笔画问题