http://acm.hdu.edu.cn/showproblem.php?pid=1698
View Code
1 #include <iostream> 2 #include<cstdio> 3 #include<string.h> 4 using namespace std; 5 #define max 100000 6 int s[max*4],te[max*4]; 7 void pushup(int w) 8 { 9 s[w] = s[2*w]+s[2*w+1]; 10 } 11 void pushdown(int w,int m) 12 { 13 if(te[w]) 14 { 15 te[2*w] = te[2*w+1] = te[w]; 16 s[2*w] = (m-m/2)*te[w]; 17 s[2*w+1] = te[w]*(m/2); 18 te[w] =0; 19 } 20 } 21 void build(int l,int r,int w) 22 { 23 te[w] = 0; 24 if(l==r) 25 { 26 s[w] = 1; 27 return ; 28 } 29 int m = (l+r)/2; 30 build(l,m,2*w); 31 build(m+1,r,2*w+1); 32 pushup(w); 33 } 34 void update(int a,int b,int c,int l,int r,int w) 35 { 36 if(a<=l&&b>=r) 37 { 38 te[w] = c; 39 s[w]=c*(r-l+1); 40 return ; 41 } 42 pushdown(w,r-l+1); 43 int m = (l+r)/2; 44 if(a<=m) 45 update(a,b,c,l,m,2*w); 46 if(b>m) 47 update(a,b,c,m+1,r,2*w+1); 48 pushup(w); 49 } 50 int main() 51 { 52 int i,j,k =0 ,t,n,m,a,b,c; 53 scanf("%d",&t); 54 while(t--) 55 { 56 k++; 57 scanf("%d",&n); 58 build(1,n,1); 59 scanf("%d",&m); 60 while(m--) 61 { 62 scanf("%d%d%d",&a,&b,&c); 63 update(a,b,c,1,n,1); 64 } 65 printf("Case %d: The total value of the hook is ",k); 66 printf("%d.\n",s[1]); 67 } 68 return 0; 69 }