Skip to content

Commit 5c35721

Browse files
authored
[20250920] BOJ / G3 / Missing Number Queries / 권혁준
1 parent 08eb5a8 commit 5c35721

File tree

1 file changed

+103
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)