题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1698
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <queue>
#include <vector> #define maxn 130050
#define lson l,mid,u<<1
#define rson mid+1,r,u<<1|1
using namespace std; const int INF = 0x3f3f3f; int seg[maxn<<];
int pau[maxn<<]; void Push_UP(int u){
seg[u] =seg[u<<] + seg[u<<|];
}
void Push_Down(int l,int r,int u){
if(pau[u]){
int mid = (l + r)/;
pau[u<<] = pau[u<<|] = pau[u];
seg[u<<] = (mid - l + ) * pau[u];
seg[u<<|] = (r - mid) * pau[u];
pau[u] = ;
}
}
void build(int l,int r,int u){
if(l == r){
seg[u] = ;
return;
}
int mid = (l + r)/;
build(lson);
build(rson);
Push_UP(u);
}
void Update(int L,int R,int num,int l,int r,int u){
if(L <= l && r <= R){ // 这个地方要注意!!
pau[u] = num;
seg[u] = num * (r - l + );
return;
}
Push_Down(l,r,u);
int mid = (l + r)/;
if(L <= mid) Update(L,R,num,lson);
if(R > mid) Update(L,R,num,rson);
Push_UP(u);
} int main()
{
if(freopen("input.txt","r",stdin)== NULL) {printf("Error\n"); exit();}
int T;
cin>>T;
for(int t=;t<=T;t++){
int N,Q;
cin>>N;
build(,N,);
cin>>Q;
memset(pau,,sizeof(pau));
while(Q--){
int X,Y,Z;
scanf("%d%d%d",&X,&Y,&Z);
Update(X,Y,Z,,N,);
}
printf("Case %d: The total value of the hook is %d.\n",t,seg[]);
}
}