标签:sum ota cal hdu -- and hang out case
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 32141 Accepted Submission(s):
15804
1 #include<cstdio> 2 #define lson l,m,rt<<1 3 #define rson m+1,r,rt<<1|1 4 const int MAXN = 100100; 5 int sum[MAXN<<2]; 6 int col[MAXN<<2]; 7 int t,n,q; 8 void putup(int rt) 9 { 10 sum[rt] = sum[rt<<1]+sum[rt<<1|1]; 11 } 12 void putdown(int rt,int m) 13 { 14 if (col[rt]) 15 { 16 col[rt<<1] = col[rt<<1|1] = col[rt]; 17 sum[rt<<1] = (m-(m>>1))*col[rt]; 18 sum[rt<<1|1] = (m>>1)*col[rt]; 19 col[rt] = 0; 20 } 21 } 22 void build(int l,int r,int rt) 23 { 24 col[rt] = 0; 25 sum[rt] = 1; 26 if (l==r) return ; 27 int m = (l+r)>>1; 28 build(lson); 29 build(rson); 30 putup(rt); 31 } 32 void update(int l,int r,int rt,int L,int R,int c) 33 { 34 if (L<=l && r<=R) 35 { 36 col[rt] = c; 37 sum[rt] = c*(r-l+1); 38 return ; 39 } 40 putdown(rt,r-l+1); 41 int m = (l+r)>>1; 42 if (L<=m) update(lson,L,R,c); 43 if (R>m) update(rson,L,R,c); 44 putup(rt); 45 } 46 int main() 47 { 48 scanf("%d",&t); 49 for (int i=1; i<=t; ++i) 50 { 51 scanf("%d%d",&n,&q); 52 build(1,n,1); 53 while (q--) 54 { 55 int x,y,z; 56 scanf("%d%d%d",&x,&y,&z); 57 update(1,n,1,x,y,z); 58 } 59 printf("Case %d: The total value of the hook is %d.\n",i,sum[1]); 60 } 61 return 0; 62 }
标签:sum ota cal hdu -- and hang out case
原文地址:http://www.cnblogs.com/mjtcn/p/7054762.html