普通平衡树板子
cpp
#include<bits/extc++.h>
using namespace __gnu_pbds;
#define TR tree<PII,null_type,less<PII>,rb_tree_tag,tree_order_statistics_node_update>
void solve(){
TR tr;
int q;
cin>>q;
int cnt=0;
tr.insert({-INF,0});
tr.insert({INF,0});
while(q--){
int op,x,ans;
cin>>op>>x;
if(op==1)tr.insert({x,++cnt});//pbds平衡树无法记录个数,因此使用pair,第二维代表编号
else if(op==2)tr.erase(*tr.lower_bound({x,0}));
else if(op==3)cout<<tr.order_of_key(*tr.lower_bound({x,0}))<<"\n";
else if(op==4)cout<<tr.find_by_order(x)->first<<"\n";
else if(op==5)cout<<(--tr.lower_bound({x,0}))->first<<"\n";
else cout<<(tr.upper_bound({x,INF})->first)<<"\n";
}
}