forked from alexprut/HackerRank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Solution.java
60 lines (52 loc) · 1.42 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
import java.io.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
BitSet A = new BitSet(n);
BitSet B = new BitSet(n);
for (int i = 0; i < m; i++) {
String query = sc.next();
int x = sc.nextInt();
int y = sc.nextInt();
if (query.equals("AND")) {
if (x == 1) {
A.and(B);
} else {
B.and(A);
}
}
if (query.equals("OR")) {
if (x == 1) {
A.or(B);
} else {
B.or(A);
}
}
if (query.equals("XOR")) {
if (x == 1) {
A.xor(B);
} else {
B.xor(A);
}
}
if (query.equals("FLIP")) {
if (x == 1) {
A.flip(y);
} else {
B.flip(y);
}
}
if (query.equals("SET")) {
if (x == 1) {
A.set(y);
} else {
B.set(y);
}
}
System.out.println(A.cardinality() + " " + B.cardinality());
}
}
}