-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path21939.cpp
More file actions
69 lines (57 loc) ยท 1.27 KB
/
21939.cpp
File metadata and controls
69 lines (57 loc) ยท 1.27 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
#define endl "\n"
#define MAX 1e8
struct coordinate {
int x;
int y;
};
int dx[] = {0, 1, -1, 0, 1, -1, -1, 1};
int dy[] = {1, 0, 0, -1, -1, 1, -1, 1};
int N, M;
unordered_map<int, int> um;
set<pair<int, int>> st;
void input() {
cin >> N;
for(int i = 0; i < N; i++) {
int a, b;
cin >> a >> b;
um[a] = b;
st.insert({b, a});
}
cin >> M;
for(int i = 0; i < M; i++) {
string a;
cin >> a;
if(a == "add") {
int b, c;
cin >> b >> c;
um[b] = c;
st.insert({c, b});
}
else if(a == "recommend") {
int b;
cin >> b;
if(b == 1) { // ๊ฐ์ฅ ์ด๋ ค์ด ๋ฌธ์
auto it = st.rbegin();
cout << it -> second << endl;
}
else { // ๊ฐ์ฅ ์ฌ์ด ๋ฌธ์
auto it = st.begin();
cout << it -> second << endl;
}
}
else {
int b;
cin >> b;
st.erase({um[b], b});
}
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
input();
}