(D) hdu1698 (modified sections)

(d) hdu1698 Just a Hook

As part you do not understand when reading this article, please ask in the comments section, or jump tree line general introduction 

 

Note the outset whole interval is 1

This problem over the water will not explain

 

Code

/*hdu1698*/
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
const int N=2e7+3;
int T,n,m;
int tag[N<<2],v[N<<2];
#define mid (l+r>>1)
#define ls (rt<<1)
#define rs (ls|1)
#define pushup(rt) v[rt]=v[ls]+v[rs]
void build(int rt,int l,int r){
    tag[rt]=0;
    if(l==r){v[rt]=1;return;}
    build(ls,l,mid);build(rs,mid+1,r);
    pushup(rt);
}
void pushdown(int rt,int l,int r){
    tag[ls]=tag[rt],tag[rs]=tag[rt];
    v[ls]=(mid-l+1)*tag[rt];
    v[rs]=(r-mid)*tag[rt];
    tag[rt]=0;
}
void update(int rt,int l,int r,int x,int y,int z){
    if(x<=l&&y>=r){tag[rt]=z;v[rt]=(r-l+1)*z;return;}
    if(tag[rt])pushdown(rt,l,r);
    if(x<=mid)update(ls,l,mid,x,y,z);
    if(y>mid)update(rs,mid+1,r,x,y,z);
    pushup(rt);
}
int Case=0;
int main(){
    scanf("%d",&T);
    while(T--){
        scanf("%d%d",&n,&m);
        //build(1,1,n);
        update(1,1,n,1,n,1);
        int x,y,z;
        while(m--){
            scanf("%d%d%d",&x,&y,&z);
            update(1,1,n,x,y,z);
        }
        printf("Case %d: The total value of the hook is %d.\n",++Case,v[1]);   
    }
    return 0;
}

 End

Guess you like

Origin www.cnblogs.com/lsy263/p/11227976.html