-
Notifications
You must be signed in to change notification settings - Fork 0
/
Java-BitSet.java
143 lines (135 loc) · 5.24 KB
/
Java-BitSet.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
/*public static void printBit(BitSet b)
{
int n = b.size();
int cnt = 0;
for(int i=0;i<n;i++)
{
if(b.isEmpty())
{
System.out.println("0 0");
}
else
{
if(b.get(i)==)
System.out.println(b.get(0)+" "+b.get(1));
}
}
}//*/
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
BitSet b1 = new BitSet(n);
BitSet b2 = new BitSet(n);
sc.nextLine();
for(int i=0;i<m;i++)
{
String line = sc.next();
//String[] op = line.split(" ");
String[] op = new String[2];
op[0] = sc.next();
op[1] = sc.next();
switch (line)
{
case "AND":
if(op[0].equals("1") && op[1].equals("1"))
{
b1.and(b1);
//printBit(b1);
}
else if(op[0].equals("1") && op[1].equals("2"))
{
b1.and(b2);
//printBit(b2);
}
else if(op[0].equals("2") && op[1].equals("1"))
{
b2.and(b1);
//printBit(b2);
}
else
{
b2.and(b2);
//printBit(b2);
}//*/
break;
case "OR": if(op[0].equals("1") && op[1].equals("1"))
{
b1.or(b1);
//printBit(b1);
}
else if(op[0].equals("1") && op[1].equals("2"))
{
b1.or(b2);
//printBit(b2);
}
else if(op[0].equals("2") && op[1].equals("1"))
{
b2.or(b1);
//printBit(b2);
}
else
{
b2.or(b2);
//printBit(b2);
}
break;
case "XOR": if(op[0].equals("1") && op[1].equals("1"))
{
b1.xor(b1);
//printBit(b1);
}
else if(op[0].equals("1") && op[1].equals("2"))
{
b1.xor(b2);
//printBit(b2);
}
else if(op[0].equals("2") && op[1].equals("1"))
{
b2.xor(b1);
//printBit(b2);
}
else
{
b2.xor(b2);
//printBit(b2);
}
break;
case "FLIP":if(op[0].equals("1"))
{
b1.flip(Integer.parseInt(op[1]));
//printBit(b1);
// System.out.println(b1.cardinality()+" "+b2.cardinality());
}
else
{
b2.flip(Integer.parseInt(op[1]));
//printBit(b2);
// System.out.println(b1.cardinality()+" "+b2.cardinality());
}
break;
case "SET":if(op[0].equals("1"))
{
b1.set(Integer.parseInt(op[1]));
//printBit(b1);
// System.out.println(b1.cardinality()+" "+b2.cardinality());
}
else
{
b2.set(Integer.parseInt(op[1]));
//printBit(b2);
// System.out.println(b1.cardinality()+" "+b2.cardinality());
}
break;//*/
}
System.out.println(b1.cardinality()+" "+b2.cardinality());
}
}
}