You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
977 B
31 lines
977 B
#include <cstdio>
|
|
#include <vector>
|
|
#include <algorithm>
|
|
#include <iostream>
|
|
using namespace std;
|
|
|
|
int n;
|
|
vector<int> a;
|
|
|
|
int main() {
|
|
//加快读入
|
|
ios::sync_with_stdio(false), cin.tie(0);
|
|
cin >> n;
|
|
int op, x;
|
|
while (n--) {
|
|
cin >> op >> x;
|
|
if (op == 1)
|
|
a.insert(lower_bound(a.begin(), a.end(), x), x); //插入数值x
|
|
else if (op == 2)
|
|
a.erase(lower_bound(a.begin(), a.end(), x)); //删除数值x
|
|
else if (op == 3)
|
|
printf("%d\n", lower_bound(a.begin(), a.end(), x) - a.begin() + 1); //查询数值 x 的排名
|
|
else if (op == 4)
|
|
printf("%d\n", a[x - 1]); //查询排名为 x 的数值
|
|
else if (op == 5)
|
|
printf("%d\n", *--lower_bound(a.begin(), a.end(), x)); //求数值 x 的前驱
|
|
else if (op == 6)
|
|
printf("%d\n", *upper_bound(a.begin(), a.end(), x)); //求数值 x 的后继
|
|
}
|
|
return 0;
|
|
} |