Color the ball - HDU 1556 - 线段树 区间更新单点查询
2017-05-28 11:22
537 查看
Color the ball - HDU 1556 - 线段树 区间更新单点查询
国际惯例中文题目不解释,思路直接裸线段树,Lazy思想入门题。Lazy传送门:延迟更新详解
AC代码:
// // main.cpp // L // // Created by LucienShui on 2017/5/28. // Copyright © 2017年 LucienShui. All rights reserved. // #include <iostream> #include <algorithm> #include <set> #include <string> #include <vector> #include <queue> #include <map> #include <iomanip> #include <cstdio> #include <cstring> #include <cmath> #include <cctype> #define memset(a,b) memset(a,b,sizeof(a)) #define il inline #define ll long long #define ull unsigned long long using namespace std; #define ls (u<<1) #define rs (u<<1|1) #define lson u<<1,l,mid #define rson u<<1|1,mid+1,r const int maxn = 100000+7; int node[maxn<<2]; void pushdown(int u) { node[ls] += node[u]; node[rs] += node[u]; node[u]=0; } void update(int u, int l, int r, int b, int e) { if(b <= l && r <= e) { node[u]++; return ; } if(node[u]!=0) pushdown(u); int mid = (l+r)>>1; if(e<=mid) update(lson,b,e); else if(b>mid) update(rson,b,e); else { update(lson,b,e); update(rson,b,e); } } int query(int u, int l, int r, int x) { if(l==r&&l==x) { return node[u]; } if(node[u]!=0) pushdown(u); int mid = (l+r)>>1; if(x<=mid) return query(lson,x); else return query(rson,x); } int main () { #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); #endif // ONLINE_JUDGE int n; while(scanf("%d",&n),n) { memset(node,0); for(int i=0,a,b ; i<n ; i++) { scanf("%d%d",&a,&b); update(1,1,n,a,b); } for(int i=1 ; i<n ; i++) { printf("%d ",query(1,1,n,i)); } printf("%d\n",query(1,1,n,n)); } return 0; }
相关文章推荐
- 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 给连续个球涂色-线段树-(区间更新,单点查询)
- HDu 1556 Color the ball【线段树&&树状数组】区间更新,单点查询
- HDU 1556 Color the ball (一维树状数组,区间更新,单点查询)
- Color the ball HDU - 1556 线段树区间更新点查询
- HDU 1556 Color the ball【线段树区间更新,一次查询+数组模拟】
- HDU 4819:单点更新,区间查询的二维线段树
- HDU-1166 敌兵布阵【简单线段树-单点更新+区间查询】
- hdu 1541 Stars(线段树单点更新,区间查询)
- HDU 2795 线段树(单点更新 区间查询)
- 线段树 HDU 4217 Data Structure? 单点更新 区间查询
- hdu 1556 Color the ball (区间跟新,单点查询)
- hdu 1166 敌兵布阵(线段树单点更新,区间查询)
- HDU 3874 Necklace (线段树单点更新+区间查询+离线操作)
- hdu 4046 Panda (线段树 单点更新 区间查询)