fork download
  1. #include <iostream>
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. int main() {
  6. // your code goes here
  7. int n,w,s;
  8. cin>>s;
  9. while(s--){
  10. cin>>n;
  11. vector<int> a(n);
  12. int mx=0;
  13. for(int i=0;i<n;i++){
  14. cin>>a[i];
  15. if(mx<a[i]) mx=a[i];
  16. }
  17.  
  18. vector<int> ans;
  19. int x=2;
  20. int mn=100001;
  21. int flg=0;
  22. unordered_set <int> mp;
  23. for(int i=0;i<n;i++){
  24. flg=0;
  25. mn=100000;
  26. for(int j=0;j<n;j++){
  27. x=0;
  28.  
  29. while(x<=10 && i!=j){
  30. if(((a[i] | a[j])+1)==pow(2,x)){
  31. flg=1;
  32. if(mn>a[j])
  33. mn=a[j];
  34.  
  35. }
  36. x++;
  37. }
  38.  
  39.  
  40. }
  41. if(flg==1)
  42. ans.push_back(mn);
  43. if(flg==0)
  44. ans.push_back(-1);
  45.  
  46. }
  47.  
  48. //unique(ans.begin(),ans.end());
  49. for(int i=0;i<ans.size();i++){
  50. cout<<ans[i]<<" ";
  51. }
  52. cout<<"\n";
  53. }
  54. return 0;
  55. }
Success #stdin #stdout 0s 4400KB
stdin
2
4
2 13 19 5
7
11 23 27 33 21 50 24
stdout
5 2 13 2 
21 11 21 -1 11 -1 23