0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-27 16:16:25 +00:00

D - Sequence Query

https://atcoder.jp/contests/abc241/submissions/29690486
This commit is contained in:
Baoshuo Ren 2022-02-26 20:48:34 +08:00
parent 27fdb57d61
commit 9a6693b2bd
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

58
AtCoder/ABC241/D/D.cpp Normal file
View File

@ -0,0 +1,58 @@
#include <iostream>
#include <set>
using std::cin;
using std::cout;
const char endl = '\n';
long long q, op, x, k;
std::multiset<long long> set, s2;
int main() {
std::ios::sync_with_stdio(false);
cin >> q;
while (q--) {
cin >> op >> x;
if (op == 1) {
set.insert(x);
s2.insert(-x);
} else if (op == 2) {
bool flag = false;
cin >> k;
auto it = s2.lower_bound(-x);
if (it == s2.end()) {
cout << -1 << endl;
continue;
}
for (int i = 1; i < k; i++) {
if (++it == s2.end()) {
cout << -1 << endl;
flag = true;
break;
}
}
if (!flag) {
cout << -*it << endl;
}
} else {
bool flag = false;
cin >> k;
auto it = set.lower_bound(x);
if (it == set.end()) {
cout << -1 << endl;
continue;
}
for (int i = 1; i < k; i++) {
if (++it == set.end()) {
cout << -1 << endl;
flag = true;
break;
}
}
if (!flag) {
cout << *it << endl;
}
}
}
return 0;
}