Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***** TheAnshul *****/
- #include<bits/stdc++.h>
- #define ll long long
- #define pb push_back
- #define ppb pop_back
- #define endl '\n'
- #define mii map<ll int,ll int>
- #define msi map<string,ll int>
- #define mis map<ll int, string>
- #define rep(i,a,b) for(ll int i=a;i<b;i++)
- #define mpi map<pair<ll int,ll int>,ll int>
- #define pii pair<ll int,ll int>
- #define vi vector<ll int>
- #define vii vector<pair<ll int, ll int>>
- #define vs vector<string>
- #define all(a) (a).begin(),(a).end()
- #define F first
- #define S second
- #define sz(x) (ll int)x.size()
- #define hell 1000000007
- #define lbnd lower_bound
- #define ubnd upper_bound
- #define bs binary_search
- #define mp make_pair
- #define what_is(x) cerr << #x << " is " << x << endl;
- using namespace std;
- #define N 1000005
- ll cnt;
- pii trie[N][2];
- void reset()
- {
- cnt=1;
- rep(i,0,N)
- {
- trie[i][0].F=-1;
- trie[i][0].S=0;
- trie[i][1].S=0;
- trie[i][1].F=-1;
- }
- return;
- }
- void insert(ll n)
- {
- ll p=0;
- while(n!=0)
- {
- if(trie[p][n&1].F!=-1)
- {
- trie[p][n&1].S++;
- p=trie[p][n&1].F;
- }
- else
- {
- trie[p][n&1].S=1;
- trie[p][n&1].F=cnt;
- p=cnt;
- cnt++;
- }
- n/=2;
- }
- return;
- }
- ll query(ll n)
- {
- ll p=0,ans=0;
- while(n!=0)
- {
- ans=ans<<1;
- if(trie[p][!(n&1)].F!=-1)
- {
- ans++;
- p=trie[p][!(n&1)].F;
- }
- else
- {
- p=trie[p][(n&1)].F;
- }
- n/=2;
- }
- return ans;
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- int TESTS=1;
- cin>>TESTS;
- while(TESTS--)
- {
- reset();
- ll n;
- cin>>n;
- vi v(n);
- ll mx=0;
- rep(i,0,n)
- {
- cin>>v[i];
- }
- rep(i,1,n)
- {
- v[i]^=v[i-1];
- mx=max(v[i],mx);
- }
- rep(i,0,n)
- {
- insert(v[i]);
- mx=max(query(v[i]),mx);
- }
- cout<<mx<<endl;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment