E - Just a Hook
#include<bits/stdc++.h>
using namespace std;
const int M = 100000+100;
int st[M<<2],lazy[M<<2];
void pushdown(int l,int r,int rt)
{
if(lazy[rt])
{
lazy[rt<<1]=lazy[rt];
lazy[rt<<1|1]=lazy[rt];
int mid=(l+r)>>1;
st[rt<<1]=(mid-l+1)*lazy[rt];
st[rt<<1|1]=(r-mid)*lazy[rt];
lazy[rt]=0;
}
}
void build(int l,int r,int rt)
{
lazy[rt]=0;
if(l==r)
{
st[rt]=1;
return ;
}
int mid=(l+r)>>1;
build(l,mid,rt<<1);
build(mid+1,r,rt<<1|1);
st[rt]=st[rt<<1]+st[rt<<1|1];
pushdown(l,r,rt);
}
void update(int l,int r,int rt,int L,int R,int d)
{
// printf("%d %d %d %d\n",l,r,L,R);
if(L<=l&&r<=R)
{
lazy[rt]=d;
st[rt]=(r-l+1)*d;
return ;
}
pushdown(l,r,rt);
int mid=(l+r)>>1;
if(L<=mid)update(l,mid,rt<<1,L,R,d);
if(R>mid)update(mid+1,r,rt<<1|1,L,R,d);
st[rt]=st[rt<<1]+st[rt<<1|1];
}
int query(int l,int r,int rt,int L,int R)
{
if(L<=l&&r<=R)
{
return st[rt];
}
pushdown(l,r,rt);
int mid=(l+r)>>1;
int ans=0;
if(L<=mid)ans+=query(l,mid,rt<<1,L,R);
if(R>mid)ans+=query(mid+1,r,rt<<1|1,L,R);
return ans;
}
int main()
{
int t,n,m;
cin>>t;
for(int i=1;i<=t;i++)
{
int x,y,z;
scanf("%d%d",&n,&m);
build(1,n,1);
// puts("ok");
while(m--)
{
scanf("%d%d%d",&x,&y,&z);
update(1,n,1,x,y,z);
}
/* puts("ok");
// while(1)
// {
// int l,r;
// cin>>l>>r;
// printf("Case %d: The total value of the hook is %d.\n",t,query(1,n,1,l,r));
// }*/
printf("Case %d: The total value of the hook is %d.\n",i,query(1,n,1,1,n));
}
return 0;
}