Knobody

Untitled

Aug 4th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. typedef long long int big;
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12. int main(){
  13. //  freopen("i.txt","r",stdin);
  14. //  freopen("o.txt","w",stdout);
  15.    
  16.    
  17.     big t=1;
  18.     cin>>t;
  19.     while(t--){
  20.         big n;
  21.         cin>>n;
  22.         vector<big> arr(n);
  23.         for(big i=0;i<n;i++){
  24.             cin>>arr[i];
  25.         }
  26.         vector<big> pref(n);
  27.         pref[0]=arr[0];
  28.         for(big i=1;i<n;i++){
  29.             pref[i]=arr[i]^pref[i-1];
  30.         }
  31.     //  dbr("pref",pref);
  32.         big result=0;
  33.         map<big,pair<big,big>> mp;
  34.         mp[0]={1,0};
  35.         for(big i=0;i<n;i++){
  36.             big count=mp[pref[i]].first;
  37.             big sum=mp[pref[i]].second;
  38.             result=result+(count*(i+1)-sum-count);
  39.             mp[pref[i]].first++;
  40.             mp[pref[i]].second=mp[pref[i]].second+(i+1);
  41.         }
  42.         cout<<result<<endl;
  43.     }
  44.     return 0;
  45. }
Add Comment
Please, Sign In to add comment