이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <stdio.h>
#define M 20
#define N (1 << M)
#define MD 0x7fffffff
unsigned int Z = 12345;
int rand_() {
return (Z *= 3) >> 1;
}
int X, Y, ppx[N + 1], ppy[N + 1];
void init() {
int i;
X = rand_() % (MD - 3) + 3;
Y = rand_() % (MD - 3) + 3;
ppx[0] = ppy[0] = 1;
for (i = 1; i <= N; i++) {
ppx[i] = (long long) ppx[i - 1] * X % MD;
ppy[i] = (long long) ppy[i - 1] * Y % MD;
}
}
long long xy[N + 1];
int compare(int i, int j) {
return xy[i] == xy[j] ? (i & 2) - (j & 2) : (xy[i] < xy[j] ? -1 : 1);
}
void sort(int *ii, int l, int r) {
while (l < r) {
int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;
while (j < k) {
int c = compare(ii[j], i_);
if (c == 0)
j++;
else if (c < 0) {
tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
i++, j++;
} else {
k--;
tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;
}
}
sort(ii, l, i);
l = k;
}
}
int main() {
static int aa[N], ii[N + 1];
int n, m, i, j, x, y;
long long ans;
init();
scanf("%d", &m), n = 1 << m;
if (m == 1) {
printf("2\n");
return 0;
}
for (i = 0; i < n; i++)
scanf("%d", &aa[i]);
for (i = 0, x = 0, y = 0; i < n; i++) {
if (aa[i] < (aa[i] ^ n - 1))
x = ((long long) x + ppx[aa[i]]) % MD, y = ((long long) y + ppy[aa[i]]) % MD;
else
x = ((long long) x - ppx[aa[i] ^ n - 1]) % MD, y = ((long long) y - ppy[aa[i] ^ n - 1]) % MD;
if (x < 0)
x += MD;
if (y < 0)
y += MD;
xy[i + 1] = (long long) x * MD + y;
}
for (i = 0; i <= n; i++)
ii[i] = i;
sort(ii, 0, n + 1);
ans = (long long) (n + 1) * n / 2;
for (i = 0; i <= n; i = j) {
j = i + 1;
while (j <= n && compare(ii[j], ii[i]) == 0)
j++;
ans -= (long long) (j - i) * (j - i - 1) / 2;
}
printf("%lld\n", ans);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
dojave.c: In function 'main':
dojave.c:69:26: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
69 | if (aa[i] < (aa[i] ^ n - 1))
| ~~^~~
dojave.c:72:39: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
72 | x = ((long long) x - ppx[aa[i] ^ n - 1]) % MD, y = ((long long) y - ppy[aa[i] ^ n - 1]) % MD;
| ~~^~~
dojave.c:72:86: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
72 | x = ((long long) x - ppx[aa[i] ^ n - 1]) % MD, y = ((long long) y - ppy[aa[i] ^ n - 1]) % MD;
| ~~^~~
dojave.c:61:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
61 | scanf("%d", &m), n = 1 << m;
| ^~~~~~~~~~~~~~~
dojave.c:67:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
67 | 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... |
# | 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... |