标签:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
#include<set>
using namespace std;
#define mem(x,y) memset(x,y,sizeof(x))
const int MAXN=100010;
struct Node{
int lazy,v;
};
Node tree[MAXN<<2];
#define ll root<<1
#define rr root<<1|1
#define lson ll,l,mid
#define rson rr,mid+1,r
#define LAZY(x) tree[x].lazy
#define V(x) tree[x].v
int ans;
void pushdown(int root){
if(LAZY(root)){
LAZY(ll)=LAZY(root);
LAZY(rr)=LAZY(root);
V(ll)=LAZY(root);
V(rr)=LAZY(root);
LAZY(root)=0;
}
}
void pushup(int root){
V(root)=V(ll)+V(rr);
}
void build(int root,int l,int r){
LAZY(root)=0;
int mid=(l+r)>>1;
if(l==r){
V(root)=1;
return;
}
build(lson);
build(rson);
pushup(root);
}
void update(int root,int l,int r,int L,int R,int v){
int mid=(l+r)>>1;
if(l>=L&&r<=R){
LAZY(root)=v;
return;
}
pushdown(root);
if(mid>=L)update(lson,L,R,v);
if(mid<R)update(rson,L,R,v);
pushup(root);
}
void query(int root,int l,int r,int L,int R){
int mid=(l+r)>>1;
if(l>=L&&r<=R){
ans+=V(root);
return;
}
if(mid>=L)query(lson,L,R);
if(mid<R)query(rson,L,R);
}
int main(){
int T,N,kase=0;
scanf("%d",&T);
while(T--){
scanf("%d",&N);
build(1,1,N);
int q,a,b,c;
scanf("%d",&q);
while(q--){
scanf("%d%d%d",&a,&b,&c);
update(1,1,N,a,b,c);
}
ans=0;
query(1,1,N,1,N);
printf("Case %d: The total value of the hook is %d.\n",++kase,ans);
}
return 0;
}
标签:
原文地址:http://www.cnblogs.com/handsomecui/p/5024610.html