0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-30 15:36:27 +00:00

P3812 【模板】线性基

https://www.luogu.com.cn/record/76955036
This commit is contained in:
Baoshuo Ren 2022-06-05 11:22:17 +08:00
parent c582e56ee3
commit 08dbbe056d
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

50
Luogu/P3812/P3812.cpp Normal file
View File

@ -0,0 +1,50 @@
#include <iostream>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 55;
int n;
long long x, a[N], ans;
void insert(long long x) {
for (int i = 50; ~i; i--) {
if (!(x & (1ll << i))) continue;
if (a[i]) {
x ^= a[i];
} else {
for (int k = 0; k < i; k++) {
if (x & (1ll << k)) x ^= a[k];
}
for (int k = i + 1; k <= 50; k++) {
if (a[k] & (1ll << i)) a[k] ^= x;
}
a[i] = x;
return;
}
}
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> x;
insert(x);
}
for (int i = 0; i <= 50; i++) ans ^= a[i];
cout << ans << endl;
return 0;
}