Solution
题目中没有规定翻转操作次数,所以题目就被转化成了区间异或和为 的区间个数。
考虑先求出异或前缀和,令 表示前 个数的异或和。如果区间 的异或和为 ,就说明 ,也就是 。
求出前缀和后使用 map 计数每一个数字有多少个前缀和等于那个数字即可。
Code
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int inf = 0x3f3f3f3f,mod = 1e9 + 7;
const int maxn = 2e5 + 7;
map<int,int> m;
int n,x;
int ans,cur;//cur存当前的异或前缀和
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
m[0] = 1;
while(n--){
cin >> x;
cur ^= x;
ans += m[cur];
m[cur]++;
}
cout << ans;
return 0;
}