给定一个长度为n的整数数组,问有多少对互不重叠的非空区间,使得两个区间内的数的异或和为0。
暴力,每次找一个中点,找左右两边异或值一样的区间
#include<bits/stdc++.h>
#define int long long
#define TEST
#define TESTS int _; cin >> _; while(_--)
using namespace std;
void Main() {int n;cin >> n;vector<int> a(n + 1, 0);for(int i = 1; i <= n; ++i) {cin >> a[i];a[i] = a[i] ^ a[i - 1];}int ans = 0;map<int, int> mp;for(int i = 1; i <= n; ++i) {for(int j = 0; j < i; ++j) {mp[a[i] ^ a[j]]++;}for(int j = i + 1; j <= n; ++j) {ans += mp[a[i] ^ a[j]];}}cout << ans << endl;
}
signed main() {ios :: sync_with_stdio(false);cin.tie(0); cout.tie(0);TEST Main();return 0;
}