fork download
  1.  
  2. ////////////// VATSAL AGARWAL ////////////////////////
  3. ////////////// Codeforces id : warhead38 ////////////////////////
  4. ////////////// Codechef id : vatsal38 ////////////////////////
  5.  
  6.  
  7. #include <bits/stdc++.h>
  8. #include <ext/pb_ds/assoc_container.hpp>
  9. #include <ext/pb_ds/tree_policy.hpp>
  10. using namespace std;
  11. using namespace __gnu_pbds;
  12. typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
  13. #define ll long long int
  14. #define ull unsigned long long int
  15. #define ld long double
  16. #define endl '\n'
  17. #define loop(a,b,c) for(ll i=a;i<=b;i+=c)
  18. #define intarr(arr,n) ll arr[n];for(ll i=0;i<n;i++)cin>>arr[i]
  19. #define inparr(arr,n) for(ll i=0;i<n;i++)cin>>arr[i]
  20. #define inpvec(vec,n) for(ll i=0;i<n;i++){ll var;cin>>var;vec.push_back(var);}
  21. #define pb push_back
  22. #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
  23. #define mod 1000000007
  24. #define newline cout<<endl
  25. #define ump unordered_map<ll,ll>
  26. #define vec vector<ll>
  27. #define mkp make_pair
  28. #define disp(var1,var2) cout<<var1<<" "<<var2<<endl;
  29. #define all(v) v.begin(),v.end()
  30. #define cout(var) cout<<var<<endl
  31. #define mod2 998244353
  32. #define fbo find_by_order /// find kth smallest by passing k-1
  33. #define ook order_of_key //// find no of smaller items less than k
  34. #define teensort(a,r,g,b) a[0]=r;a[1]=g;a[2]=b;sort(a,a+3);
  35. #define ss second
  36. #define ff first
  37. #define displayarray(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" "; cout<<endl;
  38. #define pi pair<ll,ll>
  39. #define meramax 1e18
  40. #define meramin -1e18
  41. #define percentile 1000000007
  42. #define PI 3.14159265358979323846
  43.  
  44. void AcDegaYe()
  45. {
  46. ll n;
  47. cin>>n;
  48. vector<ll> a;
  49. a.pb(-1);
  50. inpvec(a,n);
  51. ll pre[n+1];
  52. ll suf[n+1];
  53. for(ll i=1;i<=n;i++)pre[i]=(pre[i-1]|a[i]);
  54. for(ll i=n;i>=1;i--)suf[i]=(suf[i+1]|a[i]);
  55. ll idx=1;
  56. ll ans=INT_MIN;
  57. for(ll i=1;i<=n;i++)
  58. {
  59. ll x=a[i];
  60. ll y=(pre[i-1]|suf[i+1]);
  61. if((x|y)-y>ans)
  62. {
  63. ans=(x|y)-y;
  64. idx=i;
  65. }
  66. }
  67. //cout(idx);
  68. cout<<a[idx]<<" ";
  69. for(ll i=1;i<=n;i++)if(i!=idx)cout<<a[i]<<" ";
  70. }
  71. int main()
  72. {
  73.  
  74. fastio
  75. //ll t;
  76. //cin>>t;
  77. ll t=1;
  78. while(t--)
  79. {
  80. AcDegaYe();
  81. }
  82. cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  83. return 0;
  84. }
Time limit exceeded #stdin #stdout 5s 4197656KB
stdin
Standard input is empty
stdout
Standard output is empty