-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJUST2018A.java
More file actions
61 lines (52 loc) · 2.29 KB
/
Copy pathJUST2018A.java
File metadata and controls
61 lines (52 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.StringTokenizer;
public class JUST2018A {
public static void main(String[] args) throws Exception {
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
int testCase = Integer.parseInt(input.readLine());
StringTokenizer tokenizer;
HashMap<Integer, Integer> values;
int[] arrValues;
StringBuilder out = new StringBuilder();
for (int i = 0; i < testCase; i++) {
tokenizer = new StringTokenizer(input.readLine());
int n = Integer.parseInt(tokenizer.nextToken());
int q = Integer.parseInt(tokenizer.nextToken());
values = new HashMap<>();
arrValues = new int[n];
tokenizer = new StringTokenizer(input.readLine());
for (int j = 0; j < n; j++) {
arrValues[j] = Integer.parseInt(tokenizer.nextToken());
values.put(arrValues[j], values.getOrDefault(arrValues[j], 0) + 1);
}
int moves = values.size();
if (values.containsKey(0)){
moves--;
}
for (int j = 0; j < q; j++) {
tokenizer = new StringTokenizer(input.readLine());
int queryType = Integer.parseInt(tokenizer.nextToken());
if (queryType == 2) {
out.append(moves).append("\n");
} else {
int position = Integer.parseInt(tokenizer.nextToken());
int newValue = Integer.parseInt(tokenizer.nextToken());
if (values.get(arrValues[position - 1]) == 1) {
values.remove(arrValues[position - 1]);
} else {
values.put(arrValues[position - 1], values.getOrDefault(arrValues[position - 1], 0) - 1);
}
values.put(newValue, values.getOrDefault(newValue, 0) + 1);
moves = values.size();
if (values.containsKey(0)){
moves--;
}
arrValues[position - 1] = newValue;
}
}
}
System.out.println(out.toString().trim());
}
}