注意:懒标记传递到下层后一定要清空当层的。
const int N = 1e5+5;
int t;int n, m;
struct node
{
int l, r, sum, v;
}tr[N*4];
void pushup(node &root, node &le, node &re)
{
root.sum = le.sum + re.sum;
}
void pushup(int u)
{
pushup(tr[u], tr[u << 1], tr[u << 1 | 1]);
}
void pushdown(int u)
{
auto &le = tr[u << 1], &ro = tr[u], &re = tr[u << 1 | 1];
if (ro.v)
{
le.v = ro.v, re.v = ro.v;
le.sum = le.v*(le.r - le.l + 1), re.sum = re.v*(re.r - re.l + 1);
ro.v = 0;
}
}
void build(int u, int l, int r)
{
if (l == r)tr[u] = {l,l,1,0};
else
{
tr[u] = { l,r,1,1};
int mid = l + r >> 1;
build(u << 1, l, mid), build(u << 1 | 1, mid + 1, r);
pushup(u);
}
}
void modify(int u, int l, int r, int w)
{
if (tr[u].l >= l && tr[u].r <= r)//树中结点
{
tr[u].v = w;
tr[u].sum = (tr[u].r - tr[u].l + 1)*w;
}
else
{
pushdown(u);
int mid = tr[u].l + tr[u].r >> 1;
if (l <= mid)modify(u << 1, l, r,w);
if (r > mid)modify(u << 1 | 1, l, r,w);
pushup(u);
}
}
int query(int u, int l, int r)
{
if (tr[u].l >= l && tr[u].r <= r)return tr[u].sum;
else
{
pushdown(u);
int mid = tr[u].l + tr[u].r >> 1;
int ans = 0;
if (l <= mid)ans += query(u << 1, l, r);
if (r > mid)ans += query(u << 1 | 1, l, r);
return ans;
}
}
int main()
{
//freopen("in.txt", "r", stdin);
cin >> t;
int cas = 0;
while (t--)
{
scanf("%d", &n);
build(1, 1, n);
scanf("%d", &m);
int l, r, w;
while (m--)
{
scanf("%d%d%d", &l, &r, &w);
modify(1,l, r, w);
}
printf("Case %d: The total value of the hook is %d.\n", ++cas, query(1,1,n));
}
return 0;
}