HDU 1698 Just a Hook (线段树,区间更新)
2014-08-09 20:36
351 查看
Just a Hook
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 17214 Accepted Submission(s): 8600
[align=left]Problem Description[/align]
In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of the heroes. The hook is made up of several consecutive metallic sticks which are of the same length.
#include<cstdio> #include<cstring> #include<stdlib.h> #include<algorithm> using namespace std; const int MAXN=100000+10; struct node { int l,r; int num; int col; int mid() { return (l+r)/2; } }a[MAXN*4]; void pushup(int step) { a[step].num=a[step*2].num+a[step*2+1].num; } int pushdown(int x,int step) { if(a[step].col) { a[step*2].col=a[step*2+1].col=a[step].col; a[step*2].num=(x-x/2)*a[step].col; a[step*2+1].num=(x/2)*a[step].col; a[step].col=0; } } void btree(int l,int r,int step) { a[step].l=l; a[step].r=r; a[step].col=0; if(l==r) { a[step].num=1; return ; } int mid=a[step].mid(); btree(l,mid,step*2); btree(mid+1,r,step*2+1); pushup(step); } void ptree(int l,int r,int val,int step) { if(l<=a[step].l&&a[step].r<=r) { a[step].col=val; a[step].num=(a[step].r-a[step].l+1)*val; return ; } pushdown(a[step].r-a[step].l+1,step); int mid=a[step].mid(); if(l>mid) ptree(l,r,val,step*2+1); else if(r<=mid) ptree(l,r,val,step*2); else { ptree(l,r,val,step*2); ptree(l,r,val,step*2+1); } pushup(step); } int main() { int kase,cnt=0,ans; scanf("%d",&kase); while(kase--) { int n,Q; scanf("%d %d",&n,&Q); btree(1,n,1); while(Q--) { int x,y,z; scanf("%d %d %d",&x,&y,&z); ptree(x,y,z,1); } printf("Case %d: The total value of the hook is %d.\n",++cnt,a[1].num); } return 0; }
View Code
相关文章推荐
- HDU 1698 Just a Hook 线段树区间更新
- HDU-1698-Just a Hook(线段树 区间更新)
- (简单) HDU 1698 Just a Hook , 线段树+区间更新。
- HDU - 1698 - Just a Hook (线段树-成段更新)
- hdu 1698 Just a Hook 线段树区间更新
- hdu 1698 线段树区间更新
- hdu - 1698 - Just a Hook(线段树(区间更新))
- HDU 1698 【线段树区间更新】
- hdu 1698(区间更新线段树)Just a Hook
- POJ 2777 && ZOJ 1610 &&HDU 1698 --线段树--区间更新
- hdu 1698:Just a Hook(线段树,区间更新)
- 线段树区间更新——HDU 1698
- HDU 1698 (线段树 区间更新) Just a Hook
- HDU 1698 Just a Hook (线段树区间更新)
- HDU 1698 区间更新线段树
- HDU 1698-Just a Hook(线段树_区间更新+lazy标记)
- hdu 1698 Just a Hook 线段树区间更新
- HDU 1698 Just a Hook (线段树 区间更新基础)
- hdu 1698 Just a Hook(线段树-区间更新)
- 线段树(区间更新) hdu-1698-Just a Hook