线段树
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N = 100005;
struct node
{
ll l,r;
ll add,sum;//add是懒惰标记
}tree[N<<2];
void pushup(int root)
{
tree[root].sum = tree[root << 1].sum + tree[root << 1 | 1].sum;
}
void pushdown(int root, int m)
{
if (tree[root].add)
{
tree[root << 1].add = tree[root].add;
tree[root << 1 | 1].add = tree[root].add;
tree[root << 1].sum = tree[root].add * (m - (m >> 1));
tree[root << 1 | 1].sum = tree[root].add * (m >> 1);
tree[root].add = 0;
}
}
void build(int l, int r, int root)
{
tree[root].l = l;
tree[root].r = r;
tree[root].add = 0;
tree[root].sum = 1;
if (l == r)
{
tree[root].sum = 1;
return;
}
int mid = (tree[root].l + tree[root].r) / 2;
build(l, mid, root << 1);
build(mid + 1, r, root << 1 | 1);
pushup(root);
}
void update(int c, int l, int r, int root)
{
if (tree[root].l == l && tree[root].r == r)
{
tree[root].add = c;
tree[root].sum = (ll)c * (r - l + 1);
return;
}
if (tree[root].l == tree[root].r)
return;
pushdown(root, tree[root].r - tree[root].l + 1);
int mid = (tree[root].l + tree[root].r) >> 1;
if (r <= mid)
update(c, l, r, root << 1);
else if (l > mid)
update(c, l, r, root << 1 | 1);
else
{
update(c, l, mid, root << 1);
update(c, mid + 1, r, root << 1 | 1);
}
pushup(root);
}
int main()
{
int t,n,q;
cin >> t;
for(int ca = 1;ca <= t;ca++)
{
scanf("%d%d",&n,&q);
build(1,n,1);
ll x,y,val;
//char str[5];
while(q--)
{
scanf("%lld%lld%lld",&x,&y,&val);
update(val,x,y,1);
}
printf("Case %d: The total value of the hook is %lld.\n",ca,tree[1].sum);
}
return 0;
}