#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int long long
const int inf = 1e9 + 7;
struct circle {
int x, y, r, index;
};
vector <vector <circle> > build_matrix(vector <circle> circles, int sz) {
sort(circles.begin(), circles.end(), [](const circle &a, const circle &b) {
return a.x < b.x;
});
int n = (int) circles.size();
vector <circle> cur;
vector <vector <circle> > res;
for (int i = 0; i < n; i++) {
if (cur.empty() || cur.back().x / sz == circles[i].x / sz) {
cur.push_back(circles[i]);
} else {
res.push_back(cur);
cur = {circles[i]};
}
}
if (!cur.empty()) {
res.push_back(cur);
}
for (auto &to : res) {
sort(to.begin(), to.end(), [](const circle &a, const circle &b) {
return a.y < b.y;
});
}
return res;
}
bool query(const circle &a, const circle &b) {
long long distance = (a.x - b.x) * 1ll * (a.x - b.x) + (a.y - b.y) * 1ll * (a.y - b.y);
return distance <= (a.r + b.r) * 1ll * (a.r + b.r);
}
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector <circle> c;
set <pair <int, int>, greater <pair <int, int> > > rads;
for (int i = 0; i < n; i++) {
int x, y, r;
cin >> x >> y >> r;
x += inf;
y += inf;
c.push_back({x, y, r, i});
rads.insert({r, -i});
}
int sz = rads.begin()->first;
auto result = build_matrix(c, sz);
vector <int> rem(n, -1);
for (int i = 0; i < n; i++) {
auto it = rads.begin();
int index = -it->second;
int cur_rad = it->first;
rads.erase(it);
if (rem[index] != -1) {
continue;
}
rem[index] = index;
if (cur_rad <= sz / 2) {
sz = cur_rad;
result = build_matrix(c, sz);
}
int xl = n, xr = -1;
{
int starting_point = (c[index].x / sz) * sz;
int prev_point = starting_point - 2 * sz;
int l = 0, r = (int) result.size() - 1;
int res = n;
while (l <= r) {
int mid = (l + r) / 2;
if (result[mid][0].x >= prev_point) {
r = mid - 1;
res = mid;
} else {
l = mid + 1;
}
}
xl = res;
}
{
int starting_point = (c[index].x / sz) * sz;
int next_point = starting_point + 3 * sz;
int l = 0, r = (int) result.size() - 1;
int res = n;
while (l <= r) {
int mid = (l + r) / 2;
if (result[mid][0].x >= next_point) {
r = mid - 1;
res = mid;
} else {
l = mid + 1;
}
}
xr = res;
xr--;
}
xl = max(0ll, xl);
xr = min((int) result.size() - 1, xr);
for (int j = xl; j <= xr; j++) {
int yl = n, yr = -1;
{
int starting_point = (c[index].y / sz) * sz;
int prev_point = starting_point - 2 * sz;
int l = 0, r = (int) result[j].size() - 1;
int res = n;
while (l <= r) {
int mid = (l + r) / 2;
if (result[j][mid].y >= prev_point) {
r = mid - 1;
res = mid;
} else {
l = mid + 1;
}
}
yl = res;
}
{
int starting_point = (c[index].y / sz) * sz;
int next_point = starting_point + 3 * sz;
int l = 0, r = (int) result[j].size() - 1;
int res = n;
while (l <= r) {
int mid = (l + r) / 2;
if (result[j][mid].y >= next_point) {
r = mid - 1;
res = mid;
} else {
l = mid + 1;
}
}
yr = res;
yr--;
}
yl = max(0ll, yl);
yr = min((int) result[j].size() - 1, yr);
for (int k = yl; k <= yr; k++) {
if (rem[result[j][k].index] == -1 && query(c[index], result[j][k])) {
rem[result[j][k].index] = index;
}
}
}
}
for (int i = 0; i < n; i++) {
cout << rem[i] + 1 << ' ';
}
cout << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
284 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
4 ms |
1324 KB |
Output is correct |
20 |
Correct |
3 ms |
1364 KB |
Output is correct |
21 |
Correct |
5 ms |
1364 KB |
Output is correct |
22 |
Correct |
11 ms |
1772 KB |
Output is correct |
23 |
Correct |
10 ms |
1784 KB |
Output is correct |
24 |
Correct |
11 ms |
1692 KB |
Output is correct |
25 |
Correct |
10 ms |
1632 KB |
Output is correct |
26 |
Correct |
11 ms |
1744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
323 ms |
63212 KB |
Output is correct |
2 |
Correct |
318 ms |
61688 KB |
Output is correct |
3 |
Correct |
271 ms |
52496 KB |
Output is correct |
4 |
Correct |
314 ms |
62044 KB |
Output is correct |
5 |
Correct |
440 ms |
69100 KB |
Output is correct |
6 |
Correct |
726 ms |
92896 KB |
Output is correct |
7 |
Correct |
621 ms |
81212 KB |
Output is correct |
8 |
Correct |
589 ms |
82460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
366 ms |
28508 KB |
Output is correct |
3 |
Correct |
1468 ms |
100448 KB |
Output is correct |
4 |
Correct |
1482 ms |
99684 KB |
Output is correct |
5 |
Correct |
1278 ms |
105756 KB |
Output is correct |
6 |
Correct |
315 ms |
43136 KB |
Output is correct |
7 |
Correct |
147 ms |
22924 KB |
Output is correct |
8 |
Correct |
23 ms |
5172 KB |
Output is correct |
9 |
Correct |
1383 ms |
108304 KB |
Output is correct |
10 |
Correct |
677 ms |
72660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
348 ms |
50328 KB |
Output is correct |
2 |
Correct |
355 ms |
70424 KB |
Output is correct |
3 |
Correct |
218 ms |
55764 KB |
Output is correct |
4 |
Correct |
360 ms |
70936 KB |
Output is correct |
5 |
Correct |
374 ms |
71096 KB |
Output is correct |
6 |
Correct |
208 ms |
55952 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
284 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
4 ms |
1324 KB |
Output is correct |
20 |
Correct |
3 ms |
1364 KB |
Output is correct |
21 |
Correct |
5 ms |
1364 KB |
Output is correct |
22 |
Correct |
11 ms |
1772 KB |
Output is correct |
23 |
Correct |
10 ms |
1784 KB |
Output is correct |
24 |
Correct |
11 ms |
1692 KB |
Output is correct |
25 |
Correct |
10 ms |
1632 KB |
Output is correct |
26 |
Correct |
11 ms |
1744 KB |
Output is correct |
27 |
Correct |
12 ms |
2448 KB |
Output is correct |
28 |
Correct |
7 ms |
2124 KB |
Output is correct |
29 |
Correct |
7 ms |
2140 KB |
Output is correct |
30 |
Correct |
23 ms |
2992 KB |
Output is correct |
31 |
Correct |
22 ms |
3196 KB |
Output is correct |
32 |
Correct |
27 ms |
3136 KB |
Output is correct |
33 |
Correct |
81 ms |
19252 KB |
Output is correct |
34 |
Correct |
79 ms |
18096 KB |
Output is correct |
35 |
Correct |
210 ms |
20852 KB |
Output is correct |
36 |
Correct |
349 ms |
29352 KB |
Output is correct |
37 |
Correct |
338 ms |
29032 KB |
Output is correct |
38 |
Correct |
349 ms |
29464 KB |
Output is correct |
39 |
Correct |
290 ms |
28260 KB |
Output is correct |
40 |
Correct |
302 ms |
28156 KB |
Output is correct |
41 |
Correct |
282 ms |
25600 KB |
Output is correct |
42 |
Correct |
69 ms |
15896 KB |
Output is correct |
43 |
Correct |
96 ms |
19760 KB |
Output is correct |
44 |
Correct |
94 ms |
22296 KB |
Output is correct |
45 |
Correct |
93 ms |
22328 KB |
Output is correct |
46 |
Correct |
93 ms |
22376 KB |
Output is correct |
47 |
Correct |
94 ms |
22348 KB |
Output is correct |
48 |
Correct |
94 ms |
22308 KB |
Output is correct |
49 |
Correct |
101 ms |
22448 KB |
Output is correct |
50 |
Correct |
93 ms |
22340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
284 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
468 KB |
Output is correct |
17 |
Correct |
1 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
4 ms |
1324 KB |
Output is correct |
20 |
Correct |
3 ms |
1364 KB |
Output is correct |
21 |
Correct |
5 ms |
1364 KB |
Output is correct |
22 |
Correct |
11 ms |
1772 KB |
Output is correct |
23 |
Correct |
10 ms |
1784 KB |
Output is correct |
24 |
Correct |
11 ms |
1692 KB |
Output is correct |
25 |
Correct |
10 ms |
1632 KB |
Output is correct |
26 |
Correct |
11 ms |
1744 KB |
Output is correct |
27 |
Correct |
323 ms |
63212 KB |
Output is correct |
28 |
Correct |
318 ms |
61688 KB |
Output is correct |
29 |
Correct |
271 ms |
52496 KB |
Output is correct |
30 |
Correct |
314 ms |
62044 KB |
Output is correct |
31 |
Correct |
440 ms |
69100 KB |
Output is correct |
32 |
Correct |
726 ms |
92896 KB |
Output is correct |
33 |
Correct |
621 ms |
81212 KB |
Output is correct |
34 |
Correct |
589 ms |
82460 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
366 ms |
28508 KB |
Output is correct |
37 |
Correct |
1468 ms |
100448 KB |
Output is correct |
38 |
Correct |
1482 ms |
99684 KB |
Output is correct |
39 |
Correct |
1278 ms |
105756 KB |
Output is correct |
40 |
Correct |
315 ms |
43136 KB |
Output is correct |
41 |
Correct |
147 ms |
22924 KB |
Output is correct |
42 |
Correct |
23 ms |
5172 KB |
Output is correct |
43 |
Correct |
1383 ms |
108304 KB |
Output is correct |
44 |
Correct |
677 ms |
72660 KB |
Output is correct |
45 |
Correct |
348 ms |
50328 KB |
Output is correct |
46 |
Correct |
355 ms |
70424 KB |
Output is correct |
47 |
Correct |
218 ms |
55764 KB |
Output is correct |
48 |
Correct |
360 ms |
70936 KB |
Output is correct |
49 |
Correct |
374 ms |
71096 KB |
Output is correct |
50 |
Correct |
208 ms |
55952 KB |
Output is correct |
51 |
Correct |
12 ms |
2448 KB |
Output is correct |
52 |
Correct |
7 ms |
2124 KB |
Output is correct |
53 |
Correct |
7 ms |
2140 KB |
Output is correct |
54 |
Correct |
23 ms |
2992 KB |
Output is correct |
55 |
Correct |
22 ms |
3196 KB |
Output is correct |
56 |
Correct |
27 ms |
3136 KB |
Output is correct |
57 |
Correct |
81 ms |
19252 KB |
Output is correct |
58 |
Correct |
79 ms |
18096 KB |
Output is correct |
59 |
Correct |
210 ms |
20852 KB |
Output is correct |
60 |
Correct |
349 ms |
29352 KB |
Output is correct |
61 |
Correct |
338 ms |
29032 KB |
Output is correct |
62 |
Correct |
349 ms |
29464 KB |
Output is correct |
63 |
Correct |
290 ms |
28260 KB |
Output is correct |
64 |
Correct |
302 ms |
28156 KB |
Output is correct |
65 |
Correct |
282 ms |
25600 KB |
Output is correct |
66 |
Correct |
69 ms |
15896 KB |
Output is correct |
67 |
Correct |
96 ms |
19760 KB |
Output is correct |
68 |
Correct |
94 ms |
22296 KB |
Output is correct |
69 |
Correct |
93 ms |
22328 KB |
Output is correct |
70 |
Correct |
93 ms |
22376 KB |
Output is correct |
71 |
Correct |
94 ms |
22348 KB |
Output is correct |
72 |
Correct |
94 ms |
22308 KB |
Output is correct |
73 |
Correct |
101 ms |
22448 KB |
Output is correct |
74 |
Correct |
93 ms |
22340 KB |
Output is correct |
75 |
Correct |
835 ms |
73708 KB |
Output is correct |
76 |
Correct |
401 ms |
70188 KB |
Output is correct |
77 |
Correct |
312 ms |
71448 KB |
Output is correct |
78 |
Correct |
302 ms |
71508 KB |
Output is correct |
79 |
Correct |
819 ms |
70372 KB |
Output is correct |
80 |
Correct |
334 ms |
64556 KB |
Output is correct |
81 |
Correct |
1390 ms |
99816 KB |
Output is correct |
82 |
Correct |
1390 ms |
97804 KB |
Output is correct |
83 |
Correct |
1376 ms |
110792 KB |
Output is correct |
84 |
Correct |
1261 ms |
99860 KB |
Output is correct |
85 |
Correct |
1390 ms |
103300 KB |
Output is correct |
86 |
Correct |
1380 ms |
97984 KB |
Output is correct |
87 |
Correct |
1211 ms |
89728 KB |
Output is correct |
88 |
Correct |
987 ms |
81896 KB |
Output is correct |
89 |
Correct |
956 ms |
81828 KB |
Output is correct |
90 |
Correct |
980 ms |
81892 KB |
Output is correct |
91 |
Correct |
950 ms |
81820 KB |
Output is correct |
92 |
Correct |
981 ms |
81752 KB |
Output is correct |
93 |
Correct |
704 ms |
112976 KB |
Output is correct |
94 |
Correct |
649 ms |
76944 KB |
Output is correct |
95 |
Correct |
696 ms |
89340 KB |
Output is correct |
96 |
Correct |
793 ms |
95572 KB |
Output is correct |
97 |
Correct |
657 ms |
67932 KB |
Output is correct |
98 |
Correct |
753 ms |
92784 KB |
Output is correct |
99 |
Correct |
813 ms |
106640 KB |
Output is correct |
100 |
Correct |
544 ms |
88008 KB |
Output is correct |
101 |
Correct |
763 ms |
83128 KB |
Output is correct |
102 |
Correct |
798 ms |
105800 KB |
Output is correct |
103 |
Correct |
800 ms |
70596 KB |
Output is correct |
104 |
Correct |
801 ms |
105856 KB |
Output is correct |
105 |
Correct |
225 ms |
52120 KB |
Output is correct |
106 |
Correct |
349 ms |
64148 KB |
Output is correct |
107 |
Correct |
337 ms |
64164 KB |
Output is correct |
108 |
Correct |
349 ms |
64108 KB |
Output is correct |
109 |
Correct |
332 ms |
64108 KB |
Output is correct |
110 |
Correct |
357 ms |
64032 KB |
Output is correct |
111 |
Correct |
343 ms |
64196 KB |
Output is correct |
112 |
Correct |
342 ms |
64064 KB |
Output is correct |
113 |
Correct |
336 ms |
64132 KB |
Output is correct |
114 |
Correct |
352 ms |
64196 KB |
Output is correct |
115 |
Correct |
350 ms |
64132 KB |
Output is correct |
116 |
Correct |
360 ms |
71264 KB |
Output is correct |