# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
485917 |
2021-11-09T17:49:24 Z |
rainboy |
ČVENK (COI15_cvenk) |
C |
|
232 ms |
1484 KB |
#include <stdio.h>
#define N 100000
#define L 29
#define INF 0x3f3f3f3f3f3f3f3fLL
long long min(long long a, long long b) { return a < b ? a : b; }
unsigned int X = 12345;
int rand_() {
return (X *= 3) >> 1;
}
void lca(int x1, int y1, int x2, int y2, int *x, int *y, int l) {
if (l == 0)
*x = 0, *y = 0;
else {
int n = 1 << l - 1;
if (x1 >= n && y1 < n && x2 >= n && y2 < n)
lca(x1 - n, y1, x2 - n, y2, x, y, l - 1), *x += n;
else if (x1 < n && y1 >= n && x2 < n && y2 >= n)
lca(x1, y1 - n, x2, y2 - n, x, y, l - 1), *y += n;
else {
if (x1 >= n && y1 < n)
x1 = n - 1, y1 = 0;
else if (x1 < n && y1 >= n)
x1 = 0, y1 = n - 1;
if (x2 >= n && y2 < n)
x2 = n - 1, y2 = 0;
else if (x2 < n && y2 >= n)
x2 = 0, y2 = n - 1;
lca(x1, y1, x2, y2, x, y, l - 1);
}
}
}
long long dist(int x1, int y1, int x2, int y2) {
int x, y;
lca(x1, y1, x2, y2, &x, &y, L);
return (long long) (x1 + y1) + (x2 + y2) - (long long) (x + y) * 2;
}
int xx[N], yy[N];
int compare(int i, int j) {
int x, y;
if (i == j)
return 0;
lca(xx[i], yy[i], xx[j], yy[j], &x, &y, L);
if (xx[i] == x && yy[i] == y)
return -1;
if (xx[j] == x && yy[j] == y)
return 1;
return (xx[i] - yy[i]) - (xx[j] - yy[j]);
}
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 ii[N];
int n, i;
long long ans;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d%d", &xx[i], &yy[i]);
ii[i] = i;
}
sort(ii, 0, n);
ans = 0;
for (i = 0; i < n; i++) {
int u = ii[i], v = ii[(i + n / 2) % n];
ans += dist(xx[u], yy[u], xx[v], yy[v]);
}
ans /= 2;
printf("%lld\n", ans);
return 0;
}
Compilation message
cvenk.c: In function 'lca':
cvenk.c:19:18: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
19 | int n = 1 << l - 1;
| ~~^~~
cvenk.c: In function 'main':
cvenk.c:88:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
88 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
cvenk.c:90:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
90 | scanf("%d%d", &xx[i], &yy[i]);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
169 ms |
1424 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
232 ms |
1484 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |