Created
August 5, 2019 17:39
-
-
Save sudipt1999/18246168857650bb953326c7e40fd2e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> | |
using namespace std; | |
#define ll long long | |
#define ul unsigned long long | |
void preprocess(int arr[], int n, vector<vector<int> >& cnt) | |
{ | |
int i, j; | |
for (i = 0; i < 32; i++) { | |
cnt[i][0] = 0; | |
for (j = 0; j < n; j++) { | |
if (j > 0) { | |
cnt[i][j] = cnt[i][j - 1]; | |
} | |
if (arr[j] & (1 << i)) | |
cnt[i][j]++; | |
} | |
} | |
} | |
int findXOR(int L, int R, const vector<vector<int> > cnt) | |
{ | |
int ans = 0; | |
int noOfOnes; | |
int i, j; | |
for (i = 0; i < 32; i++) { | |
noOfOnes = cnt[i][R] - ((L > 0) ? cnt[i][L - 1] : 0); | |
if (noOfOnes & 1) { | |
ans += (1 << i); | |
} | |
} | |
return ans; | |
} | |
int main() { | |
ll t; cin>>t; | |
while(t--) { | |
int n ; cin >>n; | |
int arr[n]={0}; | |
for(ll i = 0 ; i < n ; i++) | |
cin>>arr[i]; | |
vector<vector<int> > cnt(32, vector<int>(n)); | |
preprocess(arr, n, cnt); | |
ll ans = 0; | |
ll a1,a2; | |
// first loop for total number of cases | |
for(ll i = 1 ; i < n ; i++){ | |
for( ll j = 0 ; j < i ; j++){ | |
a1 = findXOR(j, i-1, cnt); | |
a2 = findXOR(i, i, cnt); | |
for(ll k = i ; k < n ; k++){ | |
// cout<<" LB : "<<j<<" MID " <<i<<" END : "<<k<<endl; | |
if(a1 == a2){ | |
//cout<<"A1 : "<<a1<<" A2 : "<<a2<<endl; | |
ans++; | |
} | |
} | |
} | |
} | |
cout<<ans<<endl; | |
} | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment