#include <bits/stdc++.h>
using namespace std;
struct Treap {
vector <int> a;
void insert(int x) {
a.insert(lower_bound(a.begin(), a.end(), x), x); // 插入x
}
void eraser(int x) {
a.erase(lower_bound(a.begin(), a.end(), x)); // 删除x
}
int rank(int x) {
return lower_bound(a.begin(), a.end(), x) - a.begin() + 1; // 查询x的排名
}
int rank_at(int x) {
return a[x - 1]; // 查询排名为x的数
}
int lower_bound(int x) {
return a[lower_bound(a.begin(), a.end(), x) - a.begin() - 1]; // 查询x前驱
}
int upper_bound(int x) {
return a[upper_bound(a.begin(), a.end(), x) - a.begin()]; // 查询x的后继
}
} ;
Treap a;
int T, opt, x;
int main() {
scanf("%d", &T);
while (T--) {
scanf("%d%d", &opt, &x);
switch (opt) {
case 1:
a.insert(x);
break;
case 2:
a.eraser(x);
break;
case 3:
printf("%d\n", a.rank(x));
break;
case 4:
printf("%d\n", a.rank_at(x));
break;
case 5:
printf("%d\n", a.lower_bound(x));
break;
case 6:
printf("%d\n", a.upper_bound(x));
break;
}
}
return 0;
}
我就是想把这个封装了怎么就CE了想问问