#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 3e5+10;
const int add = 1e9;
ll R;
struct Circle
{
ll x, y, r;
int ind;
bool operator<(const ll &o) const
{
return y/R < o;
}
} circle[maxn];
vector<vector<Circle>> V;
int ans[maxn];
bool comp1(Circle a, Circle b)
{
if (a.x/R == b.x/R) return a.y < b.y;
return a.x < b.x;
}
bool comp2(Circle a, Circle b)
{
if (a.r == b.r) return a.ind < b.ind;
return a.r > b.r;
}
bool intersect(Circle a, Circle b)
{
ll dx = a.x-b.x, dy = a.y-b.y, dr = a.r+b.r;
return dx*dx + dy*dy <= dr*dr;
}
void rescale(void)
{
vector<vector<Circle>> aux;
for (int i = 0; i < V.size(); i++)
{
ll mn = 1e18, mx = 0;
for (auto c: V[i])
{
mn = min(mn, c.x/R);
mx = max(mx, c.x/R);
}
ll med = mn;
for (auto c: V[i])
if (c.x/R != mn && c.x/R != mx)
med = c.x/R;
if (aux.size() == 0 || mn > aux.back()[0].x/R)
{
aux.push_back(vector<Circle>());
for (auto c: V[i])
if (c.x/R == mn)
aux.back().push_back(c);
}
else
{
vector<Circle> aux1, aux2;
for (auto c: V[i])
if (c.x/R == mn)
aux1.push_back(c);
for (auto c: aux.back())
aux2.push_back(c);
aux.back().clear();
int ptr1 = 0, ptr2 = 0;
while (ptr1 < aux1.size() || ptr2 < aux2.size())
{
if (ptr1 == aux1.size()) aux.back().push_back(aux2[ptr2++]);
else if (ptr2 == aux2.size()) aux.back().push_back(aux1[ptr1++]);
else if (aux1[ptr1].y <= aux2[ptr2].y) aux.back().push_back(aux1[ptr1++]);
else aux.back().push_back(aux2[ptr2++]);
}
}
if (med > mn)
{
aux.push_back(vector<Circle>());
for (auto c: V[i])
if (c.x/R == med)
aux.back().push_back(c);
}
if (mx > med)
{
aux.push_back(vector<Circle>());
for (auto c: V[i])
if (c.x/R == mx)
aux.back().push_back(c);
}
}
swap(aux, V);
}
void doit(int pos, int c)
{
ll y = circle[c].y;
ll l_y = y/R - 2, r_y = y/R + 3;
auto it = lower_bound(V[pos].begin(), V[pos].end(), l_y);
for (; it != V[pos].end() && it->y/R <= r_y; it++)
if (intersect(circle[c], *it) && !ans[it->ind])
ans[it->ind] = circle[c].ind;
}
int main(void)
{
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++)
{
scanf("%lld %lld %lld", &circle[i].x, &circle[i].y, &circle[i].r);
circle[i].x += add, circle[i].y += add;
circle[i].ind = i;
R = max(R, circle[i].r);
}
sort(circle+1, circle+n+1, comp1);
for (int i = 1; i <= n; i++)
{
if (i == 1 || circle[i].x/R > circle[i-1].x/R)
V.push_back(vector<Circle>());
V.back().push_back(circle[i]);
}
sort(circle+1, circle+n+1, comp2);
for (int i = 1; i <= n; i++)
{
if (ans[circle[i].ind]) continue;
while (circle[i].r < R/2)
{
R /= 2;
rescale();
}
ll x = circle[i].x;
ll l_x = x/R - 2, r_x = x/R + 3;
int p_l, p_r;
int ini = 0, fim = (int)V.size()-1;
while (ini <= fim)
{
int mid = (ini+fim)>>1;
if (V[mid][0].x/R >= l_x) p_l = mid, fim = mid-1;
else ini = mid+1;
}
ini = 0, fim = (int)V.size()-1;
while (ini <= fim)
{
int mid = (ini+fim)>>1;
if (V[mid][0].x/R <= r_x) p_r = mid, ini = mid+1;
else fim = mid-1;
}
for (int j = p_l; j <= p_r; j++)
doit(j, i);
}
for (int i = 1; i <= n; i++)
printf("%d ", ans[i]);
printf("\n");
}
Compilation message
circle_selection.cpp: In function 'void rescale()':
circle_selection.cpp:50:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<Circle> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for (int i = 0; i < V.size(); i++)
| ~~^~~~~~~~~~
circle_selection.cpp:88:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Circle>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
88 | while (ptr1 < aux1.size() || ptr2 < aux2.size())
| ~~~~~^~~~~~~~~~~~~
circle_selection.cpp:88:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Circle>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
88 | while (ptr1 < aux1.size() || ptr2 < aux2.size())
| ~~~~~^~~~~~~~~~~~~
circle_selection.cpp:90:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Circle>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
90 | if (ptr1 == aux1.size()) aux.back().push_back(aux2[ptr2++]);
| ~~~~~^~~~~~~~~~~~~~
circle_selection.cpp:91:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Circle>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
91 | else if (ptr2 == aux2.size()) aux.back().push_back(aux1[ptr1++]);
| ~~~~~^~~~~~~~~~~~~~
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:134:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
134 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
circle_selection.cpp:138:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
138 | scanf("%lld %lld %lld", &circle[i].x, &circle[i].y, &circle[i].r);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
circle_selection.cpp:171:12: warning: 'p_r' may be used uninitialized in this function [-Wmaybe-uninitialized]
171 | int p_l, p_r;
| ^~~
circle_selection.cpp:193:3: warning: 'p_l' may be used uninitialized in this function [-Wmaybe-uninitialized]
193 | for (int j = p_l; j <= p_r; j++)
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
1 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 |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 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 |
2 ms |
492 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
492 KB |
Output is correct |
19 |
Correct |
5 ms |
876 KB |
Output is correct |
20 |
Correct |
5 ms |
876 KB |
Output is correct |
21 |
Correct |
6 ms |
1068 KB |
Output is correct |
22 |
Correct |
14 ms |
1564 KB |
Output is correct |
23 |
Correct |
15 ms |
1552 KB |
Output is correct |
24 |
Correct |
14 ms |
1564 KB |
Output is correct |
25 |
Correct |
14 ms |
1540 KB |
Output is correct |
26 |
Correct |
14 ms |
1564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
315 ms |
35192 KB |
Output is correct |
2 |
Correct |
322 ms |
34372 KB |
Output is correct |
3 |
Correct |
289 ms |
22772 KB |
Output is correct |
4 |
Correct |
308 ms |
37156 KB |
Output is correct |
5 |
Correct |
511 ms |
43596 KB |
Output is correct |
6 |
Correct |
709 ms |
63340 KB |
Output is correct |
7 |
Correct |
601 ms |
58172 KB |
Output is correct |
8 |
Correct |
590 ms |
58112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
385 ms |
21680 KB |
Output is correct |
3 |
Correct |
1265 ms |
74608 KB |
Output is correct |
4 |
Correct |
1259 ms |
87348 KB |
Output is correct |
5 |
Correct |
1217 ms |
78776 KB |
Output is correct |
6 |
Correct |
370 ms |
31320 KB |
Output is correct |
7 |
Correct |
178 ms |
15624 KB |
Output is correct |
8 |
Correct |
31 ms |
3796 KB |
Output is correct |
9 |
Correct |
1270 ms |
73804 KB |
Output is correct |
10 |
Correct |
724 ms |
52136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
764 ms |
27852 KB |
Output is correct |
2 |
Correct |
771 ms |
34392 KB |
Output is correct |
3 |
Correct |
392 ms |
23496 KB |
Output is correct |
4 |
Correct |
731 ms |
35096 KB |
Output is correct |
5 |
Correct |
723 ms |
34584 KB |
Output is correct |
6 |
Correct |
393 ms |
21996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
1 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 |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 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 |
2 ms |
492 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
492 KB |
Output is correct |
19 |
Correct |
5 ms |
876 KB |
Output is correct |
20 |
Correct |
5 ms |
876 KB |
Output is correct |
21 |
Correct |
6 ms |
1068 KB |
Output is correct |
22 |
Correct |
14 ms |
1564 KB |
Output is correct |
23 |
Correct |
15 ms |
1552 KB |
Output is correct |
24 |
Correct |
14 ms |
1564 KB |
Output is correct |
25 |
Correct |
14 ms |
1540 KB |
Output is correct |
26 |
Correct |
14 ms |
1564 KB |
Output is correct |
27 |
Correct |
15 ms |
2320 KB |
Output is correct |
28 |
Correct |
10 ms |
1516 KB |
Output is correct |
29 |
Correct |
10 ms |
1516 KB |
Output is correct |
30 |
Correct |
30 ms |
2764 KB |
Output is correct |
31 |
Correct |
28 ms |
2948 KB |
Output is correct |
32 |
Correct |
30 ms |
2936 KB |
Output is correct |
33 |
Correct |
99 ms |
10844 KB |
Output is correct |
34 |
Correct |
114 ms |
11356 KB |
Output is correct |
35 |
Correct |
208 ms |
20444 KB |
Output is correct |
36 |
Correct |
333 ms |
25768 KB |
Output is correct |
37 |
Correct |
357 ms |
24732 KB |
Output is correct |
38 |
Correct |
372 ms |
25160 KB |
Output is correct |
39 |
Correct |
343 ms |
19532 KB |
Output is correct |
40 |
Correct |
334 ms |
20044 KB |
Output is correct |
41 |
Correct |
363 ms |
23116 KB |
Output is correct |
42 |
Correct |
149 ms |
10604 KB |
Output is correct |
43 |
Correct |
191 ms |
14048 KB |
Output is correct |
44 |
Correct |
220 ms |
13980 KB |
Output is correct |
45 |
Correct |
195 ms |
13980 KB |
Output is correct |
46 |
Correct |
198 ms |
13980 KB |
Output is correct |
47 |
Correct |
190 ms |
13980 KB |
Output is correct |
48 |
Correct |
203 ms |
13992 KB |
Output is correct |
49 |
Correct |
205 ms |
14108 KB |
Output is correct |
50 |
Correct |
186 ms |
13980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
1 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 |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 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 |
2 ms |
492 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
492 KB |
Output is correct |
19 |
Correct |
5 ms |
876 KB |
Output is correct |
20 |
Correct |
5 ms |
876 KB |
Output is correct |
21 |
Correct |
6 ms |
1068 KB |
Output is correct |
22 |
Correct |
14 ms |
1564 KB |
Output is correct |
23 |
Correct |
15 ms |
1552 KB |
Output is correct |
24 |
Correct |
14 ms |
1564 KB |
Output is correct |
25 |
Correct |
14 ms |
1540 KB |
Output is correct |
26 |
Correct |
14 ms |
1564 KB |
Output is correct |
27 |
Correct |
315 ms |
35192 KB |
Output is correct |
28 |
Correct |
322 ms |
34372 KB |
Output is correct |
29 |
Correct |
289 ms |
22772 KB |
Output is correct |
30 |
Correct |
308 ms |
37156 KB |
Output is correct |
31 |
Correct |
511 ms |
43596 KB |
Output is correct |
32 |
Correct |
709 ms |
63340 KB |
Output is correct |
33 |
Correct |
601 ms |
58172 KB |
Output is correct |
34 |
Correct |
590 ms |
58112 KB |
Output is correct |
35 |
Correct |
1 ms |
492 KB |
Output is correct |
36 |
Correct |
385 ms |
21680 KB |
Output is correct |
37 |
Correct |
1265 ms |
74608 KB |
Output is correct |
38 |
Correct |
1259 ms |
87348 KB |
Output is correct |
39 |
Correct |
1217 ms |
78776 KB |
Output is correct |
40 |
Correct |
370 ms |
31320 KB |
Output is correct |
41 |
Correct |
178 ms |
15624 KB |
Output is correct |
42 |
Correct |
31 ms |
3796 KB |
Output is correct |
43 |
Correct |
1270 ms |
73804 KB |
Output is correct |
44 |
Correct |
724 ms |
52136 KB |
Output is correct |
45 |
Correct |
764 ms |
27852 KB |
Output is correct |
46 |
Correct |
771 ms |
34392 KB |
Output is correct |
47 |
Correct |
392 ms |
23496 KB |
Output is correct |
48 |
Correct |
731 ms |
35096 KB |
Output is correct |
49 |
Correct |
723 ms |
34584 KB |
Output is correct |
50 |
Correct |
393 ms |
21996 KB |
Output is correct |
51 |
Correct |
15 ms |
2320 KB |
Output is correct |
52 |
Correct |
10 ms |
1516 KB |
Output is correct |
53 |
Correct |
10 ms |
1516 KB |
Output is correct |
54 |
Correct |
30 ms |
2764 KB |
Output is correct |
55 |
Correct |
28 ms |
2948 KB |
Output is correct |
56 |
Correct |
30 ms |
2936 KB |
Output is correct |
57 |
Correct |
99 ms |
10844 KB |
Output is correct |
58 |
Correct |
114 ms |
11356 KB |
Output is correct |
59 |
Correct |
208 ms |
20444 KB |
Output is correct |
60 |
Correct |
333 ms |
25768 KB |
Output is correct |
61 |
Correct |
357 ms |
24732 KB |
Output is correct |
62 |
Correct |
372 ms |
25160 KB |
Output is correct |
63 |
Correct |
343 ms |
19532 KB |
Output is correct |
64 |
Correct |
334 ms |
20044 KB |
Output is correct |
65 |
Correct |
363 ms |
23116 KB |
Output is correct |
66 |
Correct |
149 ms |
10604 KB |
Output is correct |
67 |
Correct |
191 ms |
14048 KB |
Output is correct |
68 |
Correct |
220 ms |
13980 KB |
Output is correct |
69 |
Correct |
195 ms |
13980 KB |
Output is correct |
70 |
Correct |
198 ms |
13980 KB |
Output is correct |
71 |
Correct |
190 ms |
13980 KB |
Output is correct |
72 |
Correct |
203 ms |
13992 KB |
Output is correct |
73 |
Correct |
205 ms |
14108 KB |
Output is correct |
74 |
Correct |
186 ms |
13980 KB |
Output is correct |
75 |
Correct |
589 ms |
57720 KB |
Output is correct |
76 |
Correct |
442 ms |
49800 KB |
Output is correct |
77 |
Correct |
331 ms |
35156 KB |
Output is correct |
78 |
Correct |
335 ms |
35412 KB |
Output is correct |
79 |
Correct |
701 ms |
57332 KB |
Output is correct |
80 |
Correct |
320 ms |
35288 KB |
Output is correct |
81 |
Correct |
1234 ms |
76756 KB |
Output is correct |
82 |
Correct |
1201 ms |
80340 KB |
Output is correct |
83 |
Correct |
1226 ms |
74568 KB |
Output is correct |
84 |
Correct |
1229 ms |
80472 KB |
Output is correct |
85 |
Correct |
1235 ms |
79564 KB |
Output is correct |
86 |
Correct |
1213 ms |
80060 KB |
Output is correct |
87 |
Correct |
1250 ms |
77276 KB |
Output is correct |
88 |
Correct |
1150 ms |
68964 KB |
Output is correct |
89 |
Correct |
1214 ms |
68900 KB |
Output is correct |
90 |
Correct |
1175 ms |
69924 KB |
Output is correct |
91 |
Correct |
1100 ms |
66596 KB |
Output is correct |
92 |
Correct |
1194 ms |
68900 KB |
Output is correct |
93 |
Correct |
851 ms |
66476 KB |
Output is correct |
94 |
Correct |
839 ms |
50632 KB |
Output is correct |
95 |
Correct |
858 ms |
66692 KB |
Output is correct |
96 |
Correct |
867 ms |
72724 KB |
Output is correct |
97 |
Correct |
1120 ms |
40460 KB |
Output is correct |
98 |
Correct |
722 ms |
70568 KB |
Output is correct |
99 |
Correct |
900 ms |
73912 KB |
Output is correct |
100 |
Correct |
791 ms |
64384 KB |
Output is correct |
101 |
Correct |
812 ms |
64068 KB |
Output is correct |
102 |
Correct |
914 ms |
73400 KB |
Output is correct |
103 |
Correct |
1085 ms |
46140 KB |
Output is correct |
104 |
Correct |
876 ms |
73460 KB |
Output is correct |
105 |
Correct |
473 ms |
29232 KB |
Output is correct |
106 |
Correct |
686 ms |
39440 KB |
Output is correct |
107 |
Correct |
665 ms |
39568 KB |
Output is correct |
108 |
Correct |
654 ms |
39568 KB |
Output is correct |
109 |
Correct |
639 ms |
39440 KB |
Output is correct |
110 |
Correct |
659 ms |
39504 KB |
Output is correct |
111 |
Correct |
662 ms |
39568 KB |
Output is correct |
112 |
Correct |
656 ms |
39568 KB |
Output is correct |
113 |
Correct |
662 ms |
39440 KB |
Output is correct |
114 |
Correct |
697 ms |
39440 KB |
Output is correct |
115 |
Correct |
698 ms |
39568 KB |
Output is correct |
116 |
Correct |
652 ms |
42776 KB |
Output is correct |