- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
Latest commit
24 lines (22 loc) · 1.04 KB
/
Copy pathSolution.java
File metadata and controls
24 lines (22 loc) · 1.04 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
importjava.util.*;
importjava.util.function.BiConsumer;
publicclassSolution {
privatestaticfinalScannerscan = newScanner(System.in);
publicstaticvoidmain(String[] args) {
intn = scan.nextInt();
inti = scan.nextInt();
BitSet[] bitSets = newBitSet[]{newBitSet(n), newBitSet(n)};
Map<String, BiConsumer<Integer, Integer>> ops = newHashMap<>();
ops.put("AND", (input1, input2) -> bitSets[input1 - 1].and(bitSets[input2 - 1]));
ops.put("OR", (input1, input2) -> bitSets[input1 - 1].or(bitSets[input2 - 1]));
ops.put("XOR", (input1, input2) -> bitSets[input1 - 1].xor(bitSets[input2 - 1]));
ops.put("SET", (input1, input2) -> bitSets[input1 - 1].set(input2));
ops.put("FLIP", (input1, input2) -> bitSets[input1 - 1].flip(input2));
while (i > 0) {
ops.get(scan.next()).accept(scan.nextInt(), scan.nextInt());
System.out.println(bitSets[0].cardinality() + " " + bitSets[1].cardinality());
i--;
}
scan.close();
}
}