1 #include<cstdio> 2 #include<cstring> 3 #define MAXN 100010 4 int tree[MAXN<<2],lazy[MAXN<<2]; 5 inline void PushUp(int rt) 6 { 7 tree[rt]=tree[rt<<1]+tree[rt<<1|1]; 8 } 9 void Build(int L,int R,int rt) 10 { 11 lazy[rt]=0; 12 if(L==R) 13 tree[rt]=1; 14 else 15 { 16 int mid=(L+R)>>1; 17 Build(L,mid,rt<<1); 18 Build(mid+1,R,rt<<1|1); 19 PushUp(rt); 20 } 21 } 22 inline void PushDown(int mid,int L,int R,int rt) 23 { 24 lazy[rt<<1]=lazy[rt<<1|1]=lazy[rt]; 25 tree[rt<<1]=(mid-L+1)*lazy[rt]; 26 tree[rt<<1|1]=(R-mid)*lazy[rt]; 27 lazy[rt]=0; 28 } 29 void Update(int x,int y,int z,int L,int R,int rt) 30 { 31 if(x<=L&&R<=y) 32 { 33 lazy[rt]=z; 34 tree[rt]=(R-L+1)*z; 35 } 36 else 37 { 38 int mid=(L+R)>>1; 39 if(lazy[rt]) 40 PushDown(mid,L,R,rt); 41 if(mid>=x) 42 Update(x,y,z,L,mid,rt<<1); 43 if(y>mid) 44 Update(x,y,z,mid+1,R,rt<<1|1); 45 PushUp(rt); 46 } 47 } 48 int main() 49 { 50 int c,n,q,x,y,z,ca=1; 51 scanf("%d",&c); 52 while(c--) 53 { 54 scanf("%d%d",&n,&q); 55 Build(1,n,1); 56 while(q--) 57 { 58 scanf("%d%d%d",&x,&y,&z); 59 Update(x,y,z,1,n,1); 60 } 61 printf("Case %d: The total value of the hook is %d.\n",ca++,tree[1]); 62 } 63 return 0; 64 }
![](https://img2024.cnblogs.com/blog/35695/202408/35695-20240826070647288-243310440.jpg)