fork(1) download
  1. /**
  2. Template by Akikaze (秋風) - formerly proptit_4t41.
  3. Code written by a random fan of momocashew and Chiho.
  4.  
  5. H△G x Mili - November 27th, 2013
  6. Mag Mell (Mili) - Sep 17th, 2014
  7. H△G x Mili Vol.2 - May 9th, 2015
  8. Miracle Milk (Mili) - Oct 12th, 2016
  9. 青色フィルム (H△G) - February 14th, 2018
  10. Millennium Mother (Mili) - April 25th, 2018
  11. **/
  12.  
  13. /** -----PRAGMA----- **/
  14. #pragma comment(linker, "/stack:200000000")
  15. #pragma GCC optimize("Ofast")
  16. #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
  17.  
  18. #include <bits/stdc++.h>
  19. using namespace std;
  20.  
  21. /** -----BASIC MACROES----- **/
  22. #define endl '\n'
  23. #define i64 long long
  24. #define ld long double
  25. #define pub push_back
  26. #define mp make_pair
  27. #define fi first
  28. #define se second
  29. const long long MOD = 1000000007LL, INF = 1e9, LINF = 1e18;
  30. const long double PI = 3.141592653589793116, EPS = 1e-9, GOLD = ((1+sqrt(5))/2);
  31. typedef vector<i64> vi;
  32. typedef vector<ld> vd;
  33. typedef vector<string> vs;
  34. typedef vector<bool> vb;
  35. typedef pair<i64, i64> pii;
  36. typedef pair<i64, pii> pip;
  37. typedef pair<pii, i64> ppi;
  38.  
  39. /** -----BIT CONTROLS----- **/
  40. template<class T> int getbit(T s, int i) { return (s >> 1) & 1; }
  41. template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
  42. template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
  43. template<class T> int cntbit(T s) { return __builtin_popcount(s); }
  44.  
  45. /** -----IDEAS/ALGORITHMS-----
  46.  
  47.   -------------------------- **/
  48.  
  49. /** -----CUSTOM TYPEDEFS/DEFINES----- **/
  50.  
  51.  
  52. /** -----GLOBAL VARIABLES----- **/
  53. i64 N; vi A; multiset<i64> P;
  54.  
  55. /** -----EXTENSIVE FUNCTIONS----- **/
  56.  
  57.  
  58. /** -----COMPULSORY FUNCTIONS----- **/
  59. void VarInput() {
  60. //ios_base::sync_with_stdio(0); cin.tie(NULL);
  61. cin >> N; A.resize(N);
  62. for (i64 i=0; i<N; i++) cin >> A[i];
  63. for (i64 i=0; i<N; i++) {
  64. i64 x; cin >> x; P.insert(x);
  65. }
  66. }
  67.  
  68. void ProSolve() {
  69. for (i64 i=0; i<N; i++) {
  70. i64 optimal = 0;
  71. for (i64 j=29; j>=0; j--) {
  72. //cout << "bitOn = " << (i & (1LL << j)) << endl;
  73. if ((A[i] & (1LL << j)) == 0) {
  74. auto ite1 = P.lower_bound(optimal), ite2 = P.lower_bound(optimal+(1LL << j));
  75. if (ite1 == ite2) optimal += (1LL << j);
  76. }
  77. else {
  78. auto ite1 = P.lower_bound(optimal+(1LL << j)), ite2 = P.lower_bound(optimal+(1LL << j)+(1LL << j));
  79. if (ite1 != ite2) optimal += (1LL << j);
  80. }
  81. //cout << "working at j = " << j << ": optimal = " << optimal << endl;
  82. }
  83. //cout << "optimal = " << optimal << endl;
  84. P.erase(P.find(optimal));
  85. cout << (A[i] ^ optimal) << " ";
  86. }
  87. }
  88.  
  89. /** -----MAIN FUNCTION----- **/
  90. int main() {
  91. #ifdef Akikaze
  92. //freopen("FILE.INP", "r", stdin);
  93. //freopen("FILE.OUT", "w", stdout);
  94. #endif
  95. VarInput();
  96. #ifdef Akikaze
  97. auto TIME1 = chrono::steady_clock::now();
  98. #endif
  99. ProSolve();
  100. #ifdef Akikaze
  101. auto TIME2 = chrono::steady_clock::now();
  102. auto DIFF = TIME2 - TIME1;
  103. cout << "\n\nTime elapsed: " << fixed << setprecision(18) << chrono::duration<double>(DIFF).count() << " seconds.";
  104. #endif
  105. return 0;
  106. }
Success #stdin #stdout 0s 4548KB
stdin
10
331415699 278745619 998190004 423175621 42983144 166555524 843586353 802130100 337889448 685310951
226011312 266003835 342809544 504667531 529814910 684873393 817026985 844010788 993949858 1031395667
stdout
128965467 243912600 4281110 112029883 223689619 76924724 429589 119397893 613490433 362863284