#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
376 KB |
Output is correct |
2 |
Correct |
46 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1669 ms |
12024 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1669 ms |
12024 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
376 KB |
Output is correct |
2 |
Correct |
46 ms |
376 KB |
Output is correct |
3 |
Correct |
1102 ms |
1568 KB |
Output is correct |
4 |
Correct |
1107 ms |
1572 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
376 KB |
Output is correct |
2 |
Correct |
46 ms |
376 KB |
Output is correct |
3 |
Execution timed out |
1669 ms |
12024 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |