有趣的题目
/***
* ccccccccccc的data,一遍ac
* 线段树+懒操作第二弹
* hdu1698
*/
#include<iostream>
#include<cstdio>
using namespace std;
#define lc (d<<1)
#define rc (d<<1|1)
#define mid (l+r>>1)
const int mmax = 100005;
struct tree
{
int v;
bool lz;
}tr[mmax<<2];
void lazy(int d)
{
if(tr[d].lz)
{
tr[lc].lz = tr[rc].lz = true;
tr[lc].v = tr[rc].v = tr[d].v;
tr[d].lz = false;
}
}
void build(int d, int l, int r)
{
if(l == r)
{
tr[d].v = 1;
return;
}
build(lc, l, mid);
build(rc, mid+1, r);
tr[d].v = 1;
}
void update(int d, int l, int r, int left, int right, int x)
{
if(l == left && r == right)
{
tr[d].v = x;
tr[d].lz = true;
return;
}
lazy(d);
if(left > mid) update(rc, mid+1, r, left, right,x);
else if(right <= mid) update(lc, l, mid, left, right, x);
else
{
update(rc, mid+1, r, mid+1, right, x);
update(lc, l, mid, left, mid, x);
}
}
void out(int d, int l, int r, int & sum)
{
if(tr[d].lz)
{
sum+=tr[d].v*(r-l+1);
return;
}
if(l == r)
{
sum+=tr[d].v;
return;
}
out(lc, l, mid, sum);
out(rc, mid+1, r, sum);
}
int main()
{
int t;
scanf("%d",&t);
for(int k = 1; k <= t; k++)
{
int n1;
scanf("%d",&n1);
build(1,1,n1);
int n2;
scanf("%d",&n2);
for(int i = 1; i <= n2; i++)
{
int l,r,z;
scanf("%d%d%d",&l,&r,&z);
update(1,1,n1,l,r,z);
}
//输出
int sum = 0;
out(1, 1, n1, sum);
printf("Case %d: The total value of the hook is %d.\n",k,sum);
}
return 0;
}