#include <stdio.h>
#include <string.h>
#define N 300000
#define X 1000000000
#define C 25
unsigned int Z = 12345;
int rand_() {
return (Z *= 3) >> 1;
}
int xx[N], yy[N], rr[N];
#define intersect(i, j) ((long long) (xx[i] - xx[j]) * (xx[i] - xx[j]) + (long long) (yy[i] - yy[j]) * (yy[i] - yy[j]) <= (long long) (rr[i] + rr[j]) * (rr[i] + rr[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 = rr[ii[j]] != rr[i_] ? rr[i_] - rr[ii[j]] : 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 compare(int x1, int y1, int x2, int y2) {
return x1 != x2 ? (x1 < x2 ? -1 : 1) : (y1 == y2 ? 0 : (y1 < y2 ? -1 : 1));
}
int main() {
static char type[N];
static int xx_[N], yy_[N], ii[N], ii_[N], ii1[N], tmp[N], ggg[N][C], gg[C], iii[N * 4], kk[N], pp[N];
int n, n1, g, h, h_, i, j, k, c, lg, cnt;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d%d%d", &xx[i], &yy[i], &rr[i]);
xx[i] += X, yy[i] += X;
ii[i] = ii_[i] = i;
}
sort(ii, 0, n);
for (lg = 30, h = 0; lg >= 0; lg--) {
int x, y;
for (i = 0; i < n; i++)
xx_[i] = xx[i] >> lg + 1, yy_[i] = yy[i] >> lg + 1;
memset(gg, 0, C * sizeof *gg);
n1 = 0;
for (h_ = 0; h_ < n; h_++) {
i = ii_[h_];
if (type[i] != -1 && rr[i] >= 1 << lg)
ii1[n1++] = i;
}
for (h_ = 0; h_ < n; h_++) {
i = ii_[h_], x = xx_[i], y = yy_[i];
for (c = 0; c < C; c++) {
int dx = c / 5 - 2, dy = c % 5 - 2;
while (gg[c] < n1 && compare(xx_[ii1[gg[c]]], yy_[ii1[gg[c]]], x + dx, y + dy) < 0)
gg[c]++;
ggg[i][c] = gg[c] < n1 && compare(xx_[ii1[gg[c]]], yy_[ii1[gg[c]]], x + dx, y + dy) == 0 ? gg[c] : -1;
}
}
memset(kk, 0, n1 * sizeof *kk);
for (h_ = h; h_ < n; h_++) {
int p;
i = ii[h_], x = xx_[i], y = yy_[i], p = -1;
if (type[i] == -1)
continue;
for (c = 0; c < C; c++) {
g = ggg[i][c];
if (g == -1)
continue;
for (k = 0; k < kk[g]; k++) {
j = iii[g << 2 | k];
if (intersect(i, j)) {
if (p == -1 || rr[p] < rr[j] || rr[p] == rr[j] && p > j)
p = j;
break;
}
}
}
if (p != -1)
pp[i] = p, type[i] = -1;
else {
pp[i] = i, type[i] = 1;
if (rr[i] >= 1 << lg) {
g = ggg[i][(0 + 2) * 5 + (0 + 2)];
iii[g << 2 | kk[g]++] = i;
}
}
}
while (h < n && rr[ii[h]] >= 1 << lg)
h++;
for (i = 0; i < n; i = j) {
x = xx_[ii_[i]];
j = i + 1;
while (j < n && xx_[ii_[j]] == x)
j++;
cnt = 0;
for (h_ = i; h_ < j; h_++)
if ((xx[ii_[h_]] >> lg & 1) == 0)
ii_[i++] = ii_[h_];
else
tmp[cnt++] = ii_[h_];
memcpy(ii_ + i, tmp, cnt * sizeof *tmp);
}
for (i = 0; i < n; i = j) {
x = xx[ii_[i]] >> lg, y = yy_[ii_[i]];
j = i + 1;
while (j < n && (xx[ii_[j]] >> lg) == x && yy_[ii_[j]] == y)
j++;
cnt = 0;
for (h_ = i; h_ < j; h_++)
if ((yy[ii_[h_]] >> lg & 1) == 0)
ii_[i++] = ii_[h_];
else
tmp[cnt++] = ii_[h_];
memcpy(ii_ + i, tmp, cnt * sizeof *tmp);
}
}
for (i = 0; i < n; i++)
printf("%d ", pp[i] + 1);
printf("\n");
return 0;
}
Compilation message
circle_selection.c: In function 'main':
circle_selection.c:60:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
60 | xx_[i] = xx[i] >> lg + 1, yy_[i] = yy[i] >> lg + 1;
| ~~~^~~
circle_selection.c:60:51: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
60 | xx_[i] = xx[i] >> lg + 1, yy_[i] = yy[i] >> lg + 1;
| ~~~^~~
circle_selection.c:92:54: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
92 | if (p == -1 || rr[p] < rr[j] || rr[p] == rr[j] && p > j)
| ~~~~~~~~~~~~~~~^~~~~~~~
circle_selection.c:49:2: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
49 | scanf("%d", &n);
| ^~~~~~~~~~~~~~~
circle_selection.c:51:3: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
51 | scanf("%d%d%d", &xx[i], &yy[i], &rr[i]);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
3 ms |
364 KB |
Output is correct |
13 |
Correct |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
6 ms |
492 KB |
Output is correct |
17 |
Correct |
5 ms |
492 KB |
Output is correct |
18 |
Correct |
5 ms |
492 KB |
Output is correct |
19 |
Correct |
21 ms |
1132 KB |
Output is correct |
20 |
Correct |
22 ms |
1132 KB |
Output is correct |
21 |
Correct |
30 ms |
1132 KB |
Output is correct |
22 |
Correct |
34 ms |
1260 KB |
Output is correct |
23 |
Correct |
44 ms |
1260 KB |
Output is correct |
24 |
Correct |
41 ms |
1132 KB |
Output is correct |
25 |
Correct |
32 ms |
1132 KB |
Output is correct |
26 |
Correct |
32 ms |
1260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2019 ms |
43372 KB |
Output is correct |
2 |
Correct |
2084 ms |
43372 KB |
Output is correct |
3 |
Correct |
2043 ms |
42884 KB |
Output is correct |
4 |
Correct |
1999 ms |
43116 KB |
Output is correct |
5 |
Correct |
2842 ms |
45548 KB |
Output is correct |
6 |
Execution timed out |
3082 ms |
42864 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1020 ms |
16620 KB |
Output is correct |
3 |
Execution timed out |
3076 ms |
46920 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2859 ms |
49100 KB |
Output is correct |
2 |
Correct |
2746 ms |
49544 KB |
Output is correct |
3 |
Correct |
2412 ms |
48748 KB |
Output is correct |
4 |
Correct |
2839 ms |
49120 KB |
Output is correct |
5 |
Correct |
2777 ms |
49388 KB |
Output is correct |
6 |
Correct |
2310 ms |
48876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
3 ms |
364 KB |
Output is correct |
13 |
Correct |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
6 ms |
492 KB |
Output is correct |
17 |
Correct |
5 ms |
492 KB |
Output is correct |
18 |
Correct |
5 ms |
492 KB |
Output is correct |
19 |
Correct |
21 ms |
1132 KB |
Output is correct |
20 |
Correct |
22 ms |
1132 KB |
Output is correct |
21 |
Correct |
30 ms |
1132 KB |
Output is correct |
22 |
Correct |
34 ms |
1260 KB |
Output is correct |
23 |
Correct |
44 ms |
1260 KB |
Output is correct |
24 |
Correct |
41 ms |
1132 KB |
Output is correct |
25 |
Correct |
32 ms |
1132 KB |
Output is correct |
26 |
Correct |
32 ms |
1260 KB |
Output is correct |
27 |
Correct |
42 ms |
1772 KB |
Output is correct |
28 |
Correct |
42 ms |
1808 KB |
Output is correct |
29 |
Correct |
42 ms |
1772 KB |
Output is correct |
30 |
Correct |
67 ms |
2028 KB |
Output is correct |
31 |
Correct |
66 ms |
2028 KB |
Output is correct |
32 |
Correct |
64 ms |
2028 KB |
Output is correct |
33 |
Correct |
579 ms |
14444 KB |
Output is correct |
34 |
Correct |
611 ms |
14776 KB |
Output is correct |
35 |
Correct |
633 ms |
14572 KB |
Output is correct |
36 |
Correct |
1000 ms |
16876 KB |
Output is correct |
37 |
Correct |
1018 ms |
16876 KB |
Output is correct |
38 |
Correct |
1022 ms |
16784 KB |
Output is correct |
39 |
Correct |
694 ms |
16748 KB |
Output is correct |
40 |
Correct |
702 ms |
16748 KB |
Output is correct |
41 |
Correct |
702 ms |
16908 KB |
Output is correct |
42 |
Correct |
645 ms |
16748 KB |
Output is correct |
43 |
Correct |
833 ms |
16552 KB |
Output is correct |
44 |
Correct |
816 ms |
16620 KB |
Output is correct |
45 |
Correct |
817 ms |
16552 KB |
Output is correct |
46 |
Correct |
830 ms |
16556 KB |
Output is correct |
47 |
Correct |
827 ms |
16552 KB |
Output is correct |
48 |
Correct |
830 ms |
16552 KB |
Output is correct |
49 |
Correct |
810 ms |
16552 KB |
Output is correct |
50 |
Correct |
823 ms |
16620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
3 ms |
364 KB |
Output is correct |
13 |
Correct |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
6 ms |
492 KB |
Output is correct |
17 |
Correct |
5 ms |
492 KB |
Output is correct |
18 |
Correct |
5 ms |
492 KB |
Output is correct |
19 |
Correct |
21 ms |
1132 KB |
Output is correct |
20 |
Correct |
22 ms |
1132 KB |
Output is correct |
21 |
Correct |
30 ms |
1132 KB |
Output is correct |
22 |
Correct |
34 ms |
1260 KB |
Output is correct |
23 |
Correct |
44 ms |
1260 KB |
Output is correct |
24 |
Correct |
41 ms |
1132 KB |
Output is correct |
25 |
Correct |
32 ms |
1132 KB |
Output is correct |
26 |
Correct |
32 ms |
1260 KB |
Output is correct |
27 |
Correct |
2019 ms |
43372 KB |
Output is correct |
28 |
Correct |
2084 ms |
43372 KB |
Output is correct |
29 |
Correct |
2043 ms |
42884 KB |
Output is correct |
30 |
Correct |
1999 ms |
43116 KB |
Output is correct |
31 |
Correct |
2842 ms |
45548 KB |
Output is correct |
32 |
Execution timed out |
3082 ms |
42864 KB |
Time limit exceeded |
33 |
Halted |
0 ms |
0 KB |
- |