1
- // Authored by : BaaaaaaaaaaarkingDog
2
- // Co-authored by : -
3
- // http://boj.kr/****************
1
+ // Authored by : heheHwang
2
+ // Co-authored by : BaaaaaaaaaaarkingDog
3
+ // http://boj.kr/c26933e668ff4856874db1108942533c
4
4
#include < bits/stdc++.h>
5
5
using namespace std ;
6
6
7
- int main (void ){
7
+ string op;
8
+ int N, L, P, G, x;
9
+ pair<int , int > probLevel[100'002 ]; // 문제의 (난이도, 분류) 저장
10
+ set<int > probByL[102 ]; // 난이도별로 문제 저장
11
+ set<int > probByGL[102 ][102 ]; // (분류, 난이도) 별로 문제 저장
12
+
13
+ int main (void ) {
8
14
ios::sync_with_stdio (0 );
9
15
cin.tie (0 );
10
-
11
- }
16
+
17
+ cin >> N;
18
+ while (N--) {
19
+ cin >> P >> L >> G;
20
+ probLevel[P] = {L, G};
21
+ probByL[L].insert (P);
22
+ probByGL[G][L].insert (P);
23
+ }
24
+ cin >> N;
25
+ while (N--) {
26
+ cin >> op;
27
+ if (op == " recommend" ) {
28
+ cin >> G >> x;
29
+ if (x == 1 ) {
30
+ for (int i
10000
= 100 ; i >= 0 ; i--) {
31
+ if (probByGL[G][i].empty ()) continue ;
32
+ cout << *(prev (probByGL[G][i].end ())) << ' \n ' ;
33
+ break ;
34
+ }
35
+ } else {
36
+ for (int i = 0 ; i < 101 ; i++) {
37
+ if (probByGL[G][i].empty ()) continue ;
38
+ cout << *probByGL[G][i].begin () << ' \n ' ;
39
+ break ;
40
+ }
41
+ }
42
+ }
43
+
44
+ else if (op == " recommend2" ){
45
+ cin >> x;
46
+ if (x == 1 ) {
47
+ for (int i = 100 ; i >= 0 ; i--) {
48
+ if (probByL[i].empty ()) continue ;
49
+ cout << *(prev (probByL[i].end ())) << ' \n ' ;
50
+ break ;
51
+ }
52
+ } else {
53
+ for (int i = 0 ; i < 101 ; i++) {
54
+ if (probByL[i].empty ()) continue ;
55
+ cout << *probByL[i].begin () << ' \n ' ;
56
+ break ;
57
+ }
58
+ }
59
+ }
60
+
61
+ else if (op == " recommend3" ){
62
+ cin >> x >> L;
63
+ int ans = -1 ;
64
+ if (x == 1 ){
65
+ for (int i = L; i < 101 ; i++){
66
+ if (probByL[i].empty ()) continue ;
67
+ ans = *probByL[i].begin ();
68
+ break ;
69
+ }
70
+ }
71
+ else {
72
+ for (int i = L-1 ; i >= 0 ; i--){
73
+ if (probByL[i].empty ()) continue ;
74
+ ans = *(prev (probByL[i].end ()));
75
+ break ;
76
+ }
77
+ }
78
+ cout << ans << ' \n ' ;
79
+ }
80
+
81
+ else if (op == " add" ) {
82
+ cin >> P >> L >> G;
83
+ probLevel[P] = {L, G};
84
+ probByL[L].insert (P);
85
+ probByGL[G][L].insert (P);
86
+ }
87
+
88
+ else if (op == " solved" ) {
89
+ cin >> P;
90
+ tie (L, G) = probLevel[P];
91
+ probByL[L].erase (P);
92
+ probByGL[G][L].erase (P);
93
+ }
94
+ }
95
+ }
0 commit comments