Submission #159361

#TimeUsernameProblemLanguageResultExecution timeMemory
159361mrtsima22XOR Sum (info1cup17_xorsum)C++17
45 / 100
1669 ms12024 KiB
#pragma GCC optimize "-O3" #pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; inline int bin(){ int x=0;char ch=getchar(); while (ch<'0'||ch>'9') ch=getchar(); while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar(); return x; } void countSort(int arr[], int n, int exp) { int output[n]; // output array int i, count[10] = {0}; // Store count of occurrences in count[] for (i = 0; i < n; i++) count[ (arr[i]/exp)%10 ]++; // Change count[i] so that count[i] now contains actual // position of this digit in output[] for (i = 1; i < 10; i++) count[i] += count[i - 1]; // Build the output array for (i = n - 1; i >= 0; i--) { output[count[ (arr[i]/exp)%10 ] - 1] = arr[i]; count[ (arr[i]/exp)%10 ]--; } // Copy the output array to arr[], so that arr[] now // contains sorted numbers according to current digit for (i = 0; i < n; i++) arr[i] = output[i]; } void radixsort(int arr[], int n) { // Find the maximum number to know number of digits int m = 100000000; // Do counting sort for every digit. Note that instead // of passing digit number, exp is passed. exp is 10^i // where i is current digit number for (int exp = 1; exp<= m; exp *= 10) countSort(arr, n, exp); } const int M=29; int n,a[1000004],b[1000004]; int c[39],ans; inline void work(int x,int y,int &k,int &K){ int l=-1,r=-1; for(int o=n-1;o>=0;o--){ while(l+1<n&&b[l+1]+b[o]<x) l++; while(r+1<n&&b[r+1]+b[o]<=y) r++; if(o>l&&o<=r) K++; if(l<=r) k+=(r-l); } } int main(){ ios::sync_with_stdio(false); for(int i=1;i<=M;i++){ c[i]=(1<<(i+1))-1; } n=bin(); for(int i=0;i<n;i++){ a[i]=bin(); } for(int i=1;i<=M;i++){ for(int j=0;j<n;j++){ b[j]=c[i]&a[j]; } // sort(b,b+n); radixsort(b,n); int b1=(1<<(i)); int b2=((1<<(i+1))-1); int B1=b1+(1<<(i+1)); int B2=((1<<(i+2))-2); int k=0,K=0; work(b1,b2,k,K); work(B1,B2,k,K); k-=K; k/=2; k+=K; // cout<<k<<endl; if(k&1){ ans|=(1<<(i)); } } int k=0; for(int i=0;i<n;i++){ if(a[i]&1) k++; } if((k*(n-k))&1){ ans++; } cout<<ans<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...