pbds求助

P6136 【模板】普通平衡树(数据加强版)

Jppppp @ 2022-03-13 09:58:49

rt 只有20分qwq

#include<bits/stdc++.h>
#include<cstdlib>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#define For(i,a,b) for(int i(a);i<=b;++i)
#define int long long
using namespace std;
using namespace __gnu_pbds;
inline void read(int &x){
    bool w=0; char ch;x=0; ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')w=1; ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    if(w)x=-1*x;
}
inline void print(int x){
    if(x<0){putchar('-');print(-x);return ;}
    if(x>9)print(x/10); putchar(x%10+'0');
}
tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> T;
int n,m,k,ans,opt,ls=0,qwq=0,nown;
signed main(){
    read(n);read(m);
    For(i,1,n){
        read(k);T.insert((k<<20)+i);
    }
    nown=n;
    For(i,1+n,m+n){
        read(opt);read(k);
        k^=ans;
//      cout<<"!"<<k<<endl;
        if(opt==1)T.insert((k<<20)+i),nown++;
        if(opt==2)T.erase(T.lower_bound(k<<20)),nown--;
        if(opt==3)ans=(T.order_of_key(k<<20)+1),qwq^=ans;
        if(opt==4)ans=*T.find_by_order(min(k-1,nown-1)),ans=(ans>>20),qwq^=ans;
        if(opt==5)ans=*--T.lower_bound(k<<20),ans=(ans>>20),qwq^=ans;
        if(opt==6)ans=*T.upper_bound((k<<20)+n),ans=(ans>>20),qwq^=ans;
//      if(opt>=3){
//          cout<<"!"<<ans<<endl;
//      }
    }
    print(qwq);
}

|