#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct point
{
ll x, y;
point(ll _x = 0, ll _y = 0)
{
x = _x;
y = _y;
}
void get()
{
cin >> x >> y;
}
};
struct circle
{
point centre;
ll radius;
int idx;
circle(point _centre = point(), ll _radius = 0, int _idx = 0)
{
centre = _centre;
radius = _radius;
idx = _idx;
}
void get()
{
centre.get();
cin >> radius;
}
};
ll get_distance(point A, point B)
{
return (A.x - B.x) * (A.x - B.x) +
(A.y - B.y) * (A.y - B.y);
}
bool intersect(circle c1, circle c2)
{
ll distance = get_distance(c1.centre, c2.centre);
return (distance <= (c1.radius + c2.radius) * (c1.radius + c2.radius));
}
const int maxn = 3e5 + 10;
const int inf = 1e9 + 10;
bool cmpx(circle c1, circle c2)
{
return c1.centre.x < c2.centre.x;
}
bool cmpy(circle c1, circle c2)
{
return c1.centre.y < c2.centre.y;
}
int n;
circle c[maxn], cx[maxn], cy[maxn];
void input()
{
cin >> n;
for (int i = 1; i <= n; i ++)
{
c[i].get();
c[i].idx = i;
cx[i] = cy[i] = c[i];
}
}
void sort_arrays()
{
sort(cx + 1, cx + n + 1, cmpx);
sort(cy + 1, cy + n + 1, cmpy);
}
vector < vector < circle > > field;
bool eliminated[maxn];
int parent[maxn];
point comp[maxn];
void restructure(int block)
{
field.clear();
vector < int > dx;
int last = -inf;
for (int i = 1; i <= n; i ++)
{
if (eliminated[cx[i].idx])
continue;
int cur = cx[i].centre.x / block;
if (cur != last)
field.emplace_back();
comp[cx[i].idx].x = field.size() - 1;
last = cur;
}
for (int i = 1; i <= n; i ++)
{
if (eliminated[cy[i].idx])
continue;
comp[cy[i].idx].y = field[comp[cy[i].idx].x].size();
field[comp[cy[i].idx].x].push_back(cy[i]);
}
}
void simulate()
{
int last_block = 0;
for (int i = 1; i <= n; i ++)
last_block = max(last_block, (int)c[i].radius);
restructure(last_block);
set < pair < int, int > > active;
for (int i = 1; i <= n; i ++)
active.insert({c[i].radius, -i});
while(!active.empty())
{
int idx = -active.rbegin() -> second;
if (c[idx].radius <= last_block / 2)
{
last_block = c[idx].radius;
restructure(last_block);
}
int cor_x = comp[idx].x, cor_y = comp[idx].y;
for (int i = max(0, cor_x - 2); i < min((int)field.size(), cor_x + 3); i ++)
{
int lf = 0, rf = (int)(field[i].size()) - 1;
while(lf <= rf)
{
int mf = (lf + rf) / 2;
if (c[idx].centre.y / last_block - field[i][mf].centre.y / last_block > 2)
lf = mf + 1;
else
rf = mf - 1;
}
int lb = lf;
lf = 0;
rf = (int)(field[i].size()) - 1;
while(lf <= rf)
{
int mf = (lf + rf) / 2;
if (field[i][mf].centre.y / last_block - c[idx].centre.y / last_block > 2)
rf = mf - 1;
else
lf = mf + 1;
}
int rb = rf;
for (int j = lb; j <= rb; j ++)
{
if (eliminated[field[i][j].idx])
continue;
if (intersect(field[i][j], c[idx]))
{
parent[field[i][j].idx] = idx;
eliminated[field[i][j].idx] = 1;
active.erase({field[i][j].radius, -field[i][j].idx});
}
}
}
}
for (int i = 1; i <= n; i ++)
std::cout << parent[i] << " ";
std::cout << std::endl;
}
void solve()
{
input();
sort_arrays();
simulate();
}
int main()
{
solve();
return 0;
}
/**
11
9 9 2
13 2 1
11 8 2
3 3 2
3 12 1
12 14 1
9 8 5
2 8 2
5 2 1
14 4 2
14 14 1
*/
Compilation message
circle_selection.cpp: In function 'void simulate()':
circle_selection.cpp:149:34: warning: unused variable 'cor_y' [-Wunused-variable]
149 | int cor_x = comp[idx].x, cor_y = comp[idx].y;
| ^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
34652 KB |
Output is correct |
2 |
Correct |
5 ms |
34652 KB |
Output is correct |
3 |
Correct |
6 ms |
34648 KB |
Output is correct |
4 |
Correct |
5 ms |
34652 KB |
Output is correct |
5 |
Correct |
5 ms |
34652 KB |
Output is correct |
6 |
Correct |
5 ms |
34560 KB |
Output is correct |
7 |
Correct |
5 ms |
34588 KB |
Output is correct |
8 |
Correct |
5 ms |
34652 KB |
Output is correct |
9 |
Correct |
5 ms |
34592 KB |
Output is correct |
10 |
Correct |
5 ms |
34652 KB |
Output is correct |
11 |
Correct |
6 ms |
34648 KB |
Output is correct |
12 |
Correct |
5 ms |
34652 KB |
Output is correct |
13 |
Correct |
6 ms |
34652 KB |
Output is correct |
14 |
Correct |
6 ms |
34592 KB |
Output is correct |
15 |
Correct |
6 ms |
34652 KB |
Output is correct |
16 |
Correct |
7 ms |
34652 KB |
Output is correct |
17 |
Correct |
7 ms |
34652 KB |
Output is correct |
18 |
Correct |
7 ms |
34652 KB |
Output is correct |
19 |
Correct |
12 ms |
35164 KB |
Output is correct |
20 |
Correct |
12 ms |
35164 KB |
Output is correct |
21 |
Correct |
12 ms |
35416 KB |
Output is correct |
22 |
Correct |
13 ms |
35292 KB |
Output is correct |
23 |
Correct |
14 ms |
35164 KB |
Output is correct |
24 |
Correct |
14 ms |
35092 KB |
Output is correct |
25 |
Correct |
12 ms |
35356 KB |
Output is correct |
26 |
Correct |
15 ms |
35160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
469 ms |
58460 KB |
Output is correct |
2 |
Correct |
514 ms |
61656 KB |
Output is correct |
3 |
Correct |
500 ms |
60944 KB |
Output is correct |
4 |
Correct |
486 ms |
59164 KB |
Output is correct |
5 |
Correct |
537 ms |
64228 KB |
Output is correct |
6 |
Correct |
587 ms |
69044 KB |
Output is correct |
7 |
Correct |
543 ms |
69712 KB |
Output is correct |
8 |
Correct |
535 ms |
69828 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
34652 KB |
Output is correct |
2 |
Correct |
228 ms |
44868 KB |
Output is correct |
3 |
Correct |
800 ms |
73632 KB |
Output is correct |
4 |
Correct |
813 ms |
73668 KB |
Output is correct |
5 |
Correct |
783 ms |
71800 KB |
Output is correct |
6 |
Correct |
349 ms |
54400 KB |
Output is correct |
7 |
Correct |
167 ms |
45204 KB |
Output is correct |
8 |
Correct |
36 ms |
36940 KB |
Output is correct |
9 |
Correct |
827 ms |
72384 KB |
Output is correct |
10 |
Correct |
865 ms |
74196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
628 ms |
65848 KB |
Output is correct |
2 |
Correct |
639 ms |
78876 KB |
Output is correct |
3 |
Correct |
619 ms |
70356 KB |
Output is correct |
4 |
Correct |
603 ms |
79284 KB |
Output is correct |
5 |
Correct |
619 ms |
80212 KB |
Output is correct |
6 |
Correct |
623 ms |
68424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
34652 KB |
Output is correct |
2 |
Correct |
5 ms |
34652 KB |
Output is correct |
3 |
Correct |
6 ms |
34648 KB |
Output is correct |
4 |
Correct |
5 ms |
34652 KB |
Output is correct |
5 |
Correct |
5 ms |
34652 KB |
Output is correct |
6 |
Correct |
5 ms |
34560 KB |
Output is correct |
7 |
Correct |
5 ms |
34588 KB |
Output is correct |
8 |
Correct |
5 ms |
34652 KB |
Output is correct |
9 |
Correct |
5 ms |
34592 KB |
Output is correct |
10 |
Correct |
5 ms |
34652 KB |
Output is correct |
11 |
Correct |
6 ms |
34648 KB |
Output is correct |
12 |
Correct |
5 ms |
34652 KB |
Output is correct |
13 |
Correct |
6 ms |
34652 KB |
Output is correct |
14 |
Correct |
6 ms |
34592 KB |
Output is correct |
15 |
Correct |
6 ms |
34652 KB |
Output is correct |
16 |
Correct |
7 ms |
34652 KB |
Output is correct |
17 |
Correct |
7 ms |
34652 KB |
Output is correct |
18 |
Correct |
7 ms |
34652 KB |
Output is correct |
19 |
Correct |
12 ms |
35164 KB |
Output is correct |
20 |
Correct |
12 ms |
35164 KB |
Output is correct |
21 |
Correct |
12 ms |
35416 KB |
Output is correct |
22 |
Correct |
13 ms |
35292 KB |
Output is correct |
23 |
Correct |
14 ms |
35164 KB |
Output is correct |
24 |
Correct |
14 ms |
35092 KB |
Output is correct |
25 |
Correct |
12 ms |
35356 KB |
Output is correct |
26 |
Correct |
15 ms |
35160 KB |
Output is correct |
27 |
Correct |
20 ms |
35580 KB |
Output is correct |
28 |
Correct |
19 ms |
35408 KB |
Output is correct |
29 |
Correct |
19 ms |
35544 KB |
Output is correct |
30 |
Correct |
22 ms |
35672 KB |
Output is correct |
31 |
Correct |
21 ms |
35736 KB |
Output is correct |
32 |
Correct |
21 ms |
35836 KB |
Output is correct |
33 |
Correct |
169 ms |
43144 KB |
Output is correct |
34 |
Correct |
175 ms |
43064 KB |
Output is correct |
35 |
Correct |
169 ms |
42544 KB |
Output is correct |
36 |
Correct |
187 ms |
45252 KB |
Output is correct |
37 |
Correct |
197 ms |
47848 KB |
Output is correct |
38 |
Correct |
205 ms |
47708 KB |
Output is correct |
39 |
Correct |
216 ms |
47816 KB |
Output is correct |
40 |
Correct |
208 ms |
47860 KB |
Output is correct |
41 |
Correct |
218 ms |
48080 KB |
Output is correct |
42 |
Correct |
142 ms |
46416 KB |
Output is correct |
43 |
Correct |
174 ms |
49340 KB |
Output is correct |
44 |
Correct |
162 ms |
50096 KB |
Output is correct |
45 |
Correct |
187 ms |
50028 KB |
Output is correct |
46 |
Correct |
157 ms |
49572 KB |
Output is correct |
47 |
Correct |
174 ms |
49828 KB |
Output is correct |
48 |
Correct |
153 ms |
49712 KB |
Output is correct |
49 |
Correct |
151 ms |
50112 KB |
Output is correct |
50 |
Correct |
175 ms |
50080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
34652 KB |
Output is correct |
2 |
Correct |
5 ms |
34652 KB |
Output is correct |
3 |
Correct |
6 ms |
34648 KB |
Output is correct |
4 |
Correct |
5 ms |
34652 KB |
Output is correct |
5 |
Correct |
5 ms |
34652 KB |
Output is correct |
6 |
Correct |
5 ms |
34560 KB |
Output is correct |
7 |
Correct |
5 ms |
34588 KB |
Output is correct |
8 |
Correct |
5 ms |
34652 KB |
Output is correct |
9 |
Correct |
5 ms |
34592 KB |
Output is correct |
10 |
Correct |
5 ms |
34652 KB |
Output is correct |
11 |
Correct |
6 ms |
34648 KB |
Output is correct |
12 |
Correct |
5 ms |
34652 KB |
Output is correct |
13 |
Correct |
6 ms |
34652 KB |
Output is correct |
14 |
Correct |
6 ms |
34592 KB |
Output is correct |
15 |
Correct |
6 ms |
34652 KB |
Output is correct |
16 |
Correct |
7 ms |
34652 KB |
Output is correct |
17 |
Correct |
7 ms |
34652 KB |
Output is correct |
18 |
Correct |
7 ms |
34652 KB |
Output is correct |
19 |
Correct |
12 ms |
35164 KB |
Output is correct |
20 |
Correct |
12 ms |
35164 KB |
Output is correct |
21 |
Correct |
12 ms |
35416 KB |
Output is correct |
22 |
Correct |
13 ms |
35292 KB |
Output is correct |
23 |
Correct |
14 ms |
35164 KB |
Output is correct |
24 |
Correct |
14 ms |
35092 KB |
Output is correct |
25 |
Correct |
12 ms |
35356 KB |
Output is correct |
26 |
Correct |
15 ms |
35160 KB |
Output is correct |
27 |
Correct |
469 ms |
58460 KB |
Output is correct |
28 |
Correct |
514 ms |
61656 KB |
Output is correct |
29 |
Correct |
500 ms |
60944 KB |
Output is correct |
30 |
Correct |
486 ms |
59164 KB |
Output is correct |
31 |
Correct |
537 ms |
64228 KB |
Output is correct |
32 |
Correct |
587 ms |
69044 KB |
Output is correct |
33 |
Correct |
543 ms |
69712 KB |
Output is correct |
34 |
Correct |
535 ms |
69828 KB |
Output is correct |
35 |
Correct |
5 ms |
34652 KB |
Output is correct |
36 |
Correct |
228 ms |
44868 KB |
Output is correct |
37 |
Correct |
800 ms |
73632 KB |
Output is correct |
38 |
Correct |
813 ms |
73668 KB |
Output is correct |
39 |
Correct |
783 ms |
71800 KB |
Output is correct |
40 |
Correct |
349 ms |
54400 KB |
Output is correct |
41 |
Correct |
167 ms |
45204 KB |
Output is correct |
42 |
Correct |
36 ms |
36940 KB |
Output is correct |
43 |
Correct |
827 ms |
72384 KB |
Output is correct |
44 |
Correct |
865 ms |
74196 KB |
Output is correct |
45 |
Correct |
628 ms |
65848 KB |
Output is correct |
46 |
Correct |
639 ms |
78876 KB |
Output is correct |
47 |
Correct |
619 ms |
70356 KB |
Output is correct |
48 |
Correct |
603 ms |
79284 KB |
Output is correct |
49 |
Correct |
619 ms |
80212 KB |
Output is correct |
50 |
Correct |
623 ms |
68424 KB |
Output is correct |
51 |
Correct |
20 ms |
35580 KB |
Output is correct |
52 |
Correct |
19 ms |
35408 KB |
Output is correct |
53 |
Correct |
19 ms |
35544 KB |
Output is correct |
54 |
Correct |
22 ms |
35672 KB |
Output is correct |
55 |
Correct |
21 ms |
35736 KB |
Output is correct |
56 |
Correct |
21 ms |
35836 KB |
Output is correct |
57 |
Correct |
169 ms |
43144 KB |
Output is correct |
58 |
Correct |
175 ms |
43064 KB |
Output is correct |
59 |
Correct |
169 ms |
42544 KB |
Output is correct |
60 |
Correct |
187 ms |
45252 KB |
Output is correct |
61 |
Correct |
197 ms |
47848 KB |
Output is correct |
62 |
Correct |
205 ms |
47708 KB |
Output is correct |
63 |
Correct |
216 ms |
47816 KB |
Output is correct |
64 |
Correct |
208 ms |
47860 KB |
Output is correct |
65 |
Correct |
218 ms |
48080 KB |
Output is correct |
66 |
Correct |
142 ms |
46416 KB |
Output is correct |
67 |
Correct |
174 ms |
49340 KB |
Output is correct |
68 |
Correct |
162 ms |
50096 KB |
Output is correct |
69 |
Correct |
187 ms |
50028 KB |
Output is correct |
70 |
Correct |
157 ms |
49572 KB |
Output is correct |
71 |
Correct |
174 ms |
49828 KB |
Output is correct |
72 |
Correct |
153 ms |
49712 KB |
Output is correct |
73 |
Correct |
151 ms |
50112 KB |
Output is correct |
74 |
Correct |
175 ms |
50080 KB |
Output is correct |
75 |
Correct |
631 ms |
67864 KB |
Output is correct |
76 |
Correct |
543 ms |
69244 KB |
Output is correct |
77 |
Correct |
618 ms |
70684 KB |
Output is correct |
78 |
Correct |
660 ms |
70812 KB |
Output is correct |
79 |
Correct |
584 ms |
67144 KB |
Output is correct |
80 |
Correct |
608 ms |
69236 KB |
Output is correct |
81 |
Correct |
817 ms |
73528 KB |
Output is correct |
82 |
Correct |
807 ms |
73912 KB |
Output is correct |
83 |
Correct |
785 ms |
73632 KB |
Output is correct |
84 |
Correct |
769 ms |
72840 KB |
Output is correct |
85 |
Correct |
829 ms |
73588 KB |
Output is correct |
86 |
Correct |
828 ms |
74012 KB |
Output is correct |
87 |
Correct |
884 ms |
74128 KB |
Output is correct |
88 |
Correct |
920 ms |
80096 KB |
Output is correct |
89 |
Correct |
854 ms |
78416 KB |
Output is correct |
90 |
Correct |
894 ms |
79896 KB |
Output is correct |
91 |
Correct |
868 ms |
79928 KB |
Output is correct |
92 |
Correct |
819 ms |
79396 KB |
Output is correct |
93 |
Correct |
697 ms |
80064 KB |
Output is correct |
94 |
Correct |
780 ms |
68404 KB |
Output is correct |
95 |
Correct |
701 ms |
80668 KB |
Output is correct |
96 |
Correct |
730 ms |
79432 KB |
Output is correct |
97 |
Correct |
973 ms |
66268 KB |
Output is correct |
98 |
Correct |
706 ms |
75704 KB |
Output is correct |
99 |
Correct |
773 ms |
80380 KB |
Output is correct |
100 |
Correct |
650 ms |
80544 KB |
Output is correct |
101 |
Correct |
718 ms |
72632 KB |
Output is correct |
102 |
Correct |
707 ms |
79120 KB |
Output is correct |
103 |
Correct |
996 ms |
66284 KB |
Output is correct |
104 |
Correct |
703 ms |
78924 KB |
Output is correct |
105 |
Correct |
561 ms |
69712 KB |
Output is correct |
106 |
Correct |
579 ms |
77624 KB |
Output is correct |
107 |
Correct |
556 ms |
77292 KB |
Output is correct |
108 |
Correct |
540 ms |
77568 KB |
Output is correct |
109 |
Correct |
574 ms |
77148 KB |
Output is correct |
110 |
Correct |
554 ms |
77184 KB |
Output is correct |
111 |
Correct |
556 ms |
77768 KB |
Output is correct |
112 |
Correct |
548 ms |
77236 KB |
Output is correct |
113 |
Correct |
534 ms |
77384 KB |
Output is correct |
114 |
Correct |
579 ms |
77240 KB |
Output is correct |
115 |
Correct |
540 ms |
77216 KB |
Output is correct |
116 |
Correct |
576 ms |
80496 KB |
Output is correct |