Tarango

Codechef POLO XOR

Sep 21st, 2015
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define MEM(a,b) memset(a,(b),sizeof(a))
  5. #define MAX(a,b) ((a) > (b) ? (a) : (b))
  6. #define MIN(a,b) ((a) < (b) ? (a) : (b))
  7. #define MP make_pair
  8. #define pb push_back
  9.  
  10. #define maxn 100000
  11. #define maxv 1000000000
  12.  
  13. typedef long long  LL;
  14. typedef pair<int,int> pi;
  15. typedef vector<int> vi;
  16.  
  17.  
  18. int cnt[70][2],n;
  19.  
  20. int main()
  21. {
  22.    int i,j,k,T,tot=0;
  23.  
  24.    scanf("%d",&T);
  25.    assert(T>=1 && T<=maxn);
  26.  
  27.    while(T--)
  28.    {
  29.       LL ans=0;
  30.       MEM(cnt,0);
  31.  
  32.       for(i=0;i<30;i++) cnt[i][0]=1;
  33.       scanf("%d",&n);
  34.       assert(n>=1 && n<=maxn);
  35.       tot+=n;
  36.       int sum=0;
  37.  
  38.       for(j=0;j<n;j++)
  39.       {
  40.          scanf("%d",&k);
  41.          assert(k>=1 && k<=maxv);
  42.  
  43.          sum^=k;
  44.  
  45.          for(i=0;i<30;i++)
  46.          {
  47.             LL p=(1<<i);
  48.  
  49.             if(sum&(1<<i))
  50.                ans+=p*cnt[i][0];
  51.             else
  52.                ans+=p*cnt[i][1];
  53.          }
  54.  
  55.          for(i=0;i<30;i++)
  56.          {
  57.             if(sum&(1<<i))
  58.                cnt[i][1]++;
  59.             else
  60.                cnt[i][0]++;
  61.          }
  62.       }
  63.       cout<<ans<<endl;
  64.    }
  65.  
  66.    assert(tot>=1 && tot<=maxn);
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment