1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| #include<bits/stdc++.h> using namespace std;
long long N, a[100000 + 7]; long long S[100000 + 7], cnt[2], ans;
int main() { cin >> N; for(int i = 1; i <= N; i++) cin >> a[i]; for(int i = 0; i <= 20; i++) { for(int j = 1; j <= N; j++) { if((a[j] >> i) & 1) S[j] = S[j - 1] ^ 1; else S[j] = S[j - 1]; } cnt[0] = cnt[1] = 0; for(int j = 0; j <= N; j++) { cnt[S[j]]++; } ans += (1ll << i) * cnt[0] * cnt[1]; } cout << ans << endl; }
|