zoukankan      html  css  js  c++  java
  • 洛谷P3369 【模板】普通平衡树 01trie/骚操作

    Code:

    #include <cstdio>
    #include <algorithm>
    #include <cstring>
    #define setIO(s) freopen(s".in","r",stdin)
    #define maxn 100010 * 33 
    using namespace std;
    int root=1,tot=1,sumv[maxn],n,opt,x,ch[maxn][2]; 
    void ins(int val,int c){
        val += (int)1e7;
        for(int i=31,p=root,t;i>=0;--i){
            t=(val>>i)&1;
            if(!ch[p][t]) ch[p][t]=++tot;
            p=ch[p][t]; sumv[p]+=c; 
        }
    }
    int rank(int val){
        val += (int)1e7; 
        int res=0,p=root; 
        for(int i=31;i>=0;--i){
            int t=(val>>i)&1;
            if(t) res += sumv[ch[p][0]];
            p=ch[p][t]; 
        }
        return res; 
    }
    int kth(int val){
        int k=root,res=0;
        for(int i=31;i>=0;--i){
            if(val>sumv[ch[k][0]]) res|=(1<<i),val-=sumv[ch[k][0]],k=ch[k][1];
            else k=ch[k][0]; 
        } 
        res-=(1e7); return res; 
    }
    int main(){
        //setIO("input");
        scanf("%d",&n);
        while(n--){
            scanf("%d%d",&opt,&x);
            if(opt==1) ins(x,1);
            else if(opt==2) ins(x,-1);
            else if(opt==3) printf("%d
    ",rank(x)+1);
            else if(opt==4) printf("%d
    ",kth(x));
            else if(opt==5) printf("%d
    ",kth(rank(x)));
            else if(opt==6) printf("%d
    ",kth(rank(x+1)+1)); 
        }
        return 0; 
    }
    

      

  • 相关阅读:
    View onMeasure方法介绍
    控件的3个状态
    多个Activity之间的跳转(1)
    7种形式的Android Dialog使用举例(下)
    调用摄像头采集图像
    读取播放视频
    MATLAB
    下载数据CSV文件格式
    生成数据
    java中给当前时间添加一小时
  • 原文地址:https://www.cnblogs.com/guangheli/p/10370035.html
Copyright © 2011-2022 走看看