rt,求助
#include <bits/stdc++.h>
#define debug(x) (cout << #x << " " << x << "\n")
using namespace std;
using ll = long long;
const int N = 1e5 + 5;
int n, tot, val[N], dat[N], cnt[N], sz[N], ch[N][2], root;
int New(int v) {
val[++ tot] = v;
dat[tot] = rand();
cnt[tot] = sz[tot] = 1;
return tot;
}
void pushup(int cur) { sz[cur] = sz[ch[cur][0]] + sz[ch[cur][1]] + cnt[cur]; }
void build() {
root = New(-1e9), ch[root][1] = New(1e9);
pushup(root);
}
void split(int cur, int v, int &x, int &y) {
if (!cur) { x = y = 0; return ; }
if (val[cur] <= v) {
x = cur, split(ch[cur][1], v, ch[cur][1], y);
} else {
y = cur, split(ch[cur][0], v, x, ch[cur][0]);
}
}
int merge(int x, int y) {
if (!x || !y) return x + y;
if (dat[x] < dat[y]) {
ch[x][1] = merge(ch[x][1], y);
pushup(x);
return x;
} else {
ch[y][0] = merge(y, ch[y][0]);
pushup(y);
return y;
}
}
void insert(int v) {
int x, y;
split(root, v, x, y);
int z = New(v);
root = merge(merge(x, z), y);
}
void del(int v) {
int x, y, z;
split(root, v, x, z);
split(root, v - 1, x, y);
y = merge(ch[y][0], ch[y][1]);
root = merge(merge(x, y), z);
}
int rnk(int v) {
int x, y;
split(root, v - 1, x, y);
int ans = sz[x] + 1;
root = merge(x, y);
return ans;
}
int kth(int cur, int k) {
int lsz = sz[ch[cur][0]];
if (k == lsz + 1) return val[cur];
if (k <= lsz) return kth(ch[cur][0], k);
return kth(ch[cur][1], k - lsz - 1);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
build();
while (n --) {
int opt, x; cin >> opt >> x;
if (opt == 1) insert(x);
else if (opt == 2) del(x);
else if (opt == 3) cout << rnk(x) - 1 << "\n";
else if (opt == 4) cout << kth(root, x + 1) << "\n";
else if (opt == 5) cout << kth(root, rnk(x) - 1) << "\n";
else if (opt == 6) cout << kth(root, rnk(x + 1)) << "\n";
}
return 0;
}