-
Notifications
You must be signed in to change notification settings - Fork 13
/
XMAX.cpp
65 lines (44 loc) · 1.06 KB
/
XMAX.cpp
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
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
int n;
scanf("%d",&n);
vector<long long> v;
long long x;
for(int i=0;i<n;i++)
{
scanf("%lld",&x);
v.push_back(x);
}
sort(v.rbegin(),v.rend());
long long int sig=1;
while(sig<=v[0])
sig<<=1;
sig>>=1;
for(int t=0;sig>=1;sig>>=1)
{
int i=t;
while(i<n && (v[i]&sig)==0)
i++;
if(i>=n)
continue;
swap(v[t],v[i]);
for(int j=0;j<n;++j)
{
if(j!=t && (v[j]&sig)!=0)
v[j]=v[j]^v[t];
}
t++;
}
long long int result=0;
for(int q=0;q<n;q++)
{
result=result^v[q];
}
printf("%lld\n",result);
system ("pause");
return 0;
}