#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 400010
#define L(rt) rt<<1
#define R(rt) rt<<1|1
#define LSON l,mid,L(rt)
#define RSON mid+1,r,R(rt)
#define MID (l+r)>>1
#define FOR(i,n) for( int i = 0; i < n; i ++ )
using namespace std;
int sum[N<<2], lazy[N<<2];
void push_down( int l, int r, int rt )
{
if( lazy[rt] != -1 )
{
lazy[ L(rt) ] = lazy[ R(rt) ] = lazy[rt];
sum[rt] = lazy[rt]*(r-l+1);
lazy[rt] = -1;
}
}
void push_up( int rt )
{
sum[rt] = sum[ L(rt) ] + sum[ R(rt) ];
}
void build( int l, int r, int rt )
{
sum[rt] = r-l+1;
lazy[rt] = -1;
if( l == r ) return ;
int mid = MID;
build(LSON);
build(RSON);
}
void update( int a, int b, int c, int l, int r, int rt )
{
if( l >=a && r<= b )
{
lazy[rt] = c;
push_down(l,r,rt);
int mid = MID;
push_down( LSON );
push_down( RSON );
return ;
}
push_down( l, r, rt );
int mid = MID;
push_down( LSON );
push_down( RSON );
if( a<= mid ) update( a, b, c, LSON );
if( mid < b ) update( a, b, c, RSON );
push_up(rt);
}
int main()
{
int ncas,n , m, l, r, c ;
scanf("%d",&ncas);
for( int cas = 1; cas <= ncas; cas ++ )
{
scanf("%d",&n);
build( 1, n,1 );
scanf("%d",&m);
FOR(i,m)
{
scanf("%d%d%d",&l,&r,&c);
update( l, r, c, 1, n, 1 );
}
printf("Case %d: The total value of the hook is %d.\n",cas,sum[1]);
}
return 0;
}
hdu 1698
最新推荐文章于 2022-12-12 21:12:45 发布