git reimport
This commit is contained in:
@@ -0,0 +1,86 @@
|
||||
package chelper;
|
||||
|
||||
import io.InputReader;
|
||||
import io.OutputWriter;
|
||||
import misc.SimpleSavingChelperSolution;
|
||||
|
||||
|
||||
public class TaskC extends SimpleSavingChelperSolution {
|
||||
|
||||
public void solve(int testNumber, InputReader in, OutputWriter out) {
|
||||
wrapSolve(testNumber, in, out);
|
||||
}
|
||||
|
||||
int m = 31;
|
||||
|
||||
class Node {
|
||||
Node child0;
|
||||
Node child1;
|
||||
|
||||
int count = 0;
|
||||
|
||||
void add(boolean[] x, int i) {
|
||||
count++;
|
||||
|
||||
if (i == m) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (x[i]) {
|
||||
if (child1 == null) {
|
||||
child1 = new Node();
|
||||
}
|
||||
child1.add(x, i + 1);
|
||||
} else {
|
||||
if (child0 == null) {
|
||||
child0 = new Node();
|
||||
}
|
||||
child0.add(x, i + 1);
|
||||
}
|
||||
}
|
||||
|
||||
int remove(boolean[] desired, int i) {
|
||||
count--;
|
||||
|
||||
if (i == m) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Node child = desired[i] ? child1 : child0;
|
||||
boolean node = (child != null && child.count > 0) == desired[i];
|
||||
|
||||
int r = node ? child1.remove(desired, i + 1) : child0.remove(desired, i + 1);
|
||||
int add = (node ? 1 : 0) * (1 << (m - i - 1));
|
||||
|
||||
return r + add;
|
||||
}
|
||||
}
|
||||
|
||||
boolean[] explode(int x) {
|
||||
boolean[] res = new boolean[m];
|
||||
for (int i = 0; i < m; i++) {
|
||||
res[m - i - 1] = x % 2 == 1;
|
||||
x /= 2;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void solve(int testNumber) {
|
||||
int n = in.nextInt();
|
||||
|
||||
Node root = new Node();
|
||||
|
||||
int[] want = in.nextIntArray(n);
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
root.add(explode(in.nextInt()), 0);
|
||||
}
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
int x = root.remove(explode(want[i]), 0) ^ want[i];
|
||||
out.print(x + " ");
|
||||
}
|
||||
out.println();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user