-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathMaximum Xor Subarray.cpp
More file actions
51 lines (45 loc) · 977 Bytes
/
Maximum Xor Subarray.cpp
File metadata and controls
51 lines (45 loc) · 977 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+5;
int trie[N*30][2];
int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
int invert(int N,int pos){return N=N ^ (1<<pos);}
int counter = 0;
void insert(int n){
int node = 0;
for(int i=30;i>=0;i--){
int d = (n>>i)&1;
if( trie[node][d] == 0 ) trie[node][d] = ++counter;
node = trie[node][d];
}
}
int searchd(int n){
int node = 0,ans = 0;
for(int i=30;i>=0;i--){
int d = (n>>i)&1;
d = 1 - d;
if( trie[node][d] != 0 ){
node = trie[node][d];
ans+=(1<<i);
}else {
node = trie[node][1-d];
}
}
return ans;
}
int main(){
int n;
cin>>n;
int xorr = 0;
int mx = 0;
insert(0);
while(n--){
int x;
cin>>x;
xorr^=x;
insert(xorr);
mx = max( mx,searchd(xorr) );
}
cout<<mx;
}