题意:
给你一个1到n的区间有q次操作
每次操作把区间x~y替换成z
最开始每个区间值为1
求最后整个区间的和
裸的区间替换
ACcode:
#include <iostream>
#include <cstdio>
#include <cstring>
#define maxn 100011
#define mid ((l+r)>>1)
#define tmp (st<<1)
#define len (r-l+1)
#define lson l,mid,tmp
#define rson mid+1,r,tmp|1
#define push_up(x) sum[x]=sum[tmp]+sum[tmp|1]
using namespace std;
int sum[maxn<<2],col[maxn<<2];
inline void push_down(int st,int m){
if(col[st]){
col[tmp]=col[tmp|1]=col[st];
sum[tmp]=(m-(m>>1))*col[st];
sum[tmp|1]=(m>>1)*col[st];
col[st]=0;
}
}
inline void updata(int L,int R,int add,int l,int r,int st){
if(L<=l&&r<=R){
col[st]=add;
sum[st]=add*len;
return ;
}
push_down(st,len);
if(L<=mid)updata(L,R,add,lson);
if(R>mid)updata(L,R,add,rson);
push_up(st);
}
int main(){
ios::sync_with_stdio(false);
int loop,cnt=1;
cin>>loop;
while(loop--){
int n,q;
cin>>n>>q;
memset(col,0,sizeof(col));
updata(1,n,1,1,n,1);
while(q--){
int x,y,z;
cin>>x>>y>>z;
updata(x,y,z,1,n,1);
}
cout<<"Case "<<cnt++<<": The total value of the hook is "<<sum[1]<<".\n";
}
return 0;
}
/*
1
10
2
1 5 2
5 9 3
*/