#include<iostream> #include<cstdio> using namespace std; #define lson left,mid,i<<1 #define rson mid+1,right,i<<1|1 struct IntervalTree { int left,right,sum,set; }f[300005]; void pushdown(int i) { if(f[i].set>0) { f[i<<1].set=f[i<<1|1].set=f[i].set; f[i<<1].sum=(f[i<<1].right-f[i<<1].left+1)*f[i].set; f[i<<1|1].sum=(f[i<<1|1].right-f[i<<1|1].left+1)*f[i].set; f[i].set=0; } } void pushup(int i) { f[i].sum=f[i<<1].sum+f[i<<1|1].sum; } void bulid(int left,int right,int i) { f[i].left=left,f[i].right=right,f[i].set=0; if(left==right) { f[i].sum=1;return ; } int mid=(left+right)>>1; bulid(lson); bulid(rson); pushup(i); return ; } void update(int left,int right,int set,int i) { if(f[i].left==left && f[i].right==right) { f[i].set=set; f[i].sum=(right-left+1)*set; return ; } pushdown(i); if(f[i<<1].right>=right) update(left,right,set,i<<1); else if(f[i<<1|1].left<=left) update(left,right,set,i<<1|1); else { update(left,f[i<<1].right,set,i<<1);update(f[i<<1|1].left,right,set,i<<1|1);} pushup(i); return ; } int query(int left,int right,int i) { if(f[i].left==left && f[i].right==right) return f[i].sum; pushdown(i); if(f[i<<1].right>=right) return query(left,right,i<<1); else if (f[i<<1|1].left<=left) return query(left,right,i<<1|1); else return query(left,f[i<<1].right,i<<1)+query(f[i<<1|1].left,right,i<<1|1); } int main() { int icase,T,n,m,ai,bi,d; scanf("%d",&T); for(icase=1;icase<=T;icase++) { scanf("%d",&n); bulid(1,n,1); scanf("%d",&m); while(m--) { scanf("%d %d %d",&ai,&bi,&d); update(ai,bi,d,1); } printf("Case %d: The total value of the hook is %d. ",icase,f[1].sum); } return 0; }