线性基模板
const int N = 51; ll a[N], p[101] = { 0 }; void get_lb(ll x) { for (int i = 63; i >= 0; i--) { if (x & (1LL << i)) { if (!p[i]) { p[i] = x; break; } else { x ^= p[i]; } } } }
洛谷p3812
#include<bits/stdc++.h> #define ll long long using namespace std; const int N = 51; ll a[N], p[101] = { 0 }; void get_lb(ll x) { for (int i = 63; i >= 0; i--) { if (x & (1LL << i)) { if (!p[i]) { p[i] = x; break; } else { x ^= p[i]; } } } } int main() { ll n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; get_lb(a[i]); } ll ans = 0; for (int i = 63; i > 0; i--) { if (p[i] && (ans ^ p[i]) > ans) { ans ^= p[i]; } } cout << ans << endl; }