时间复杂度 $O(n \log w)$。
```cpp
#include <bits/stdc++.h>
using namespace std;
#define N 200005
int n, a[N], pre[N];
void _main() {
cin >> n;
long long tot = 0;
for (int i = 1; i <= n; i++) cin >> a[i], tot += a[i], pre[i] = pre[i - 1] ^ a[i];
long long res = 0;
for (int i = 27; i >= 0; i--) {
int s[2] = {0, 0};
for (int j = 1; j <= n; j++) {
int u = pre[j - 1] >> i & 1, v = pre[j] >> i & 1;
s[u]++;
res += (1LL << i) * s[v ^ 1];
}
}
cout << res - tot;
} signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
_main();
return 0;
}
```