fork(1) download
  1. import java.util.*;
  2. import java.io.*;
  3. import java.text.*;
  4. class Code{
  5. static final long MOD = (long)1e9+7, mod = 1;
  6. static int MAX = (int)1e6+1;
  7. static int INF = (int)1e9;
  8. static final double eps = (double)1e-9;
  9. static DecimalFormat df = new DecimalFormat("0.00000000");
  10. static FastReader in;
  11. static final int L = 31;
  12. static int N;
  13. static int[] v, T;
  14. static StringBuilder out = new StringBuilder("");
  15. public static void main(String[] args){
  16. in = new FastReader();
  17. int N = ni();
  18. v = new int[N]; T = new int[N];
  19. for(int i = 0; i< N; i++)v[i] = ni();
  20. Node root = new Node();
  21. for(int i = 0; i< N; i++){
  22. T[i] = ni();
  23. add(root, i, T[i], L-1);
  24. }
  25. int[] ans = new int[N];
  26. for(int i = 0; i< N; i++){
  27. int val = v[i];
  28. Node t = root;
  29. for(int l = L-1; l>=0; l--){
  30. if(t.child[(val>>l)&1] != null && t.child[(val>>l)&1].set.size()>0){
  31. t = t.child[(val>>l)&1];
  32. }else if(t.child[((val>>l)&1)^1] != null && t.child[((val>>l)&1)^1].set.size()>0){
  33. t = t.child[1^((val>>l)&1)];
  34. }
  35. }
  36. int x = 0;
  37. for(int p:t.set){
  38. x = p;
  39. break;
  40. }
  41. ans[i] = v[i]^T[x];
  42. remove(root, x, L-1);
  43. }
  44. for(int i:ans)out.append(i+" ");
  45. pn(out.toString());
  46. }
  47.  
  48.  
  49. static long mod(long a){
  50. return (a%mod+mod)%mod;
  51. }
  52.  
  53. static void add(Node root, int i, int x, int d){
  54. root.set.add(i);
  55. if(root.child[(x>>d)&1]==null)root.child[(x>>d)&1] = new Node();
  56. if(d>0)add(root.child[(x>>d)&1],i, x,d-1);
  57. }
  58.  
  59. static void remove(Node root, int i, int d){
  60. root.set.remove(i);
  61. if(d>0)remove(root.child[(T[i]>>d)&1],i,d-1);
  62. }
  63.  
  64.  
  65. static class Node{
  66. HashSet<Integer> set;
  67. Node[] child;
  68. public Node(){
  69. set = new HashSet<Integer>();
  70. child = new Node[2];
  71. }
  72. }
  73.  
  74. static long gcd(long a,long b){
  75. return (b==0)?a:gcd(b,a%b);
  76. }
  77.  
  78. static void pn(Object o){
  79. System.out.println(o);
  80. }
  81.  
  82. static void p(Object o){
  83. System.out.print(o);
  84. }
  85.  
  86. static String n(){
  87. return in.next();
  88. }
  89.  
  90. static String nln(){
  91. return in.nextLine();
  92. }
  93.  
  94. static int ni(){
  95. return Integer.parseInt(in.next());
  96. }
  97.  
  98. static long nl(){
  99. return Long.parseLong(in.next());
  100. }
  101.  
  102. static double nd(){
  103. return Double.parseDouble(in.next());
  104. }
  105.  
  106. static class FastReader{
  107. public FastReader(){
  108. }
  109.  
  110. public FastReader(String s) throws Exception{
  111. br = new BufferedReader(new FileReader(s));
  112. }
  113.  
  114.  
  115. String next(){
  116. while (st == null || !st.hasMoreElements()){
  117. try{
  118. st = new StringTokenizer(br.readLine());
  119. }catch (IOException e){
  120. e.printStackTrace();
  121. }
  122. }
  123. return st.nextToken();
  124. }
  125.  
  126. String nextLine(){
  127. String str = "";
  128. try{
  129. str = br.readLine();
  130. }catch (IOException e){
  131. e.printStackTrace();
  132. }
  133. return str;
  134. }
  135. }
  136.  
  137. }
Success #stdin #stdout 0.07s 29216KB
stdin
5
12 7 87 22 11
18 39 9 12 16
stdout
0 14 69 6 44