#include<stdio.h>
#define N 100100
struct node {
int x,y,yanchi;
}a[N*4];//注意数组范围
void build(int t,int x,int y) {
a[t].x=x;
a[t].y=y;
a[t].yanchi=1;
if(x==y)
return ;
int temp=t<<1;
int mid=(x+y)/2;
build(temp,x,mid);
build(temp+1,mid+1,y);
}
void update(int t,int x,int y,int z) {
if(a[t].yanchi==z)
return ;
if(a[t].x==x&&a[t].y==y) {
a[t].yanchi=z;
return ;
}
int temp=t<<1;
if(a[t].yanchi!=-1) {
a[temp].yanchi=a[temp+1].yanchi=a[t].yanchi;
a[t].yanchi=-1;
}
int mid=(a[t].x+a[t].y)/2;
if(x>mid)
update(temp+1,x,y,z);
else
if(y<=mid)
update(temp,x,y,z);
else {
update(temp,x,mid,z);
update(temp+1,mid+1,y,z);
}
return ;
}
__int64 qury(int t) {
if(a[t].yanchi!=-1)
return (a[t].y-a[t].x+1)*a[t].yanchi;
else
return qury(t*2)+qury(t*2+1);
}
int main() {
int t,i,j,k,n,m,count=0;
scanf("%d",&t);
while(t--) {
scanf("%d",&n);
scanf("%d",&m);
build(1,1,n);
while(m--) {
scanf("%d%d%d",&i,&j,&k);
update(1,i,j,k);
}
printf("Case %d: The total value of the hook is %I64d.\n",++count,qury(1));//注意结果大小
}
return 0;
}
相关文章
- hdu 1541 Stars(线段树单点更新,区间查询)
- hdu 1556 Color the ball 线段树 区间更新
- hdu1556Color the ball线段树区间更新
- 线段树 + 区间更新 ----- HDU 4902 : Nice boat
- HDU1698 Just a Hook(线段树&区间覆盖)题解
- HDU.1394 Minimum Inversion Number (线段树 单点更新 区间求和 逆序对)
- HDU 1698 <线段树,区间set>
- codevs 1191 数轴染色 区间更新加延迟标记
- B - I Hate It HDU - 1754 线段树区间最大值板子(单点更新,区间最大)
- HDU1698:Just a Hook(线段树区间更新)