习题-Xorto(前缀和\异或)
#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
int a[N], cnt[N];
signed main(){
int n; cin >> n;
for(int i = 1; i <= n; ++i) {cin >> a[i]; a[i] ^= a[i-1];}
long long ans = 0;
for(int i = 1; i <= n; ++i){
for(int j = i; j > 0; --j)
cnt[a[i]^a[j-1]]++;
for(int j = i + 1; j <= n; ++j)
ans += cnt[a[i]^a[j]];
}
cout << ans << endl;
return 0;
}

浙公网安备 33010602011771号