-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution.java
63 lines (60 loc) · 1.73 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int N = scan.nextInt();
int M = scan.nextInt();
BitSet B1 = new BitSet(N);
BitSet B2 = new BitSet(N);
while (M-- > 0) {
String str = scan.next();
int a = scan.nextInt();
int b = scan.nextInt();
switch (str) {
case "AND":
if (a == 1) {
B1.and(B2);
} else {
B2.and(B1);
}
break;
case "OR":
if (a == 1) {
B1.or(B2);
} else {
B2.or(B1);
}
break;
case "XOR":
if (a == 1) {
B1.xor(B2);
} else {
B2.xor(B1);
}
break;
case "FLIP":
if (a == 1) {
B1.flip(b);
} else {
B2.flip(b);
}
break;
case "SET":
if (a == 1) {
B1.set(b);
} else {
B2.set(b);
}
break;
default:
break;
}
System.out.println(B1.cardinality() + " " + B2.cardinality());
}
scan.close();
}
}