-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path99problems.cpp
More file actions
53 lines (51 loc) · 1.47 KB
/
Copy path99problems.cpp
File metadata and controls
53 lines (51 loc) · 1.47 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 <iostream>
#include <set>
#include <unordered_map>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N, Q; cin >> N >> Q;
unordered_map<int, int> freq;
set<int> problems;
for (int i = 0; i < N; i++) {
int curr; cin >> curr;
if (freq.find(curr) == freq.end())
freq[curr] = 1;
else
freq[curr]++;
problems.insert(curr);
}
for (int i = 0; i < Q; i++) {
int T, D; cin >> T >> D;
if (problems.empty())
cout << -1 << '\n';
else {
if (T == 1) {
auto itr = problems.upper_bound(D);
if (itr == problems.end())
cout << -1 << '\n';
else {
int num = *itr;
cout << num << '\n';
freq[num]--;
if (freq[num] == 0)
problems.erase(num);
}
}
else {
if (D < *problems.begin())
cout << -1 << '\n';
else {
auto itr = problems.upper_bound(D);
itr--;
int num = *itr;
cout << num << '\n';
freq[num]--;
if (freq[num] == 0)
problems.erase(num);
}
}
}
}
}