#include <iostream>
#include <algorithm>
#include <math.h>
#define MAX_N 1000000
using namespace std;
int v[MAX_N], ant[MAX_N], rest[MAX_N];
int countLower( int v[], int n, int a ) {
int st, dr, mij;
st = 0;
dr = n;
while ( dr - st > 1 ) {
mij = (st + dr) / 2;
if ( v[mij] > a )
dr = mij;
else
st = mij;
}
if ( v[st] > a )
return 0;
return st + 1;
}
int main() {
int n, m, maxLog2, st, dr, leftR, rightR, res, i, j, p;
long long nrSume;
cin >> n;
maxLog2 = 0;
for ( i = 0; i < n; i++ ) {
cin >> v[i];
if ( log2( v[i] ) > maxLog2 )
maxLog2 = log2( v[i] );
}
res = 0;
for ( p = maxLog2 + 1; p >= 0; p-- ) {
if ( p <= maxLog2 ) {
j = 0;
while ( j < n && rest[j] < (1 << (p + 1)) )
j++;
m = j;
i = 0;
while ( i < m && j < n ) {
if ( ant[i] < ant[j] - (1 << (p + 1)) ) {
rest[i + j - m] = ant[i];
i++;
} else {
rest[i + j - m] = ant[j] - (1 << (p + 1));
j++;
}
}
while ( i < m ) {
rest[n - m + i] = ant[i];
i++;
}
while ( j < n ) {
rest[j] = ant[j] - (1 << (p + 1));
j++;
}
} else {
for ( i = 0; i < n; i++ )
rest[i] = v[i] & ((1 << (p + 1)) - 1);
sort( rest, rest + n );
}
nrSume = 0;
st = dr = 0;
for ( i = n - 1; i >= 0; i-- ) {
leftR = (1 << p) - rest[i];
if ( leftR < 0 )
leftR += (1 << (p + 1));
rightR = (1 << (p + 1)) - 1 - rest[i];
if ( rightR < 0 )
rightR += (1 << (p + 1));
if ( rest[st] > leftR )
st = 0;
while ( st < n && rest[st] < leftR )
st++;
if ( rest[dr] > rightR )
dr = 0;
while ( dr < n && rest[dr] <= rightR )
dr++;
if ( leftR <= rightR ) {
nrSume += dr - st;
if ( leftR <= rest[i] && rest[i] <= rightR )
nrSume++;
} else {
nrSume += n - st + dr;
if ( leftR <= rest[i] || rest[i] <= rightR )
nrSume++;
}
if ( st > 0 )
st--;
if ( dr > 0 )
dr--;
}
nrSume /= 2;
if ( nrSume % 2 == 1 )
res += (1 << p);
for ( i = 0; i < n; i++ )
ant[i] = rest[i];
}
cout << res;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
332 KB |
Output is correct |
2 |
Correct |
5 ms |
356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
431 ms |
12008 KB |
Output is correct |
2 |
Correct |
408 ms |
11224 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
431 ms |
12008 KB |
Output is correct |
2 |
Correct |
408 ms |
11224 KB |
Output is correct |
3 |
Correct |
630 ms |
12008 KB |
Output is correct |
4 |
Correct |
624 ms |
18156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
332 KB |
Output is correct |
2 |
Correct |
5 ms |
356 KB |
Output is correct |
3 |
Correct |
100 ms |
1472 KB |
Output is correct |
4 |
Correct |
120 ms |
1416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
332 KB |
Output is correct |
2 |
Correct |
5 ms |
356 KB |
Output is correct |
3 |
Correct |
431 ms |
12008 KB |
Output is correct |
4 |
Correct |
408 ms |
11224 KB |
Output is correct |
5 |
Correct |
630 ms |
12008 KB |
Output is correct |
6 |
Correct |
624 ms |
18156 KB |
Output is correct |
7 |
Correct |
100 ms |
1472 KB |
Output is correct |
8 |
Correct |
120 ms |
1416 KB |
Output is correct |
9 |
Correct |
993 ms |
21364 KB |
Output is correct |
10 |
Correct |
984 ms |
21428 KB |
Output is correct |
11 |
Correct |
973 ms |
21456 KB |
Output is correct |