一条钩子由许多小钩子组成 更新一段小钩子 变成铜银金 价值分别变成1 2 3 输出最后的总价值
Sample Input
1
10
2
1 5 2
5 9 3
Sample Output
Case 1: The total value of the hook is 24.
# include <iostream>
# include <cstdio>
# include <cstring>
# include <algorithm>
# include <cmath>
# include <queue>
# define LL long long
using namespace std ; const int maxn = ; int sum[maxn<<] ; //结点开4倍
int col[maxn<<] ; //延迟标记 void PushUP(int rt) //更新到父节点
{
sum[rt] = sum[rt * ] + sum[rt * + ] ; //rt 为当前结点
} void PushDown(int rt , int m ) //向下更新
{
if (col[rt])
{
col[rt * ] = col[rt * + ] = col[rt] ;
sum[rt * ] = (m - m / ) * col[rt] ;
sum[rt * + ] = (m / ) * col[rt] ;
col[rt] = ;
}
} void build(int l , int r , int rt) //构建线段树
{
col[rt] = ;
if (l == r)
{
sum[rt] = ;
return ;
}
int m = (l + r) / ;
build(l , m , rt * ) ;
build(m + , r , rt * +) ;
PushUP(rt) ;
} void updata(int L , int R , int c , int l , int r , int rt)
{
if (L <= l && r <= R)
{
col[rt] = c ;
sum[rt] = (r - l + ) * c ;
return ;
}
PushDown(rt , r - l + ) ;
int m = (l + r) / ; if (L <= m)
updata(L , R , c , l , m , rt * ) ;
if (R > m)
updata(L , R , c , m + , r , rt * + ) ; PushUP(rt) ;
} int main ()
{
//freopen("in.txt","r",stdin) ;
int n , m ;
int T ;
int Case = ;
scanf("%d" , &T) ;
while(T--)
{
Case++ ;
scanf("%d%d",&n,&m);
build( , n , ) ;
while(m--)
{
int a , b , c ;
scanf("%d%d%d",&a,&b,&c);
updata(a , b , c , , n , ) ;
}
printf("Case %d: The total value of the hook is %d.\n",Case , sum[]);
} return ;
}