Files
python/TangDou/AcWing/BalanceTree/253_Vecotr.cpp

31 lines
977 B
C++
Raw Normal View History

2025-08-30 18:35:01 +08:00
#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;
}