/*
Just a Hook
线段树区间更新
区间求和
*/
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define lson (pos<<1)
#define rson (pos<<1|1)
const int maxn = 100005;
int cover[maxn << 2],sum[maxn << 2];
void pushdown(int pos,int l,int r){
if(cover[pos]){
int mid = (l + r) >> 1;
sum[lson] = cover[pos] * (mid - l + 1);
sum[rson] = cover[pos] * (r - mid);
cover[lson] = cover[rson] = cover[pos];
cover[pos] = 0;
}
}
void pushup(int pos){
sum[pos] = sum[lson] + sum[rson];
}
void build(int l,int r,int pos){
cover[pos] = 0;
if(l == r){
sum[pos] = 1;
return;
}
int mid = (l + r) >> 1;
build(l,mid,lson);
build(mid + 1,r,rson);
pushup(pos);
}
void update(int L,int R,int l,int r,int pos,int d){
if(l <= L && R <= r){
sum[pos] = (R - L + 1) * d;
cover[pos] = d;
return;
}
pushdown(pos,L,R);
int mid = (L + R) >> 1;
if(l <= mid)
update(L,mid,l,r,lson,d);
if(r > mid)
update(mid + 1,R,l,r,rson,d);
pushup(pos);
}
int main(){
int T,Case = 1;
scanf("%d",&T);
while(T--){
int n,m;
scanf("%d%d",&n,&m);
build(1,n,1);
for(int i = 0; i < m; i++){
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
update(1,n,x,y,1,z);
}
printf("Case %d: The total value of the hook is %d.\n",Case++,sum[1]);
}
return 0;
}
HDU 1698
最新推荐文章于 2022-12-12 21:12:45 发布