http://www.lydsy.com/JudgeOnline/problem.php?id=3105
就是不懂。。。
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N = 100010; int n; ll tot; ll a[N], bin[40], b[N]; bool cp(ll x, ll y) { return x > y; } int main() { bin[0] = 1; for(int i = 1; i <= 30; ++i) bin[i] = bin[i - 1] * 2; scanf("%d", &n); for(int i = 1; i <= n; ++i) scanf("%d", &a[i]), tot += a[i]; sort(a + 1, a + n + 1, cp); for(int i = 1; i <= n; ++i) { ll t = a[i]; for(int j = 30; j >= 0; --j) if(a[i] & bin[j]) { if(!b[j]) { b[j] = i; break; } else a[i] ^= a[b[j]]; } if(a[i]) tot -= t; } printf("%lld\n", tot); return 0; }