fork 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. ans[i] = v[i]^T[t.set.first()];
  37. remove(root, t.set.first(), L-1);
  38. }
  39. for(int i:ans)out.append(i+" ");
  40. pn(out.toString());
  41. }
  42.  
  43.  
  44. static long mod(long a){
  45. return (a%mod+mod)%mod;
  46. }
  47.  
  48. static void add(Node root, int i, int x, int d){
  49. root.set.add(i);
  50. if(root.child[(x>>d)&1]==null)root.child[(x>>d)&1] = new Node();
  51. if(d>0)add(root.child[(x>>d)&1],i, x,d-1);
  52. }
  53.  
  54. static void remove(Node root, int i, int d){
  55. root.set.remove(i);
  56. if(d>0)remove(root.child[(T[i]>>d)&1],i,d-1);
  57. }
  58.  
  59.  
  60. static class Node{
  61. TreeSet<Integer> set;
  62. Node[] child;
  63. public Node(){
  64. set = new TreeSet<Integer>();
  65. child = new Node[2];
  66. }
  67. }
  68.  
  69. static long gcd(long a,long b){
  70. return (b==0)?a:gcd(b,a%b);
  71. }
  72.  
  73. static void pn(Object o){
  74. System.out.println(o);
  75. }
  76.  
  77. static void p(Object o){
  78. System.out.print(o);
  79. }
  80.  
  81. static String n(){
  82. return in.next();
  83. }
  84.  
  85. static String nln(){
  86. return in.nextLine();
  87. }
  88.  
  89. static int ni(){
  90. return Integer.parseInt(in.next());
  91. }
  92.  
  93. static long nl(){
  94. return Long.parseLong(in.next());
  95. }
  96.  
  97. static double nd(){
  98. return Double.parseDouble(in.next());
  99. }
  100.  
  101. static class FastReader{
  102. public FastReader(){
  103. }
  104.  
  105. public FastReader(String s) throws Exception{
  106. br = new BufferedReader(new FileReader(s));
  107. }
  108.  
  109.  
  110. String next(){
  111. while (st == null || !st.hasMoreElements()){
  112. try{
  113. st = new StringTokenizer(br.readLine());
  114. }catch (IOException e){
  115. e.printStackTrace();
  116. }
  117. }
  118. return st.nextToken();
  119. }
  120.  
  121. String nextLine(){
  122. String str = "";
  123. try{
  124. str = br.readLine();
  125. }catch (IOException e){
  126. e.printStackTrace();
  127. }
  128. return str;
  129. }
  130. }
  131.  
  132. }
Success #stdin #stdout 0.12s 29108KB
stdin
5
12 7 87 22 11
18 39 9 12 16
stdout
0 14 69 6 44