#include<cstdio>
#include<cstring>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define MAX_N 100010
int t[MAX_N<<2],d[MAX_N<<2];
void pushup(int rt)
{
t[rt]=t[rt<<1]+t[rt<<1|1];
}
void pushdown(int l,int r,int rt)
{
if(d[rt])
{
int m=(l+r)>>1;
d[rt<<1]=d[rt];
d[rt<<1|1]=d[rt];
t[rt<<1]=(m-l+1)*d[rt];
t[rt<<1|1]=(r-m)*d[rt];
d[rt]=0;
}
}
void build(int l,int r,int rt)
{
d[rt]=0;
if(l==r)
{
t[rt]=1;
return ;
}
int m=(l+r)>>1;
build(lson);
build(rson);
pushup(rt);
}
void update(int a,int b,int v,int l,int r,int rt)
{
if(a>r||b<l)
return ;
if(a<=l&&r<=b)
{
d[rt]=v;
t[rt]=v*(r-l+1);
return ;
}
pushdown(l,r,rt);
int m=(l+r)>>1;
update(a,b,v,lson);
update(a,b,v,rson);
pushup(rt);
}
int main()
{
int T,p=1;
scanf("%d",&T);
while(T--)
{
int n,q;
scanf("%d",&n);
build(1,n,1);
scanf("%d",&q);
while(q--)
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
update(a,b,c,1,n,1);
}
printf("Case %d: The total value of the hook is %d.\n",p++,t[1]);
}
}
poj 1698 线段树
最新推荐文章于 2017-09-07 21:19:04 发布