#include<bits/stdc++.h>
using namespace std;
int n, root, cnt, opt, x;
struct node{
int value, left, right, size, num;
node(int l, int r, int s, int v): left(l), right(r), size(s), value(v), num(1) {}
node() {}
}t[10010];
void update(int root) {
t[root].size = t[t[root].left].size + t[t[root].right].size + t[root].num;
}
int rk (int x, int root) {
if (root) {
if (x < t[root].value) return rk(x, t[root].left);
if (x > t[root].value) return rk(x, t[root].right) + t[t[root].left].size + t[root].num;
return t[t[root].left].size + t[root].num;
}
return 1;
}
int kth (int x, int root) {
if (x <= t[t[root].left].size) return kth(x, t[root].left);
if (x <= t[t[root].left].size + t[root].num) return t[root].value;
return kth(x - t[t[root].left].size - t[root].num, t[root].right);
}
void insert (int x, int & root) {
if (x < t[root].value){
if (!t[root].left) t[t[root].left = ++cnt] = node(0, 0, 1, x);
else insert(x, t[root].left);
}
else if (x > t[root].value) {
if (!t[root].right) t[t[root].right = ++cnt] = node(0, 0, 1, x);
else insert(x, t[root].right);
}
else t[root].num++;
update(root);
}
int main() {
cin >> n;
int num = 0;
t[root = ++cnt] = node(0, 0, 1, 2147483647);
while (n--) {
cin >> opt >> x;
num++;
if (opt == 1) cout << rk(x, root) << endl;
if (opt == 2) cout << kth(x, root) << endl;
if (opt == 3) cout << kth(rk(x, root)-1, root) << endl;
if (opt == 4) cout << kth(rk(x+1, root), root) << endl;
if (opt == 5) {
num--; insert(x, root);
}
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 张高兴的大模型开发实战:(一)使用 Selenium 进行网页爬虫
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构