이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <stdio.h>
#include <string.h>
#define N 1000000
#define L 29 /* L = floor(log2(10^9)) */
int main() {
static int aa[N], aa0[N], aa1[N];
int n, n0, n1, i, i0, i1, l, ans, k;
scanf("%d", &n);
for (i = 0; i < n; i++)
scanf("%d", &aa[i]);
ans = 0;
if (n % 2 == 0)
for (i = 0; i < n; i++)
ans ^= aa[i];
for (l = 1; l <= L; l++) {
n0 = 0, n1 = 0;
for (i = 0; i < n; i++)
if ((aa[i] & 1 << l - 1) == 0)
aa0[n0++] = aa[i];
else
aa1[n1++] = aa[i];
k = (long long) n1 * (n1 + 1) / 2 % 2;
for (i0 = 0, i1 = n1 - 1; i0 < n0; i0++) {
while (i1 >= 0 && (aa0[i0] & (1 << l) - 1) + (aa1[i1] & (1 << l) - 1) >= 1 << l)
i1--;
if ((n1 - 1 - i1) % 2 != 0)
k ^= 1;
}
memcpy(aa, aa0, n0 * sizeof *aa0), memcpy(aa + n0, aa1, n1 * sizeof *aa1);
if (k)
ans ^= 1 << l;
}
printf("%d\n", ans);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
xorsum.c: In function 'main':
xorsum.c:21:24: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
21 | if ((aa[i] & 1 << l - 1) == 0)
| ~~^~~
xorsum.c:27:42: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
27 | while (i1 >= 0 && (aa0[i0] & (1 << l) - 1) + (aa1[i1] & (1 << l) - 1) >= 1 << l)
| ~~~~~~~~~^~~
xorsum.c:27:69: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
27 | while (i1 >= 0 && (aa0[i0] & (1 << l) - 1) + (aa1[i1] & (1 << l) - 1) >= 1 << l)
| ~~~~~~~~~^~~
xorsum.c:11:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
11 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
xorsum.c:13:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | scanf("%d", &aa[i]);
| ^~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |