• E


    思路:区间修改即可。
    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    int t,n,m,tot;
    struct nond{
        int l,r;
        int sum,falg;
    }tree[101000*4];
    void up(int now){
        tree[now].sum=tree[now<<1].sum+tree[now<<1|1].sum;
    }
    void build(int now,int l,int r){
        tree[now].l=l;
        tree[now].r=r;
        if(tree[now].l==tree[now].r){
            tree[now].sum=1;
            return ;
        }
        int mid=(tree[now].l+tree[now].r)>>1;
        build(now<<1,l,mid);
        build(now<<1|1,mid+1,r);
        up(now);
    }
    void down(int now){
        tree[now<<1].sum=(tree[now<<1].r-tree[now<<1].l+1)*tree[now].falg;
        tree[now<<1|1].sum=(tree[now<<1|1].r-tree[now<<1|1].l+1)*tree[now].falg;
        tree[now<<1].falg=tree[now<<1|1].falg=tree[now].falg;
        tree[now].falg=0;
    }
    void change(int now,int l,int r,int x){
        if(tree[now].l==l&&tree[now].r==r){
            tree[now].sum=(tree[now].r-tree[now].l+1)*x;
            tree[now].falg=x;
            return;
        }
        if(tree[now].falg)    down(now);
        int mid=(tree[now].l+tree[now].r)>>1;
        if(r<=mid)    change(now<<1,l,r,x);
        else if(l>mid)    change(now<<1|1,l,r,x);
        else{ change(now<<1,l,mid,x);change(now<<1|1,mid+1,r,x); }
        up(now);
    }
    int main(){
        scanf("%d",&t);
        while(t--){
            scanf("%d",&n);tot++;
            memset(tree,0,sizeof(tree));
            build(1,1,n);scanf("%d",&m);
            for(int i=1;i<=m;i++){
                int x,y,z;
                scanf("%d%d%d",&x,&y,&z);
                change(1,x,y,z);
            }
            printf("Case %d: The total value of the hook is %d.
    ",tot,tree[1].sum);
        }
    }
    细雨斜风作晓寒。淡烟疏柳媚晴滩。入淮清洛渐漫漫。 雪沫乳花浮午盏,蓼茸蒿笋试春盘。人间有味是清欢。
  • 相关阅读:
    C++模板学习之优先队列实现
    static 和const分别怎么用,类里面static和const可以同时修饰成员函数吗?
    C和C++的区别
    C++多态例子_虚函数
    转:master公式(主方法)
    C++11最常用的新特性如下
    转:哈夫曼树详解
    linux shell脚本
    linux 正则表达式
    linux shell命令
  • 原文地址:https://www.cnblogs.com/cangT-Tlan/p/8467662.html
Copyright © 2020-2023  润新知