1 #include <iostream> 2 #include <cstdio> 3 4 using namespace std; 5 6 struct Node 7 { 8 int l; 9 int r; 10 int sum; 11 int lz; 12 }bn[400000]; 13 14 void build(int k,int l,int r) 15 { 16 bn[k].l=l; 17 bn[k].r=r; 18 bn[k].lz=0; 19 if(l==r) 20 { 21 bn[k].sum=1; 22 return ; 23 } 24 int lk=k*2; 25 int rk=lk+1; 26 int mid=(l+r)/2; 27 build(lk,l,mid); 28 build(rk,mid+1,r); 29 bn[k].sum=bn[lk].sum+bn[rk].sum; 30 } 31 32 void push(int k) 33 { 34 int lk=k*2; 35 int rk=lk+1; 36 bn[lk].sum=(bn[lk].r-bn[lk].l+1)*bn[k].lz; 37 bn[rk].sum=(bn[rk].r-bn[rk].l+1)*bn[k].lz; 38 bn[lk].lz=bn[k].lz; 39 bn[rk].lz=bn[k].lz; 40 bn[k].lz=0; 41 } 42 43 void change(int k,int l,int r,int a) 44 { 45 if(bn[k].l==l&&bn[k].r==r) 46 { 47 bn[k].sum=a*(bn[k].r-bn[k].l+1); 48 bn[k].lz=a; 49 return ; 50 } 51 if(bn[k].lz) 52 push(k); 53 int lk=k*2; 54 int rk=lk+1; 55 if(bn[lk].r>=r) 56 change(lk,l,r,a); 57 else if(bn[rk].l<=l) 58 change(rk,l,r,a); 59 else 60 { 61 change(lk,l,bn[lk].r,a); 62 change(rk,bn[rk].l,r,a); 63 } 64 bn[k].sum=bn[lk].sum+bn[rk].sum; 65 } 66 67 int main() 68 { 69 int t; 70 cin>>t; 71 for(int l=1;l<=t;l++) 72 { 73 int n; 74 scanf("%d",&n); 75 build(1,1,n); 76 int s; 77 scanf("%d",&s); 78 while(s--) 79 { 80 int a,b,c; 81 scanf("%d%d%d",&a,&b,&c); 82 change(1,a,b,c); 83 } 84 cout<<"Case "<<l<<": The total value of the hook is "; 85 cout<<bn[1].sum<<'.'<<endl; 86 } 87 return 0; 88 }