-
Notifications
You must be signed in to change notification settings - Fork 183
/
Copy pathSolution.java
38 lines (34 loc) · 1.08 KB
/
Solution.java
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
import java.util.*;
class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
BitSet[] bits = {new BitSet(n), new BitSet(n)};
for (int i = 0; i < m; i++) {
String operation = sc.next();
int x = sc.nextInt();
int y = sc.nextInt();
switch (operation) {
case "AND":
bits[x - 1].and(bits[y - 1]);
break;
case "OR":
bits[x - 1].or(bits[y - 1]);
break;
case "XOR":
bits[x - 1].xor(bits[y - 1]);
break;
case "FLIP":
bits[x - 1].flip(y);
break;
case "SET":
bits[x - 1].set(y);
break;
default:
break;
}
System.out.println(bits[0].cardinality() + " " + bits[1].cardinality());
}
}
}