#include <algorithm>
#include <cstdio>
#include <vector>
using ll = long long;
inline ll sqr(int x) { return (ll)x * x; }
struct circle { int x, y, r; } arr[300005], seq[300005];
inline bool operator <(const circle &a, const circle &b) { return a.x < b.x || (a.x == b.x && a.y < b.y); }
inline bool operator !=(const circle &a, const circle &b) { return a < b || b < a; }
inline bool operator ==(const circle &a, const circle &b) { return !(a != b); }
inline bool inter(circle a, circle b) { return sqr(a.x - b.x) + sqr(a.y - b.y) <= sqr(a.r + b.r); }
int ans[300005], ord[300005], n, blk, len;
std::vector<int> vec[300005];
void resize(int sz)
{
if (blk && blk / 2 < sz)
return;
blk = sz;
int cnt = 0;
for (int i = 0; i < n; i++)
{
if (-1 == ans[i])
seq[cnt++] = {arr[i].x / blk, arr[i].y / blk, i};
}
std::sort(seq, seq + cnt);
len = 0;
for (int i = 0, j = 0; i < cnt; i = j)
{
while (j < cnt && seq[i] == seq[j])
j++;
vec[len].clear();
for (int k = i; k < j; k++)
vec[len].push_back(seq[k].r);
seq[len++] = seq[i];
}
}
int main()
{
// freopen("uoj-415.in", "r", stdin);
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
scanf("%d%d%d", &arr[i].x, &arr[i].y, &arr[i].r);
arr[i].x += 1e9;
arr[i].y += 1e9;
ord[i] = i;
ans[i] = -1;
}
std::sort(ord, ord + n, [&] (int x, int y) { return arr[x].r > arr[y].r || (arr[x].r == arr[y].r && x < y); });
for (int t = 0; t < n; t++)
{
int u = ord[t];
if (~ans[u])
continue;
resize(arr[u].r * 2);
int x = arr[u].x / blk, y = arr[u].y / blk;
for (int i = x - 1; i <= x + 1; i++)
{
for (int j = y - 1; j <= y + 1; j++)
{
circle cur = {i, j, -1};
int res = std::lower_bound(seq, seq + len, cur) - seq;
if (res >= len || seq[res] != cur)
continue;
std::vector<int> rem;
for (int v : vec[res])
{
if (inter(arr[u], arr[v]))
ans[v] = u;
else
rem.push_back(v);
}
std::swap(vec[res], rem);
}
}
}
for (int i = 0; i < n; i++)
printf("%d%c", ans[i] + 1, " \n"[i + 1 == n]);
return 0;
}
Compilation message
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:39:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
~~~~~^~~~~~~~~~
circle_selection.cpp:42:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &arr[i].x, &arr[i].y, &arr[i].r);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
7424 KB |
Output is correct |
2 |
Correct |
8 ms |
7424 KB |
Output is correct |
3 |
Correct |
8 ms |
7424 KB |
Output is correct |
4 |
Correct |
8 ms |
7396 KB |
Output is correct |
5 |
Correct |
8 ms |
7424 KB |
Output is correct |
6 |
Correct |
8 ms |
7424 KB |
Output is correct |
7 |
Correct |
7 ms |
7424 KB |
Output is correct |
8 |
Correct |
7 ms |
7424 KB |
Output is correct |
9 |
Correct |
9 ms |
7424 KB |
Output is correct |
10 |
Correct |
10 ms |
7424 KB |
Output is correct |
11 |
Correct |
9 ms |
7424 KB |
Output is correct |
12 |
Correct |
8 ms |
7424 KB |
Output is correct |
13 |
Correct |
8 ms |
7424 KB |
Output is correct |
14 |
Correct |
33 ms |
7424 KB |
Output is correct |
15 |
Correct |
10 ms |
7424 KB |
Output is correct |
16 |
Correct |
9 ms |
7424 KB |
Output is correct |
17 |
Correct |
9 ms |
7424 KB |
Output is correct |
18 |
Correct |
9 ms |
7424 KB |
Output is correct |
19 |
Correct |
12 ms |
7552 KB |
Output is correct |
20 |
Correct |
12 ms |
7552 KB |
Output is correct |
21 |
Correct |
12 ms |
7552 KB |
Output is correct |
22 |
Correct |
18 ms |
7680 KB |
Output is correct |
23 |
Correct |
18 ms |
7680 KB |
Output is correct |
24 |
Correct |
19 ms |
7680 KB |
Output is correct |
25 |
Correct |
21 ms |
7680 KB |
Output is correct |
26 |
Correct |
21 ms |
7680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
247 ms |
18924 KB |
Output is correct |
2 |
Correct |
283 ms |
19072 KB |
Output is correct |
3 |
Correct |
245 ms |
19072 KB |
Output is correct |
4 |
Correct |
239 ms |
19156 KB |
Output is correct |
5 |
Correct |
243 ms |
20344 KB |
Output is correct |
6 |
Correct |
405 ms |
21752 KB |
Output is correct |
7 |
Correct |
313 ms |
20600 KB |
Output is correct |
8 |
Correct |
337 ms |
20728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
7424 KB |
Output is correct |
2 |
Correct |
291 ms |
14180 KB |
Output is correct |
3 |
Correct |
839 ms |
28080 KB |
Output is correct |
4 |
Correct |
902 ms |
36272 KB |
Output is correct |
5 |
Correct |
784 ms |
32964 KB |
Output is correct |
6 |
Correct |
298 ms |
20668 KB |
Output is correct |
7 |
Correct |
158 ms |
14328 KB |
Output is correct |
8 |
Correct |
36 ms |
8804 KB |
Output is correct |
9 |
Correct |
945 ms |
35704 KB |
Output is correct |
10 |
Correct |
707 ms |
33144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
733 ms |
28128 KB |
Output is correct |
2 |
Correct |
683 ms |
28280 KB |
Output is correct |
3 |
Correct |
307 ms |
20472 KB |
Output is correct |
4 |
Correct |
692 ms |
28156 KB |
Output is correct |
5 |
Correct |
682 ms |
28152 KB |
Output is correct |
6 |
Correct |
209 ms |
19960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
7424 KB |
Output is correct |
2 |
Correct |
8 ms |
7424 KB |
Output is correct |
3 |
Correct |
8 ms |
7424 KB |
Output is correct |
4 |
Correct |
8 ms |
7396 KB |
Output is correct |
5 |
Correct |
8 ms |
7424 KB |
Output is correct |
6 |
Correct |
8 ms |
7424 KB |
Output is correct |
7 |
Correct |
7 ms |
7424 KB |
Output is correct |
8 |
Correct |
7 ms |
7424 KB |
Output is correct |
9 |
Correct |
9 ms |
7424 KB |
Output is correct |
10 |
Correct |
10 ms |
7424 KB |
Output is correct |
11 |
Correct |
9 ms |
7424 KB |
Output is correct |
12 |
Correct |
8 ms |
7424 KB |
Output is correct |
13 |
Correct |
8 ms |
7424 KB |
Output is correct |
14 |
Correct |
33 ms |
7424 KB |
Output is correct |
15 |
Correct |
10 ms |
7424 KB |
Output is correct |
16 |
Correct |
9 ms |
7424 KB |
Output is correct |
17 |
Correct |
9 ms |
7424 KB |
Output is correct |
18 |
Correct |
9 ms |
7424 KB |
Output is correct |
19 |
Correct |
12 ms |
7552 KB |
Output is correct |
20 |
Correct |
12 ms |
7552 KB |
Output is correct |
21 |
Correct |
12 ms |
7552 KB |
Output is correct |
22 |
Correct |
18 ms |
7680 KB |
Output is correct |
23 |
Correct |
18 ms |
7680 KB |
Output is correct |
24 |
Correct |
19 ms |
7680 KB |
Output is correct |
25 |
Correct |
21 ms |
7680 KB |
Output is correct |
26 |
Correct |
21 ms |
7680 KB |
Output is correct |
27 |
Correct |
16 ms |
7808 KB |
Output is correct |
28 |
Correct |
15 ms |
7808 KB |
Output is correct |
29 |
Correct |
16 ms |
7808 KB |
Output is correct |
30 |
Correct |
28 ms |
8064 KB |
Output is correct |
31 |
Correct |
27 ms |
8056 KB |
Output is correct |
32 |
Correct |
34 ms |
8084 KB |
Output is correct |
33 |
Correct |
75 ms |
11368 KB |
Output is correct |
34 |
Correct |
76 ms |
11296 KB |
Output is correct |
35 |
Correct |
102 ms |
11452 KB |
Output is correct |
36 |
Correct |
259 ms |
14212 KB |
Output is correct |
37 |
Correct |
251 ms |
14200 KB |
Output is correct |
38 |
Correct |
241 ms |
14328 KB |
Output is correct |
39 |
Correct |
287 ms |
13260 KB |
Output is correct |
40 |
Correct |
263 ms |
13432 KB |
Output is correct |
41 |
Correct |
273 ms |
13340 KB |
Output is correct |
42 |
Correct |
135 ms |
11844 KB |
Output is correct |
43 |
Correct |
189 ms |
14132 KB |
Output is correct |
44 |
Correct |
181 ms |
14176 KB |
Output is correct |
45 |
Correct |
190 ms |
14076 KB |
Output is correct |
46 |
Correct |
179 ms |
14044 KB |
Output is correct |
47 |
Correct |
185 ms |
14072 KB |
Output is correct |
48 |
Correct |
196 ms |
14072 KB |
Output is correct |
49 |
Correct |
204 ms |
14072 KB |
Output is correct |
50 |
Correct |
210 ms |
14200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
7424 KB |
Output is correct |
2 |
Correct |
8 ms |
7424 KB |
Output is correct |
3 |
Correct |
8 ms |
7424 KB |
Output is correct |
4 |
Correct |
8 ms |
7396 KB |
Output is correct |
5 |
Correct |
8 ms |
7424 KB |
Output is correct |
6 |
Correct |
8 ms |
7424 KB |
Output is correct |
7 |
Correct |
7 ms |
7424 KB |
Output is correct |
8 |
Correct |
7 ms |
7424 KB |
Output is correct |
9 |
Correct |
9 ms |
7424 KB |
Output is correct |
10 |
Correct |
10 ms |
7424 KB |
Output is correct |
11 |
Correct |
9 ms |
7424 KB |
Output is correct |
12 |
Correct |
8 ms |
7424 KB |
Output is correct |
13 |
Correct |
8 ms |
7424 KB |
Output is correct |
14 |
Correct |
33 ms |
7424 KB |
Output is correct |
15 |
Correct |
10 ms |
7424 KB |
Output is correct |
16 |
Correct |
9 ms |
7424 KB |
Output is correct |
17 |
Correct |
9 ms |
7424 KB |
Output is correct |
18 |
Correct |
9 ms |
7424 KB |
Output is correct |
19 |
Correct |
12 ms |
7552 KB |
Output is correct |
20 |
Correct |
12 ms |
7552 KB |
Output is correct |
21 |
Correct |
12 ms |
7552 KB |
Output is correct |
22 |
Correct |
18 ms |
7680 KB |
Output is correct |
23 |
Correct |
18 ms |
7680 KB |
Output is correct |
24 |
Correct |
19 ms |
7680 KB |
Output is correct |
25 |
Correct |
21 ms |
7680 KB |
Output is correct |
26 |
Correct |
21 ms |
7680 KB |
Output is correct |
27 |
Correct |
247 ms |
18924 KB |
Output is correct |
28 |
Correct |
283 ms |
19072 KB |
Output is correct |
29 |
Correct |
245 ms |
19072 KB |
Output is correct |
30 |
Correct |
239 ms |
19156 KB |
Output is correct |
31 |
Correct |
243 ms |
20344 KB |
Output is correct |
32 |
Correct |
405 ms |
21752 KB |
Output is correct |
33 |
Correct |
313 ms |
20600 KB |
Output is correct |
34 |
Correct |
337 ms |
20728 KB |
Output is correct |
35 |
Correct |
8 ms |
7424 KB |
Output is correct |
36 |
Correct |
291 ms |
14180 KB |
Output is correct |
37 |
Correct |
839 ms |
28080 KB |
Output is correct |
38 |
Correct |
902 ms |
36272 KB |
Output is correct |
39 |
Correct |
784 ms |
32964 KB |
Output is correct |
40 |
Correct |
298 ms |
20668 KB |
Output is correct |
41 |
Correct |
158 ms |
14328 KB |
Output is correct |
42 |
Correct |
36 ms |
8804 KB |
Output is correct |
43 |
Correct |
945 ms |
35704 KB |
Output is correct |
44 |
Correct |
707 ms |
33144 KB |
Output is correct |
45 |
Correct |
733 ms |
28128 KB |
Output is correct |
46 |
Correct |
683 ms |
28280 KB |
Output is correct |
47 |
Correct |
307 ms |
20472 KB |
Output is correct |
48 |
Correct |
692 ms |
28156 KB |
Output is correct |
49 |
Correct |
682 ms |
28152 KB |
Output is correct |
50 |
Correct |
209 ms |
19960 KB |
Output is correct |
51 |
Correct |
16 ms |
7808 KB |
Output is correct |
52 |
Correct |
15 ms |
7808 KB |
Output is correct |
53 |
Correct |
16 ms |
7808 KB |
Output is correct |
54 |
Correct |
28 ms |
8064 KB |
Output is correct |
55 |
Correct |
27 ms |
8056 KB |
Output is correct |
56 |
Correct |
34 ms |
8084 KB |
Output is correct |
57 |
Correct |
75 ms |
11368 KB |
Output is correct |
58 |
Correct |
76 ms |
11296 KB |
Output is correct |
59 |
Correct |
102 ms |
11452 KB |
Output is correct |
60 |
Correct |
259 ms |
14212 KB |
Output is correct |
61 |
Correct |
251 ms |
14200 KB |
Output is correct |
62 |
Correct |
241 ms |
14328 KB |
Output is correct |
63 |
Correct |
287 ms |
13260 KB |
Output is correct |
64 |
Correct |
263 ms |
13432 KB |
Output is correct |
65 |
Correct |
273 ms |
13340 KB |
Output is correct |
66 |
Correct |
135 ms |
11844 KB |
Output is correct |
67 |
Correct |
189 ms |
14132 KB |
Output is correct |
68 |
Correct |
181 ms |
14176 KB |
Output is correct |
69 |
Correct |
190 ms |
14076 KB |
Output is correct |
70 |
Correct |
179 ms |
14044 KB |
Output is correct |
71 |
Correct |
185 ms |
14072 KB |
Output is correct |
72 |
Correct |
196 ms |
14072 KB |
Output is correct |
73 |
Correct |
204 ms |
14072 KB |
Output is correct |
74 |
Correct |
210 ms |
14200 KB |
Output is correct |
75 |
Correct |
266 ms |
28708 KB |
Output is correct |
76 |
Correct |
253 ms |
29196 KB |
Output is correct |
77 |
Correct |
253 ms |
27888 KB |
Output is correct |
78 |
Correct |
261 ms |
28068 KB |
Output is correct |
79 |
Correct |
297 ms |
28368 KB |
Output is correct |
80 |
Correct |
255 ms |
28388 KB |
Output is correct |
81 |
Correct |
895 ms |
36216 KB |
Output is correct |
82 |
Correct |
936 ms |
36088 KB |
Output is correct |
83 |
Correct |
885 ms |
36064 KB |
Output is correct |
84 |
Correct |
917 ms |
36400 KB |
Output is correct |
85 |
Correct |
992 ms |
36140 KB |
Output is correct |
86 |
Correct |
855 ms |
36144 KB |
Output is correct |
87 |
Correct |
908 ms |
35952 KB |
Output is correct |
88 |
Correct |
968 ms |
30524 KB |
Output is correct |
89 |
Correct |
891 ms |
29156 KB |
Output is correct |
90 |
Correct |
922 ms |
29476 KB |
Output is correct |
91 |
Correct |
936 ms |
29544 KB |
Output is correct |
92 |
Correct |
932 ms |
28456 KB |
Output is correct |
93 |
Correct |
757 ms |
35068 KB |
Output is correct |
94 |
Correct |
927 ms |
35688 KB |
Output is correct |
95 |
Correct |
766 ms |
35064 KB |
Output is correct |
96 |
Correct |
736 ms |
35128 KB |
Output is correct |
97 |
Correct |
906 ms |
35064 KB |
Output is correct |
98 |
Correct |
519 ms |
29048 KB |
Output is correct |
99 |
Correct |
832 ms |
35216 KB |
Output is correct |
100 |
Correct |
724 ms |
35036 KB |
Output is correct |
101 |
Correct |
705 ms |
30492 KB |
Output is correct |
102 |
Correct |
760 ms |
34780 KB |
Output is correct |
103 |
Correct |
915 ms |
34672 KB |
Output is correct |
104 |
Correct |
723 ms |
34952 KB |
Output is correct |
105 |
Correct |
453 ms |
25848 KB |
Output is correct |
106 |
Correct |
607 ms |
34808 KB |
Output is correct |
107 |
Correct |
659 ms |
34696 KB |
Output is correct |
108 |
Correct |
627 ms |
34724 KB |
Output is correct |
109 |
Correct |
612 ms |
34680 KB |
Output is correct |
110 |
Correct |
685 ms |
34684 KB |
Output is correct |
111 |
Correct |
695 ms |
34800 KB |
Output is correct |
112 |
Correct |
625 ms |
34564 KB |
Output is correct |
113 |
Correct |
608 ms |
34584 KB |
Output is correct |
114 |
Correct |
627 ms |
34580 KB |
Output is correct |
115 |
Correct |
595 ms |
34680 KB |
Output is correct |
116 |
Correct |
629 ms |
34692 KB |
Output is correct |