题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1698
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<utility>
using namespace std;
#define lson l , mid , rt << 1
#define rson mid + 1 , r , rt << 1 | 1
const int maxn = 120000;
int col[maxn << 2], sum[maxn << 2];
void PushUp(int rt)
{
sum[rt] = sum[rt << 1] + sum[rt << 1 | 1];
}
void build(int l, int r, int rt)
{
col[rt] = 0;
sum[rt] = 1;
if (l == r) return;
int mid = (l + r) >> 1;
build(lson);
build(rson);
PushUp(rt);
}
void PushDown(int rt, int len)
{
if (col[rt])
{
col[rt << 1] = col[rt << 1 | 1] = col[rt];
sum[rt << 1] = (len - (len >> 1)) * col[rt];
sum[rt << 1 | 1] = (len >> 1) * col[rt];
col[rt] = 0;
}
}
void update(int L, int R, int c, int l, int r, int rt)
{
if (L <= l && r <= R)
{
col[rt] = c;
sum[rt] = c * (r - l + 1);
return;
}
PushDown(rt, r - l + 1);
int mid = (l + r) >> 1;
if (L <= mid) update(L, R, c, lson);
if (R > mid) update(L, R, c, rson);
PushUp(rt);
}
int main()
{
int T;
cin >> T;
for (int kase = 1; kase <= T; kase++)
{
int len, Q;
scanf("%d%d", &len, &Q);
build(1, len, 1);
while (Q--)
{
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
update(a, b, c, 1, len, 1);
}
printf("Case %d: The total value of the hook is %d.\n", kase, sum[1]);
}
}