8000 Update 21944.cpp · kimhaech/basic-algo-lecture@5d921ac · GitHub
[go: up one dir, main page]

Skip to content

Commit 5d921ac

Browse files
committed
Update 21944.cpp
1 parent 816221b commit 5d921ac

File tree

1 file changed

+81
-4
lines changed

1 file changed

+81
-4
lines changed

0x16/solutions/21944.cpp

Lines changed: 81 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,88 @@
1-
// Authored by : BaaaaaaaaaaarkingDog
1+
// Authored by : heheHwang
22
// Co-authored by : -
3-
// http://boj.kr/****************
3+
// http://boj.kr/f24803c9e97348e5b803f336bc044f52
44
#include <bits/stdc++.h>
55
using namespace std;
66

7-
int main(void){
7+
string op;
8+
int G, N, L, P, x;
9+
pair<int, int> probinfo[100'002]; // 문제별 분류, 난이도 저장
10+
map<int, map<int, set<int>>> probDB; // probDB[분류][난이도]
11+
void insertDB(int P, int L, int G) {
12+
probinfo[P] = {G, L};
13+
if (probDB.find(G) == probDB.end())
14+
probDB.insert({G, map<int, set<int>>()});
15+
if (probDB[G].find(L) == probDB[G].end())
16+
probDB[G].insert({L, set<int>()});
17+
probDB[G][L].insert(P);
18+
}
19+
int main(void) {
820
ios::sync_with_stdio(0);
921
cin.tie(0);
10-
22+
23+
cin >> N;
24+
while (N--) {
25+
cin >> P >> L >> G;
26+
insertDB(P, L, G);
27+
}
28+
cin >> N;
29+
while (N--) {
30+
cin >> op;
31+
if (op == "recommend") {
32+
cin >> G >> x;
33+
if (x == 1)
34+
cout << *(probDB[G].rbegin()->second.rbegin()) << '\n';
35+
else
36+
cout << *(probDB[G].begin()->second.begin()) << '\n';
37+
} else if (op == "recommend2") {
38+
cin >> x;
39+
pair<int, int> mxv = {0, -1};
40+
pair<int, int> mnv = {102, 100'002};
41+
for (auto &group : probDB) {
42+
if (x == 1) {
43+
auto gMxLevKV = group.second.rbegin();
44+
pair<int, int> gv = {gMxLevKV->first, *gMxLevKV->second.rbegin()};
45+
mxv = max(mxv, gv);
46+
} else {
47+
auto gMnLevKV = group.second.begin();
48+
pair<int, int> gv = {gMnLevKV->first, *gMnLevKV->second.begin()};
49+
mnv = min(mnv, gv);
50+
}
51+
}
52+
cout << (x == 1 ? mxv.second : mnv.second) << '\n';
53+
54+
} else if (op == "recommend3") {
55+
cin >> x >> L;
56+
pair<int, int> mxv = {0, -1};
57+
pair<int, int> mnv = {102, 100'002};
58+
for (auto &group : probDB) {
59+
for (auto &level : group.second) {
60+
if (x == 1) {
61+
if (level.first < L) continue;
62+
pair<int, int> lv = {level.first, *level.second.begin()};
63+
if (lv < mnv) mnv = lv;
64+
} else {
65+
if (L <= level.first) continue;
66+
pair<int, int> lv = {level.first, *level.second.rbegin()};
67+
if (mxv < lv) mxv = lv;
68+
}
69+
}
70+
}
71+
if (x == 1)
72+
cout << (mnv.first == 102 ? -1 : mnv.second) << '\n';
73+
else
74+
cout << (mxv.first == 0 ? -1 : mxv.second) << '\n';
75+
76+
} else if (op == "add") {
77+
cin >> P >> L >> G;
78+
insertDB(P, L, G);
79+
80+
} else if (op == "solved") {
81+
cin >> P;
82+
auto [G, L] = probinfo[P];
83+
probDB[G][L].erase(P);
84+
if (probDB[G][L].empty()) probDB[G].erase(L);
85+
if (probDB[G].empty()) probDB.erase(G);
86+
}
87+
}
1188
}

0 commit comments

Comments
 (0)
0