-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaBitSet.java
More file actions
35 lines (31 loc) · 851 Bytes
/
JavaBitSet.java
File metadata and controls
35 lines (31 loc) · 851 Bytes
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
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int m = input.nextInt();
int n = input.nextInt();
BitSet[] B = {new BitSet(m), new BitSet(m)};
for (int i = 0; i < n; i++) {
String op = input.next();
int param1 = input.nextInt();
int param2 = input.nextInt();
switch (op) {
case "AND":
B[param1-1].and(B[param2-1]);
break;
case "OR":
B[param1-1].or(B[param2-1]);
break;
case "XOR":
B[param1-1].xor(B[param2-1]);
break;
case "SET":
B[param1-1].set(param2);
break;
case "FLIP":
B[param1-1].flip(param2);
}
System.out.println(B[0].cardinality() + " " + B[1].cardinality());
}
}
}