fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4.  
  5. const ll max_mask = (1LL << 22);
  6.  
  7. ll n, a[1000005];
  8. ll dp[max_mask];
  9.  
  10. int main(){
  11. ios_base::sync_with_stdio(0);
  12. cin.tie(0);
  13.  
  14. cin >> n;
  15.  
  16. memset(dp, -1, sizeof(dp));
  17.  
  18. for (ll i = 1; i <= n; i++){
  19. cin >> a[i];
  20. dp[a[i]] = a[i];
  21. }
  22.  
  23. for (ll bit = 0; bit < 22; bit++){
  24. for (ll mask = 0; mask < max_mask; mask++){
  25. if (mask & (1LL << bit)){
  26. if (dp[mask] == -1){
  27. dp[mask] = dp[mask ^ (1LL << bit)];
  28. }
  29. }
  30. }
  31. }
  32.  
  33. ll full = max_mask - 1;
  34.  
  35. for (ll i = 1; i <= n; i++){
  36. cout << dp[full ^ a[i]] << ' ';
  37. }
  38.  
  39. return 0;
  40. }
  41.  
Success #stdin #stdout 0.11s 34688KB
stdin
Standard input is empty
stdout
Standard output is empty