我是蒟蒻,自己做出来的60分,让AI优化修改了一下,直接AC了,答案在下面:
#include <iostream>
#include <set>
using namespace std;
int main() {
int q, op, x;
cin >> q;
set<int> s;
while (q--) {
cin >> op >> x;
switch (op) {
case 1: {
// 查询数 x 的排名
auto it = s.lower_bound(x);
int rank = distance(s.begin(), it) + 1;
cout << rank << endl;
break;
}
case 2: {
// 查询排名为 x 的数
auto it = s.begin();
advance(it, x - 1);
cout << *it << endl;
break;
}
case 3: {
// 求 x 的前驱
auto it = s.lower_bound(x);
if (it == s.begin()) {
cout << -2147483647 << endl;
} else {
--it;
cout << *it << endl;
}
break;
}
case 4: {
// 求 x 的后继
auto it = s.upper_bound(x);
if (it == s.end()) {
cout << 2147483647 << endl;
} else {
cout << *it << endl;
}
break;
}
case 5: {
// 插入一个数 x
s.insert(x);
break;
}
}
}
return 0;
}