习题-Xorto(前缀和\异或)

习题-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;
}
posted @ 2025-03-27 10:24  awei040519  阅读(15)  评论(0)    收藏  举报