-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path99problems.cpp
More file actions
53 lines (45 loc) · 1.54 KB
/
99problems.cpp
File metadata and controls
53 lines (45 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
map<ll, int> difficulties1;
map<ll, int> difficulties2;
int N, Q; cin >> N >> Q;
while (N--) {
ll D; cin >> D;
++difficulties1[D];
++difficulties2[-D];
}
while (Q--) {
int T; ll D; cin >> T >> D;
if (T == 1) {
auto itr1 = difficulties1.upper_bound(D);
if (itr1 == difficulties1.end()) {
cout << "-1" << '\n';
} else {
cout << itr1->first << '\n';
--difficulties2[-(itr1->first)];
--(itr1->second);
if (itr1->second == 0) {
difficulties1.erase(itr1);
difficulties2.erase(-(itr1->first));
}
}
} else {
auto itr2 = difficulties2.lower_bound(-D);
if (itr2 == difficulties2.end()) {
cout << "-1" << '\n';
} else {
cout << -(itr2->first) << '\n';
--difficulties1[-(itr2->first)];
--(itr2->second);
if (itr2->second == 0) {
difficulties2.erase(itr2);
difficulties1.erase(-(itr2->first));
}
}
}
}
return 0;
}