forked from encrypted-def/basic-algo-lecture
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path21944.cpp
95 lines (88 loc) · 2.21 KB
/
21944.cpp
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Authored by : heheHwang
// Co-authored by : BaaaaaaaaaaarkingDog
// http://boj.kr/c26933e668ff4856874db1108942533c
#include <bits/stdc++.h>
using namespace std;
string op;
int N, L, P, G, x;
pair<int, int> probLevel[100'002]; // 문제의 (난이도, 분류) 저장
set<int> probByL[102]; // 난이도별로 문제 저장
set<int> probByGL[102][102]; // (분류, 난이도) 별로 문제 저장
int main(void) {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> N;
while (N--) {
cin >> P >> L >> G;
probLevel[P] = {L, G};
probByL[L].insert(P);
probByGL[G][L].insert(P);
}
cin >> N;
while (N--) {
cin >> op;
if (op == "recommend") {
cin >> G >> x;
if (x == 1) {
for (int i = 100; i >= 0; i--) {
if (probByGL[G][i].empty()) continue;
cout << *(prev(probByGL[G][i].end())) << '\n';
break;
}
} else {
for (int i = 0; i < 101; i++) {
if (probByGL[G][i].empty()) continue;
cout << *probByGL[G][i].begin() << '\n';
break;
}
}
}
else if(op == "recommend2"){
cin >> x;
if (x == 1) {
for (int i = 100; i >= 0; i--) {
if (probByL[i].empty()) continue;
cout << *(prev(probByL[i].end())) << '\n';
break;
}
} else {
for (int i = 0; i < 101; i++) {
if (probByL[i].empty()) continue;
cout << *probByL[i].begin() << '\n';
break;
}
}
}
else if(op == "recommend3"){
cin >> x >> L;
int ans = -1;
if(x == 1){
for(int i = L; i < 101; i++){
if(probByL[i].empty()) continue;
ans = *probByL[i].begin();
break;
}
}
else{
for(int i = L-1; i >= 0; i--){
if(probByL[i].empty()) continue;
ans = *(prev(probByL[i].end()));
break;
}
}
cout << ans << '\n';
}
else if (op == "add") {
cin >> P >> L >> G;
probLevel[P] = {L, G};
probByL[L].insert(P);
probByGL[G][L].insert(P);
}
else if (op == "solved") {
cin >> P;
tie(L, G) = probLevel[P];
probByL[L].erase(P);
probByGL[G][L].erase(P);
}
}
}