#include <bits/stdc++.h>
using std::array;
using std::pair;
using std::tuple;
using std::vector;
constexpr int MAX = 1000000000;
constexpr int LOG = 31;
int main() {
int N;
std::cin >> N;
vector<int> X(N), Y(N), R(N);
for (int i = 0; i < N; ++i) {
std::cin >> X[i] >> Y[i] >> R[i];
X[i] += MAX;
}
int logR = LOG;
vector<int> xs = {0};
vector<vector<int>> pts = {{}};
for (int i = 0; i < N; ++i) {
pts[0].push_back(i);
}
std::sort(pts[0].begin(), pts[0].end(),
[&](const int i, const int j) { return Y[i] < Y[j]; });
vector<int> order(N), ans(N, -1);
std::iota(order.begin(), order.end(), 0);
std::sort(order.begin(), order.end(),
[&](const int i, const int j) { return R[i] != R[j] ? R[i] > R[j] : i < j; });
for (const int i : order) {
if (ans[i] != -1) {
continue;
}
while (R[i] <= (1 << (logR - 1))) {
logR -= 1;
vector<int> next_xs;
vector<vector<int>> next_pts;
for (int i = 0; i < (int)xs.size(); ++i) {
array<vector<int>, 2> arr;
for (const int j : pts[i]) {
arr[X[j] >> logR & 1].push_back(j);
}
for (int k = 0; k < 2; ++k) {
if (!arr[k].empty()) {
next_xs.push_back(xs[i] * 2 + k);
next_pts.push_back(std::move(arr[k]));
}
}
}
xs = std::move(next_xs);
pts = std::move(next_pts);
}
ans[i] = i;
int xi = std::lower_bound(xs.begin(), xs.end(), (X[i] >> logR) - 2) - xs.begin();
while (xi < (int)xs.size() && xs[xi] <= (X[i] >> logR) + 2) {
const auto& ys = pts[xi];
int yi = std::partition_point(ys.begin(), ys.end(),
[&](const int j) { return Y[i] - Y[j] > 2 * R[i]; }) -
ys.begin();
while (yi < (int)ys.size() && Y[ys[yi]] - Y[i] <= 2 * R[i]) {
const int j = ys[yi];
if (ans[j] == -1) {
const long long dx = X[i] - X[j];
const long long dy = Y[i] - Y[j];
const long long r = R[i] + R[j];
if (dx * dx + dy * dy <= r * r) {
ans[j] = i;
}
}
yi += 1;
}
xi += 1;
}
}
for (int i = 0; i < N; ++i) {
std::cout << ans[i] + 1 << " \n"[i + 1 == N];
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
304 KB |
Output is correct |
3 |
Correct |
1 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 |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
304 KB |
Output is correct |
9 |
Correct |
1 ms |
300 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
300 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
3 ms |
340 KB |
Output is correct |
19 |
Correct |
8 ms |
644 KB |
Output is correct |
20 |
Correct |
8 ms |
640 KB |
Output is correct |
21 |
Correct |
8 ms |
596 KB |
Output is correct |
22 |
Correct |
14 ms |
1500 KB |
Output is correct |
23 |
Correct |
13 ms |
1308 KB |
Output is correct |
24 |
Correct |
15 ms |
1424 KB |
Output is correct |
25 |
Correct |
16 ms |
1500 KB |
Output is correct |
26 |
Correct |
14 ms |
1404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
358 ms |
12416 KB |
Output is correct |
2 |
Correct |
357 ms |
12880 KB |
Output is correct |
3 |
Correct |
354 ms |
12708 KB |
Output is correct |
4 |
Correct |
353 ms |
11824 KB |
Output is correct |
5 |
Correct |
477 ms |
33548 KB |
Output is correct |
6 |
Correct |
657 ms |
61980 KB |
Output is correct |
7 |
Correct |
590 ms |
55720 KB |
Output is correct |
8 |
Correct |
622 ms |
57616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
395 ms |
23056 KB |
Output is correct |
3 |
Correct |
1171 ms |
70268 KB |
Output is correct |
4 |
Correct |
1073 ms |
70752 KB |
Output is correct |
5 |
Correct |
1008 ms |
69764 KB |
Output is correct |
6 |
Correct |
346 ms |
20284 KB |
Output is correct |
7 |
Correct |
173 ms |
10392 KB |
Output is correct |
8 |
Correct |
35 ms |
2940 KB |
Output is correct |
9 |
Correct |
1040 ms |
74612 KB |
Output is correct |
10 |
Correct |
630 ms |
23852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
611 ms |
15336 KB |
Output is correct |
2 |
Correct |
824 ms |
67116 KB |
Output is correct |
3 |
Correct |
462 ms |
20228 KB |
Output is correct |
4 |
Correct |
695 ms |
54988 KB |
Output is correct |
5 |
Correct |
747 ms |
60456 KB |
Output is correct |
6 |
Correct |
448 ms |
21300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
304 KB |
Output is correct |
3 |
Correct |
1 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 |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
304 KB |
Output is correct |
9 |
Correct |
1 ms |
300 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
300 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
3 ms |
340 KB |
Output is correct |
19 |
Correct |
8 ms |
644 KB |
Output is correct |
20 |
Correct |
8 ms |
640 KB |
Output is correct |
21 |
Correct |
8 ms |
596 KB |
Output is correct |
22 |
Correct |
14 ms |
1500 KB |
Output is correct |
23 |
Correct |
13 ms |
1308 KB |
Output is correct |
24 |
Correct |
15 ms |
1424 KB |
Output is correct |
25 |
Correct |
16 ms |
1500 KB |
Output is correct |
26 |
Correct |
14 ms |
1404 KB |
Output is correct |
27 |
Correct |
19 ms |
912 KB |
Output is correct |
28 |
Correct |
16 ms |
968 KB |
Output is correct |
29 |
Correct |
17 ms |
968 KB |
Output is correct |
30 |
Correct |
28 ms |
2596 KB |
Output is correct |
31 |
Correct |
25 ms |
2620 KB |
Output is correct |
32 |
Correct |
28 ms |
2484 KB |
Output is correct |
33 |
Correct |
151 ms |
6568 KB |
Output is correct |
34 |
Correct |
149 ms |
6436 KB |
Output is correct |
35 |
Correct |
184 ms |
9892 KB |
Output is correct |
36 |
Correct |
301 ms |
20304 KB |
Output is correct |
37 |
Correct |
303 ms |
21312 KB |
Output is correct |
38 |
Correct |
301 ms |
20340 KB |
Output is correct |
39 |
Correct |
194 ms |
5608 KB |
Output is correct |
40 |
Correct |
187 ms |
5520 KB |
Output is correct |
41 |
Correct |
195 ms |
5544 KB |
Output is correct |
42 |
Correct |
134 ms |
5564 KB |
Output is correct |
43 |
Correct |
223 ms |
19344 KB |
Output is correct |
44 |
Correct |
219 ms |
19336 KB |
Output is correct |
45 |
Correct |
224 ms |
19332 KB |
Output is correct |
46 |
Correct |
221 ms |
19276 KB |
Output is correct |
47 |
Correct |
219 ms |
19284 KB |
Output is correct |
48 |
Correct |
213 ms |
19348 KB |
Output is correct |
49 |
Correct |
208 ms |
19288 KB |
Output is correct |
50 |
Correct |
210 ms |
19300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
304 KB |
Output is correct |
3 |
Correct |
1 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 |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
304 KB |
Output is correct |
9 |
Correct |
1 ms |
300 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
300 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
2 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
3 ms |
340 KB |
Output is correct |
19 |
Correct |
8 ms |
644 KB |
Output is correct |
20 |
Correct |
8 ms |
640 KB |
Output is correct |
21 |
Correct |
8 ms |
596 KB |
Output is correct |
22 |
Correct |
14 ms |
1500 KB |
Output is correct |
23 |
Correct |
13 ms |
1308 KB |
Output is correct |
24 |
Correct |
15 ms |
1424 KB |
Output is correct |
25 |
Correct |
16 ms |
1500 KB |
Output is correct |
26 |
Correct |
14 ms |
1404 KB |
Output is correct |
27 |
Correct |
358 ms |
12416 KB |
Output is correct |
28 |
Correct |
357 ms |
12880 KB |
Output is correct |
29 |
Correct |
354 ms |
12708 KB |
Output is correct |
30 |
Correct |
353 ms |
11824 KB |
Output is correct |
31 |
Correct |
477 ms |
33548 KB |
Output is correct |
32 |
Correct |
657 ms |
61980 KB |
Output is correct |
33 |
Correct |
590 ms |
55720 KB |
Output is correct |
34 |
Correct |
622 ms |
57616 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
395 ms |
23056 KB |
Output is correct |
37 |
Correct |
1171 ms |
70268 KB |
Output is correct |
38 |
Correct |
1073 ms |
70752 KB |
Output is correct |
39 |
Correct |
1008 ms |
69764 KB |
Output is correct |
40 |
Correct |
346 ms |
20284 KB |
Output is correct |
41 |
Correct |
173 ms |
10392 KB |
Output is correct |
42 |
Correct |
35 ms |
2940 KB |
Output is correct |
43 |
Correct |
1040 ms |
74612 KB |
Output is correct |
44 |
Correct |
630 ms |
23852 KB |
Output is correct |
45 |
Correct |
611 ms |
15336 KB |
Output is correct |
46 |
Correct |
824 ms |
67116 KB |
Output is correct |
47 |
Correct |
462 ms |
20228 KB |
Output is correct |
48 |
Correct |
695 ms |
54988 KB |
Output is correct |
49 |
Correct |
747 ms |
60456 KB |
Output is correct |
50 |
Correct |
448 ms |
21300 KB |
Output is correct |
51 |
Correct |
19 ms |
912 KB |
Output is correct |
52 |
Correct |
16 ms |
968 KB |
Output is correct |
53 |
Correct |
17 ms |
968 KB |
Output is correct |
54 |
Correct |
28 ms |
2596 KB |
Output is correct |
55 |
Correct |
25 ms |
2620 KB |
Output is correct |
56 |
Correct |
28 ms |
2484 KB |
Output is correct |
57 |
Correct |
151 ms |
6568 KB |
Output is correct |
58 |
Correct |
149 ms |
6436 KB |
Output is correct |
59 |
Correct |
184 ms |
9892 KB |
Output is correct |
60 |
Correct |
301 ms |
20304 KB |
Output is correct |
61 |
Correct |
303 ms |
21312 KB |
Output is correct |
62 |
Correct |
301 ms |
20340 KB |
Output is correct |
63 |
Correct |
194 ms |
5608 KB |
Output is correct |
64 |
Correct |
187 ms |
5520 KB |
Output is correct |
65 |
Correct |
195 ms |
5544 KB |
Output is correct |
66 |
Correct |
134 ms |
5564 KB |
Output is correct |
67 |
Correct |
223 ms |
19344 KB |
Output is correct |
68 |
Correct |
219 ms |
19336 KB |
Output is correct |
69 |
Correct |
224 ms |
19332 KB |
Output is correct |
70 |
Correct |
221 ms |
19276 KB |
Output is correct |
71 |
Correct |
219 ms |
19284 KB |
Output is correct |
72 |
Correct |
213 ms |
19348 KB |
Output is correct |
73 |
Correct |
208 ms |
19288 KB |
Output is correct |
74 |
Correct |
210 ms |
19300 KB |
Output is correct |
75 |
Correct |
553 ms |
22336 KB |
Output is correct |
76 |
Correct |
477 ms |
21216 KB |
Output is correct |
77 |
Correct |
463 ms |
20792 KB |
Output is correct |
78 |
Correct |
437 ms |
20148 KB |
Output is correct |
79 |
Correct |
615 ms |
36988 KB |
Output is correct |
80 |
Correct |
452 ms |
20276 KB |
Output is correct |
81 |
Correct |
1016 ms |
72888 KB |
Output is correct |
82 |
Correct |
1016 ms |
71496 KB |
Output is correct |
83 |
Correct |
1014 ms |
77796 KB |
Output is correct |
84 |
Correct |
1010 ms |
70180 KB |
Output is correct |
85 |
Correct |
1012 ms |
67136 KB |
Output is correct |
86 |
Correct |
1046 ms |
75452 KB |
Output is correct |
87 |
Correct |
997 ms |
66220 KB |
Output is correct |
88 |
Correct |
658 ms |
17676 KB |
Output is correct |
89 |
Correct |
702 ms |
17564 KB |
Output is correct |
90 |
Correct |
672 ms |
17656 KB |
Output is correct |
91 |
Correct |
670 ms |
17648 KB |
Output is correct |
92 |
Correct |
684 ms |
17652 KB |
Output is correct |
93 |
Correct |
870 ms |
71872 KB |
Output is correct |
94 |
Correct |
731 ms |
20916 KB |
Output is correct |
95 |
Correct |
882 ms |
73680 KB |
Output is correct |
96 |
Correct |
861 ms |
71892 KB |
Output is correct |
97 |
Correct |
797 ms |
20764 KB |
Output is correct |
98 |
Correct |
774 ms |
65316 KB |
Output is correct |
99 |
Correct |
936 ms |
65576 KB |
Output is correct |
100 |
Correct |
917 ms |
70172 KB |
Output is correct |
101 |
Correct |
790 ms |
57812 KB |
Output is correct |
102 |
Correct |
866 ms |
70308 KB |
Output is correct |
103 |
Correct |
815 ms |
19692 KB |
Output is correct |
104 |
Correct |
917 ms |
70316 KB |
Output is correct |
105 |
Correct |
453 ms |
18072 KB |
Output is correct |
106 |
Correct |
649 ms |
40528 KB |
Output is correct |
107 |
Correct |
664 ms |
40528 KB |
Output is correct |
108 |
Correct |
654 ms |
39752 KB |
Output is correct |
109 |
Correct |
653 ms |
39696 KB |
Output is correct |
110 |
Correct |
651 ms |
39668 KB |
Output is correct |
111 |
Correct |
627 ms |
39728 KB |
Output is correct |
112 |
Correct |
652 ms |
39640 KB |
Output is correct |
113 |
Correct |
655 ms |
39556 KB |
Output is correct |
114 |
Correct |
664 ms |
39556 KB |
Output is correct |
115 |
Correct |
656 ms |
39684 KB |
Output is correct |
116 |
Correct |
689 ms |
55200 KB |
Output is correct |