Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //In the Name of Allah Most Gracious, Most Merciful//
- /*If you want something you've never had, you have to do something you never did.*/
- #include<bits/stdc++.h>
- using namespace std;
- #define pb push_back
- #define ll long long
- #define pii pair<int,int>
- #define pll pair<ll,ll>
- #define M 100007
- #define INF 1e9
- #define INFL 1e18
- #define PI acos(-1)
- #define mp make_pair
- //const int fx[]= {+1,-1,+0,+0};
- //const int fy[]= {+0,+0,+1,-1};
- //const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1}; // Kings Move
- //const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1}; // Kings Move
- //const int fx[]={-2, -2, -1, -1, 1, 1, 2, 2}; // Knights Move
- //const int fy[]={-1, 1, -2, 2, -2, 2, -1, 1}; // Knights Move
- struct node
- {
- int endmark;
- node* next[2];
- node()
- {
- endmark=0;
- next[0]=NULL;
- next[1]=NULL;
- }
- }*root;
- void insert_node(int num)
- {
- node* curr=root;
- for(int i=31;i>=0;i--)
- {
- int rem=(num&(1<<i))!=0;
- if(curr->next[rem]==NULL)
- {
- curr->next[rem]=new node();
- }
- curr=curr->next[rem];
- curr->endmark++;
- }
- }
- ll query_node(int num)
- {
- ll sum=0;
- node* curr=root;
- for(int i=31;i>=0;i--)
- {
- int rem=!(((num)&(1<<i))!=0);
- // cout<<rem<<endl;
- if(curr->next[rem]!=NULL)
- {
- sum+=(1<<i);
- curr=curr->next[rem];
- }
- else
- {
- curr=curr->next[!rem];
- }
- }
- return sum;
- }
- void delete_node(node *curr)
- {
- for(int i=0;i<2;i++)
- {
- if(curr->next[i]!=NULL)
- {
- delete_node(curr->next[i]);
- }
- }
- delete (curr);
- }
- int main()
- {
- // #ifndef ONLINE_JUDGE
- // freopen("input.txt","r",stdin);
- // freopen("output.txt","w",stdout);
- // #endif
- int t;
- cin>>t;
- while(t--)
- {
- root=new node();
- int n;
- cin>>n;
- int arr[n+5];
- for(int i=0;i<n;i++)
- {
- cin>>arr[i];
- }
- int pre=0;
- ll ans=0;
- insert_node(0);
- for(int i=0;i<n;i++)
- {
- pre=pre^arr[i];
- insert_node(pre);
- // cout<<pre<<endl;
- // cout<<query_node(pre)<<endl;
- ans=max(ans,query_node(pre));
- // cout<<ans<<endl;
- }
- cout<<ans<<" ";
- delete_node(root);
- }
- cout<<endl;
- ///Before submit=>
- /// *check for integer overflow,array bounds
- /// *check for n=1
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement