Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void solve(){
- ll n;
- cin>>n;
- set<ll>A;
- for(int i=0;i<n;i++){
- ll x;
- cin>>x;
- A.insert(x);
- }
- unordered_map<ll,set<ll>>mp;
- ll till_or = 0;
- ll iter = 0;
- ll ans = 1;
- for(int bit = 30 ; bit>=0;bit--){
- vector<vector<ll>>nxt(1 , vector<ll>(31));
- ll id = 1;
- for(auto it : A){
- ll node = 0;
- for(int j = 30 ; j>=0;j--){
- ll c = 0;
- if(it&(1ll<<j)) c= 1;
- if(nxt[node][c] == 0){
- nxt.push_back(vector<ll>(31));
- nxt[node][c] = id++;
- }
- node = nxt[node][c];
- }
- }
- ll node = 0;
- ll max_make = 0;
- for(int j = 30 ; j>=0;j--){
- if(nxt[node][1] != 0){
- node = nxt[node][1];
- max_make += (1ll<<j);
- }
- else{
- node = nxt[node][0];
- }
- }
- if(max_make == 0){
- break;
- }
- iter++;
- till_or |= max_make;
- ans *= (till_or);
- set<ll>new_A;
- for(auto it : A){
- ll new_val = (it - (it&till_or));
- new_A.insert(new_val);
- }
- A.swap(new_A);
- }
- for(int j = iter ; j < n ; j++){
- ans *= till_or;
- }
- cout << ans << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment