题解思路:
假设l-r区间可以与其他区间配对异或和为0,那么这些区间的R一定<l,所以去枚举个个区间然后保存该区间的异或和,用cnt[x]表示当前已知异或和为x的区间个数。
代码:
#include<iostream>
#include<cstring>
using namespace std;
const int maxn = 1 << 17;
int a[1005];
int cnt[maxn];
int main()
{
int n;
while (scanf("%d", &n)!=EOF)
{
memset(cnt,0,sizeof(cnt));
for (int i = 1; i <= n; i++) scanf("%d", a + i);
for (int i = 1; i <= n; i++) a[i] ^= a[i - 1];
long long ans = 0;
for (int i = 1; i <= n; i++)
{
for (int j = i; j <= n; j++)
ans += cnt[a[j] ^ a[i - 1]];
for (int j = 0; j < i; j++)
cnt[a[i] ^ a[j]]++;
}
printf("%lld\n", ans);
}
return 0;
}