hdu 1698区间延迟更新

来源:互联网 发布:qsv转换mp4软件 编辑:程序博客网 时间:2024/05/16 08:11
#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;
}
原创粉丝点击