8000 Merge pull request #270 from hehehwang/0x16-23326 · w10gd/basic-algo-lecture@683a28d · GitHub
[go: up one dir, main page]

Skip to content

Commit 683a28d

Browse files
Merge pull request encrypted-def#270 from hehehwang/0x16-23326
(0x16 이진 검색 트리) Update 23326.cpp
2 parents f12bfec + 362869d commit 683a28d

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

0x16/solutions/23326.cpp

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

7-
int main(void){
7+
int main(void) {
88
ios::sync_with_stdio(0);
99
cin.tie(0);
10-
10+
11+
set<int> hu; // 홍익대학교의 명소들 위치
12+
int N, Q, t, curr = 1;
13+
cin >> N >> Q;
14+
for (int i = 1; i <= N; i++) {
15+
cin >> t;
16+
if (t) hu.insert(i);
17+
}
18+
while (Q--) {
19+
cin >> t;
20+
switch (t) {
21+
case 1:
22+
cin >> t;
23+
if (hu.find(t) != hu.end())
24+
hu.erase(t);
25+
else
26+
hu.insert(t);
27+
break;
28+
case 2:
29+
cin >> t;
30+
curr = (curr + t - 1) % N + 1;
31+
break;
32+
case 3:
33+
if (hu.empty()) cout << -1 << '\n';
34+
else {
35+
auto it = hu.lower_bound(curr);
36+
if (it != hu.end())
37+
cout << *it - curr << '\n';
38+
else
39+
cout << N - curr + *hu.begin() << '\n';
40+
}
41+
}
42+
}
1143
}

0 commit comments

Comments
 (0)
0