zoukankan      html  css  js  c++  java
  • Codeforces 817F

    817F - MEX Queries

    思路:

    离线+离散化+线段树

    代码:

    #include<bits/stdc++.h>
    using namespace std;
    #define LL long long 
    #define pb push_back
    #define ls rt<<1,l,m
    #define rs rt<<1|1,m+1,r
    
    const int N=1e5+5;
    int t[N],tree[N*16],lazy[N*16];
    LL l[N],r[N];
    vector<LL>vc;
    void push_up(int rt){
        tree[rt]=tree[rt<<1]+tree[rt<<1|1];
    }
    void push_down(int rt,int l,int r){
        int m=(l+r)>>1;
        if(lazy[rt]==1){
            lazy[rt<<1]=lazy[rt<<1|1]=1;
            tree[rt<<1]=m-l+1;
            tree[rt<<1|1]=r-m;
        }
        else if(lazy[rt]==2){
            lazy[rt<<1]=lazy[rt<<1|1]=2;
            tree[rt<<1]=tree[rt<<1|1]=0;
        }
        else if(lazy[rt]==3){
            lazy[rt<<1]=3-lazy[rt<<1];
            lazy[rt<<1|1]=3-lazy[rt<<1|1];
            tree[rt<<1]=m-l+1-tree[rt<<1];
            tree[rt<<1|1]=r-m-tree[rt<<1|1];
        }
        lazy[rt]=0;
    }
    void build(int rt,int l,int r){
        if(l==r){
            tree[rt]=0;
            lazy[rt]=0; 
            return ;
        }
        int m=(l+r)>>1;
        build(ls);
        build(rs);
        push_up(rt);
    }
    void update(int t,int L,int R,int rt,int l,int r){
        if(L<=l&&r<=R){
            if(t==1){
                tree[rt]=r-l+1;
                lazy[rt]=1; 
            }
            else if(t==2){
                tree[rt]=0;
                lazy[rt]=2;
            }
            else{
                if(lazy[rt]&&l!=r)push_down(rt,l,r);//注意这里,在更新第3种操作时,把之前在这个节点的操作pushdown 
                tree[rt]=r-l+1-tree[rt];
                lazy[rt]=3;
            }
            return ;
        }
        if(lazy[rt])push_down(rt,l,r);
        int m=(l+r)>>1;
        if(L<=m)update(t,L,R,ls);
        if(R>m) update(t,L,R,rs); 
        push_up(rt);
    }
    int query(int rt,int l,int r){
        if(l==r){
            return l;
        }
        if(lazy[rt])push_down(rt,l,r);
        int m=(l+r)>>1;
        if(tree[rt<<1]!=m-l+1)return query(ls);
        else return query(rs);
    }
    int main(){
        ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        int n;
        cin>>n;
        vc.pb(1LL);
        for(int i=1;i<=n;i++)cin>>t[i]>>l[i]>>r[i],vc.pb(l[i]),vc.pb(r[i]),vc.pb(r[i]+1),vc.pb(l[i]+1);
        sort(vc.begin(),vc.end());
        vc.erase(unique(vc.begin(),vc.end()),vc.end());
        int m=vc.size();
        build(1,1,m);
        for(int i=1;i<=n;i++){
            int L=lower_bound(vc.begin(),vc.end(),l[i])-vc.begin()+1;
            int R=lower_bound(vc.begin(),vc.end(),r[i])-vc.begin()+1;
            update(t[i],L,R,1,1,m);
            cout<<vc[query(1,1,m)-1]<<endl;
        }
        return 0;
    } 
  • 相关阅读:
    Bank5
    面向对象特征之多态性
    继承性与super的使用练习
    阿里云服务器被挖矿minerd入侵的解决办法
    ES Pipeline Aggregation(管道聚合)
    Elasticsearch索引自动套用模板
    docker.service启动失败:Unit not found的原因及解决办法
    Kubernetes集群资源监控
    Kunbernetes-基于NFS的存储
    Kubernetes核心技术Helm
  • 原文地址:https://www.cnblogs.com/widsom/p/8519724.html
Copyright © 2011-2022 走看看