0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-09-19 21:25:24 +00:00

#159. 【模板】最大异或和

https://sjzezoj.com/submission/7564
This commit is contained in:
Baoshuo Ren 2021-01-03 20:44:28 +08:00 committed by Baoshuo Ren
parent c8cbda6669
commit ec9fe743da
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

34
S2OJ/159/159.cpp Normal file
View File

@ -0,0 +1,34 @@
#include <bits/stdc++.h>
using namespace std;
int n;
long long t, ans, p[60];
void insert(long long x) {
for (int i = 50; i >= 0; i--) {
if (x & (1ll << i)) {
if (!p[i]) {
p[i] = x;
break;
} else {
x ^= p[i];
}
}
}
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> t;
insert(t);
}
for (int i = 50; i >= 0; i--) {
if ((ans ^ p[i]) > ans) {
ans ^= p[i];
}
}
cout << ans << endl;
return 0;
}