标签:des style blog http color java os io
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 17214 Accepted Submission(s): 8600
1 #include<cstdio> 2 #include<cstring> 3 #include<stdlib.h> 4 #include<algorithm> 5 using namespace std; 6 const int MAXN=100000+10; 7 struct node 8 { 9 int l,r; 10 int num; 11 int col; 12 int mid() 13 { 14 return (l+r)/2; 15 } 16 }a[MAXN*4]; 17 18 void pushup(int step) 19 { 20 a[step].num=a[step*2].num+a[step*2+1].num; 21 } 22 23 int pushdown(int x,int step) 24 { 25 if(a[step].col) 26 { 27 a[step*2].col=a[step*2+1].col=a[step].col; 28 a[step*2].num=(x-x/2)*a[step].col; 29 a[step*2+1].num=(x/2)*a[step].col; 30 a[step].col=0; 31 } 32 } 33 34 void btree(int l,int r,int step) 35 { 36 a[step].l=l; 37 a[step].r=r; 38 a[step].col=0; 39 if(l==r) 40 { 41 a[step].num=1; 42 return ; 43 } 44 int mid=a[step].mid(); 45 btree(l,mid,step*2); 46 btree(mid+1,r,step*2+1); 47 pushup(step); 48 } 49 50 void ptree(int l,int r,int val,int step) 51 { 52 if(l<=a[step].l&&a[step].r<=r) 53 { 54 a[step].col=val; 55 a[step].num=(a[step].r-a[step].l+1)*val; 56 return ; 57 } 58 pushdown(a[step].r-a[step].l+1,step); 59 int mid=a[step].mid(); 60 if(l>mid) 61 ptree(l,r,val,step*2+1); 62 else if(r<=mid) 63 ptree(l,r,val,step*2); 64 else 65 { 66 ptree(l,r,val,step*2); 67 ptree(l,r,val,step*2+1); 68 } 69 pushup(step); 70 } 71 int main() 72 { 73 int kase,cnt=0,ans; 74 scanf("%d",&kase); 75 while(kase--) 76 { 77 int n,Q; 78 scanf("%d %d",&n,&Q); 79 btree(1,n,1); 80 while(Q--) 81 { 82 int x,y,z; 83 scanf("%d %d %d",&x,&y,&z); 84 ptree(x,y,z,1); 85 } 86 printf("Case %d: The total value of the hook is %d.\n",++cnt,a[1].num); 87 } 88 return 0; 89 }
HDU 1698 Just a Hook (线段树,区间更新),布布扣,bubuko.com
HDU 1698 Just a Hook (线段树,区间更新)
标签:des style blog http color java os io
原文地址:http://www.cnblogs.com/clliff/p/3901544.html