题目链接:https://www.luogu.org/problemnew/show/P3369
使用教程:https://baijiahao.baidu.com/s?id=1610302746201562113&wfr=spider&for=pc
tree差不多可以当作强化版set来用吧。
/// int类型
/// null_type为映射类型, 低版本g++为 null_mapped_type
/// less<int>, greater<int> 比较器
/// rb_tree_tag 和 splay_tree_tag 选择树的类型
/// tree_order_statistics_node_update 结点更新
/// insert, erase
/// order_of_key 查询rank 返回值
/// find_by_order() 查询 kth 返回迭代器
/// lower_bound() 前继, >=x 最小的迭代器
/// upper_bound() 后继 >x 最小的迭代器
/// a.join(b) b并入a,前提是两颗树的取值范围不相交
/// a.split(v, b) key <= v的属于a,其他属于
/// 注意,插入的元素会去重,如set
///显然迭代器可以++,--运算
#include<bits/stdc++.h>
//#include<bits/extc++.h> //include全部文件,但是好像不能用
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp> //用tree
#include<ext/pb_ds/hash_policy.hpp> //用hash
#include<ext/pb_ds/priority_queue.hpp> //用priority_queue
#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define ll long long
using namespace std;
using namespace __gnu_pbds;
tree<ll,null_type, less<ll> ,rb_tree_tag,tree_order_statistics_node_update> T;
int main() {
freopen("a.txt","r",stdin);
ios::sync_with_stdio(0);
int n;
cin>>n;
rep(i, 1, n) {
int oper;
ll x;
cin>>oper>>x;
if(oper==1) T.insert((x<<20)+i);
if(oper==2) T.erase(T.lower_bound(x<<20));
if(oper==3) cout<<T.order_of_key(x<<20)+1<<endl;
ll ans = -1e9;
if(oper==4) ans = *T.find_by_order(x-1);
if(oper==5) ans = *--T.lower_bound(x<<20);
if(oper==6) ans = *T.lower_bound((x+1)<<20);
if(ans!=-1e9) cout<<(ans>>20)<<endl;
}
return 0;
}