题目传送门
题意
给你n个数,问你有多少个连续子区间的异或值为0。
思路
我们用一个类似前缀和的数组去存前缀异或数组,如果后面出现了之前出现过的值,那么中间这一段的连续异或值就是0。
用map存一个前缀异或的值出现过多少次(因为异或的结果可能比较大,一般数组开不了这么大或者浪费空间)
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
const double EPS=1e-6;
typedef long long ll;
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//#define int long long
int a[N],b[N];
signed main()
{
IOS;
//freopen("","r",stdin);
//freopen("","w",stdout);
int n;
cin>>n;
map<int,int>mp;
ll res=0;
for(int i=1;i<=n;i++)
{
cin>>a[i];
b[i]=b[i-1]^a[i];
if(b[i]==0)//如果这次异或得到0,那么也要加上
res++;
res+=mp[b[i]];
mp[b[i]]++;
}
cout<<res<<endl;
}