mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2025-02-17 14:26:47 +00:00
D - Sequence Query
https://atcoder.jp/contests/abc241/submissions/29690486
This commit is contained in:
parent
27fdb57d61
commit
9a6693b2bd
58
AtCoder/ABC241/D/D.cpp
Normal file
58
AtCoder/ABC241/D/D.cpp
Normal 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;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user