Skip to content

Commit a375ebe

Browse files
authored
[20250404] BOJ / G3 / 홍익 투어리스트 / 권혁준
1 parent 32ff104 commit a375ebe

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
```java
2+
3+
import java.util.*;
4+
import java.io.*;
5+
6+
class Main {
7+
8+
// IO field
9+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
10+
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
11+
static StringTokenizer st = new StringTokenizer("");
12+
13+
static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());}
14+
static String nextToken() throws Exception {
15+
while(!st.hasMoreTokens()) nextLine();
16+
return st.nextToken();
17+
}
18+
static int nextInt() throws Exception { return Integer.parseInt(nextToken()); }
19+
static long nextLong() throws Exception { return Long.parseLong(nextToken()); }
20+
static double nextDouble() throws Exception { return Double.parseDouble(nextToken()); }
21+
static void bwEnd() throws Exception {bw.flush();bw.close();}
22+
23+
// Additional field
24+
25+
static int N, Q;
26+
static int[] A;
27+
static TreeSet<Integer> T;
28+
29+
public static void main(String[] args) throws Exception {
30+
31+
ready();
32+
solve();
33+
34+
bwEnd();
35+
36+
}
37+
38+
static void ready() throws Exception{
39+
40+
N = nextInt();
41+
Q = nextInt();
42+
T = new TreeSet<>();
43+
for(int i=0;i<N;i++) if(nextInt() == 1) T.add(i);
44+
45+
}
46+
47+
static void solve() throws Exception{
48+
49+
int cur = 0;
50+
for(;Q-->0;) {
51+
int op, x;
52+
op = nextInt();
53+
54+
if(op == 3) {
55+
Integer temp = T.ceiling(cur);
56+
int m1 = -1;
57+
if(temp != null) {
58+
m1 = temp;
59+
bw.write((m1-cur) + "\n");
60+
continue;
61+
}
62+
temp = T.ceiling(0);
63+
int m2 = -1;
64+
if(temp != null) {
65+
m2 = temp;
66+
bw.write((N-cur+m2) + "\n");
67+
continue;
68+
}
69+
bw.write("-1\n");
70+
71+
}
72+
else {
73+
x = nextInt();
74+
if(op == 1) {
75+
if(T.contains(x-1)) T.remove(x-1);
76+
else T.add(x-1);
77+
}
78+
else {
79+
cur = (cur + x) % N;
80+
}
81+
}
82+
}
83+
84+
}
85+
86+
}
87+
88+
```

0 commit comments

Comments
 (0)