hdu 1556 Color the ball(线段树+懒惰标记)
来源:互联网 发布:印象笔记导出为知笔记 编辑:程序博客网 时间:2024/05/17 02:39
Color the ball
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4961 Accepted Submission(s): 2624
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
Recommend
LL
思路:就是一道比较水的线段树,非常明显,我用上了懒惰节点。现在做就是为了重温一下线段树,一切都是自己重新码的。
#include<iostream>#include<cstring>#include<cstdio>#define lson t<<1#define rson t<<1|1#define midl (l+r)/2#define midr (l+r)/2+1using namespace std;const int mm=1e5+9;class node{ public:int l,r,lazy,ci;}rt[mm*4];int n;void build(int t,int l,int r){ rt[t].l=l;rt[t].r=r;rt[t].lazy=rt[t].ci=0; if(l==r)return; build(lson,l,midl);build(rson,midr,r);}void update(int t,int l,int r,int num){ if(rt[t].l==l&&rt[t].r==r){rt[t].ci+=num;rt[t].lazy+=num;return;} rt[lson].lazy+=rt[t].lazy;rt[rson].lazy+=rt[t].lazy; rt[lson].ci+=rt[t].lazy;rt[rson].ci+=rt[t].lazy; rt[t].lazy=0; if(rt[lson].r>=r)update(lson,l,r,rt[t].lazy+num); else if(rt[rson].l<=l)update(rson,l,r,rt[t].lazy+num); else update(lson,l,rt[lson].r,rt[t].lazy+num),update(rson,rt[rson].l,r,rt[t].lazy+num);}int query(int t,int id){ int ret; if(rt[t].l==rt[t].r&&rt[t].l==id)return rt[t].ci; rt[lson].lazy+=rt[t].lazy; rt[lson].ci+=rt[t].lazy; rt[rson].ci+=rt[t].lazy; rt[rson].lazy+=rt[t].lazy; rt[t].lazy=0; if(rt[lson].r>=id)ret=query(lson,id); else ret=query(rson,id); return ret;}int main(){ int a,b; while(scanf("%d",&n)&&n) { build(1,1,n); for(int i=0;i<n;++i) { scanf("%d%d",&a,&b); update(1,a,b,1); } printf("%d",query(1,1)); for(int i=2;i<=n;++i) printf(" %d",query(1,i)); printf("\n"); }}
- 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(线段树)
- HDU 1556 Color the ball(线段树)
- hdu 1556 Color the ball(线段树)
- Java 里面方法的形式;
- 【easyUI】<div class="easyui-panel" >
- mallet源码分析之bagging与boosting
- 面向对象
- Oracle PGA参数
- hdu 1556 Color the ball(线段树+懒惰标记)
- APUE学习笔记——第十三章 守护进程
- IIS HTTP 500 内部服务器错误 服务器无法加载应用程序 '/LM/W3SVC '找不到指定的元数据
- Service总结
- MDS中file layout初始化过程
- 循环
- Eclipse开发环境搭建
- SAX中止解析XML方法
- 直接选择排序