-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathXORSUM1_array.cpp
More file actions
81 lines (78 loc) · 1.12 KB
/
XORSUM1_array.cpp
File metadata and controls
81 lines (78 loc) · 1.12 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxBITS = 31;
const int maxn =3e5*32;
int trie[maxn][2];
int sz = 1;
inline void clear()
{
trie[0][0] = trie[0][1] = -1;
}
inline void insert(int N)
{
int node = 0;
for(int i = maxBITS; i >= 0; i--)
{
int b = ( N & (1 << i )) != 0;
if(trie[node][b] == -1)
{
trie[node][b] = sz;
trie[sz][0] = trie[sz][1] = -1;
sz++;
}
node = trie[node][b];
}
}
inline long long query(int X)
{
int node = 0;
long long ans = 0;
for(int i = maxBITS; i >= 0; i--)
{
int ok = 1;
int b = ( X & (1 << i )) != 0;
if(trie[node][b^1] == -1)
{
ok = 0;
node = trie[node][b];
}
else
{
node = trie[node][b^1];
}
if(ok)
{
ans += (1 << i);
}
}
return ans;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
clear();
int n;
scanf("%d",&n);
long long p = 0;
long long ans = -1;
insert(0);
for(int i = 0; i < n; i++)
{
int x;
scanf("%d",&x);
p ^= x;
insert(p);
ans = max(ans , query(p));
}
printf("%lld\n",ans);
}
return 0;
}