zoukankan      html  css  js  c++  java
  • 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);
        }
    }
    细雨斜风作晓寒。淡烟疏柳媚晴滩。入淮清洛渐漫漫。 雪沫乳花浮午盏,蓼茸蒿笋试春盘。人间有味是清欢。
  • 相关阅读:
    UI复习笔记1
    PHP字符串 集合的相关函数
    PHP的基本知识点
    XMLDictionary 解析的使用
    Json解析
    数据库增 删 改 查
    UICollectionViewFlowLayout自定义
    除了自定义cell以为,还可以通过属性来控制cell线条的长度
    观察者模式
    PHP字符串相关的方法
  • 原文地址:https://www.cnblogs.com/cangT-Tlan/p/8467662.html
Copyright © 2011-2022 走看看