Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ll arr[MAX];
- string binary(ll n)
- {
- string s;
- while(n)
- {
- s+=(n%2)+48;
- n/=2;
- }
- return s;
- }
- struct node
- {
- node *next[2];
- bool endmark;
- node()
- {
- endmark = false;
- next[0] = next[1] = NULL;
- }
- }*root;
- void Insert(string s)
- {
- node *curr = root;
- for(int i = 0;i<s.length();i++)
- {
- int id = s[i] - 48;
- if(curr->next[id]==NULL)
- {
- curr->next[id] = new node();
- }
- curr = curr -> next[id];
- }
- curr->endmark = true;
- }
- void del(node* cur)
- {
- for (int i = 0; i < 2; i++)
- if (cur->next[i])
- del(cur->next[i]);
- delete (cur);
- }
- ll query(string s,ll pk)
- {
- ll ans = 0;
- node *curr = root;
- for(int i = 0;i<s.length();i++)
- {
- if(s[i]=='1')
- {
- if(curr->next[0]!=NULL)
- {
- ans+=(1ll<<pk);
- curr = curr->next[0];
- }
- else if(curr->next[1]!=NULL)
- {
- curr = curr->next[1];
- }
- else break;
- }
- else
- {
- if(curr->next[1]!=NULL)
- {
- ans+=(1ll<<pk);
- curr = curr->next[1];
- }
- else if(curr->next[0]!=NULL)
- {
- curr = curr->next[0];
- }
- else break;
- }
- pk--;
- }
- return ans;
- }
- int main()
- {
- booster()
- ///read("input.txt");
- int n;
- cin>>n;
- root = new node();
- ll x = 0;
- for(int i = 0;i<n;i++)
- {
- cin>>arr[i];
- x = x ^ arr[i];
- string s = binary(x);
- while(s.length()<60)s+='0';
- reverse(all(s));
- Insert(s);
- }
- x = 0;ll ans = 0;
- for(int i = n-1;i>=0;i--)
- {
- x = x ^ arr[i];
- string s = binary(x);
- while(s.length()<60)s+='0';
- reverse(all(s));
- ans = max(ans,query(s,59));
- }
- cout<<max(ans,x);
- del(root);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement