#include <bits/stdc++.h>
#define nl '\n'
const int inf = 1e9;
signed main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int n;
std::cin >> n;
std::vector<int> ans(n, -1);
std::vector<std::array<int, 3>> c(n);
for (int i = 0; i < n; i++) {
std::cin >> c[i][1] >> c[i][2] >> c[i][0];
c[i][1] += inf;
c[i][2] += inf;
}
std::vector<int> ord(n);
std::iota(ord.begin(), ord.end(), 0);
std::sort(ord.begin(), ord.end(), [&](int i, int j) {
if (c[i][0] == c[j][0]) return i < j;
return c[i][0] > c[j][0];
});
int block = c[ord[0]][0];
std::vector<std::pair<int, int>> xy;
std::vector<std::vector<int>> at(n);
auto get_id = [&](std::pair<int, int> p) {
int i = std::lower_bound(xy.begin(), xy.end(), p) - xy.begin();
if (i == (int) xy.size() || xy[i] != p) return -1;
return i;
};
auto sqr = [&](int x) -> int64_t {
return (int64_t) x * x;
};
auto intersect = [&](int i, int j) {
auto dist = sqr(c[i][1] - c[j][1]) + sqr(c[i][2] - c[j][2]);
auto srad = sqr(c[i][0] + c[j][0]);
return dist <= srad;
};
auto rescale = [&]() {
xy.clear();
for (int i = 0; i < n; i++) {
at[i].clear();
}
for (int i = 0; i < n; i++) {
if (ans[i] != -1) continue;
xy.emplace_back(c[i][1] / block, c[i][2] / block);
}
std::sort(xy.begin(), xy.end());
xy.erase(std::unique(xy.begin(), xy.end()), xy.end());
for (int i = 0; i < n; i++) {
if (ans[i] != -1) continue;
at[get_id({c[i][1] / block, c[i][2] / block})].push_back(i);
}
};
rescale();
for (int id : ord) {
if (ans[id] != -1) continue;
if (c[id][0] * 2 < block) {
block = c[id][0];
rescale();
}
ans[id] = id;
int x = c[id][1] / block;
int y = c[id][2] / block;
for (int i = x - 2; i <= x + 2; i++) {
for (int j = y - 2; j <= y + 2; j++) {
int idx = get_id({i, j});
if (idx == -1) continue;
std::vector<int> new_at;
for (int ii : at[idx]) {
if (intersect(id, ii)) {
ans[ii] = id;
} else {
new_at.push_back(ii);
}
}
std::swap(at[idx], new_at);
}
}
}
for (int i = 0; i < n; i++) {
std::cout << ++ans[i] << " ";
}
std::cout << nl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
356 KB |
Output is correct |
5 |
Correct |
0 ms |
608 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
356 KB |
Output is correct |
8 |
Correct |
0 ms |
356 KB |
Output is correct |
9 |
Correct |
0 ms |
356 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
588 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
356 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
356 KB |
Output is correct |
17 |
Correct |
1 ms |
356 KB |
Output is correct |
18 |
Correct |
1 ms |
380 KB |
Output is correct |
19 |
Correct |
2 ms |
952 KB |
Output is correct |
20 |
Correct |
2 ms |
868 KB |
Output is correct |
21 |
Correct |
3 ms |
868 KB |
Output is correct |
22 |
Correct |
11 ms |
860 KB |
Output is correct |
23 |
Correct |
12 ms |
1004 KB |
Output is correct |
24 |
Correct |
11 ms |
940 KB |
Output is correct |
25 |
Correct |
10 ms |
1012 KB |
Output is correct |
26 |
Correct |
10 ms |
864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
132 ms |
27904 KB |
Output is correct |
2 |
Correct |
134 ms |
26308 KB |
Output is correct |
3 |
Correct |
146 ms |
27360 KB |
Output is correct |
4 |
Correct |
135 ms |
28040 KB |
Output is correct |
5 |
Correct |
180 ms |
24516 KB |
Output is correct |
6 |
Correct |
404 ms |
28096 KB |
Output is correct |
7 |
Correct |
223 ms |
25140 KB |
Output is correct |
8 |
Correct |
241 ms |
26632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
283 ms |
11960 KB |
Output is correct |
3 |
Correct |
982 ms |
35016 KB |
Output is correct |
4 |
Correct |
934 ms |
36192 KB |
Output is correct |
5 |
Correct |
834 ms |
33916 KB |
Output is correct |
6 |
Correct |
325 ms |
17100 KB |
Output is correct |
7 |
Correct |
147 ms |
9144 KB |
Output is correct |
8 |
Correct |
24 ms |
2260 KB |
Output is correct |
9 |
Correct |
1014 ms |
34760 KB |
Output is correct |
10 |
Correct |
742 ms |
33768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
802 ms |
35092 KB |
Output is correct |
2 |
Correct |
638 ms |
34604 KB |
Output is correct |
3 |
Correct |
257 ms |
29568 KB |
Output is correct |
4 |
Correct |
639 ms |
35716 KB |
Output is correct |
5 |
Correct |
646 ms |
35288 KB |
Output is correct |
6 |
Correct |
181 ms |
27912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
356 KB |
Output is correct |
5 |
Correct |
0 ms |
608 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
356 KB |
Output is correct |
8 |
Correct |
0 ms |
356 KB |
Output is correct |
9 |
Correct |
0 ms |
356 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
588 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
356 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
356 KB |
Output is correct |
17 |
Correct |
1 ms |
356 KB |
Output is correct |
18 |
Correct |
1 ms |
380 KB |
Output is correct |
19 |
Correct |
2 ms |
952 KB |
Output is correct |
20 |
Correct |
2 ms |
868 KB |
Output is correct |
21 |
Correct |
3 ms |
868 KB |
Output is correct |
22 |
Correct |
11 ms |
860 KB |
Output is correct |
23 |
Correct |
12 ms |
1004 KB |
Output is correct |
24 |
Correct |
11 ms |
940 KB |
Output is correct |
25 |
Correct |
10 ms |
1012 KB |
Output is correct |
26 |
Correct |
10 ms |
864 KB |
Output is correct |
27 |
Correct |
5 ms |
1372 KB |
Output is correct |
28 |
Correct |
5 ms |
1372 KB |
Output is correct |
29 |
Correct |
5 ms |
1372 KB |
Output is correct |
30 |
Correct |
26 ms |
1448 KB |
Output is correct |
31 |
Correct |
22 ms |
1368 KB |
Output is correct |
32 |
Correct |
24 ms |
1372 KB |
Output is correct |
33 |
Correct |
45 ms |
9492 KB |
Output is correct |
34 |
Correct |
47 ms |
9668 KB |
Output is correct |
35 |
Correct |
51 ms |
9560 KB |
Output is correct |
36 |
Correct |
251 ms |
11724 KB |
Output is correct |
37 |
Correct |
272 ms |
11852 KB |
Output is correct |
38 |
Correct |
270 ms |
11764 KB |
Output is correct |
39 |
Correct |
235 ms |
10248 KB |
Output is correct |
40 |
Correct |
246 ms |
10212 KB |
Output is correct |
41 |
Correct |
226 ms |
10168 KB |
Output is correct |
42 |
Correct |
117 ms |
10880 KB |
Output is correct |
43 |
Correct |
183 ms |
11628 KB |
Output is correct |
44 |
Correct |
180 ms |
11724 KB |
Output is correct |
45 |
Correct |
196 ms |
11740 KB |
Output is correct |
46 |
Correct |
182 ms |
11720 KB |
Output is correct |
47 |
Correct |
183 ms |
11724 KB |
Output is correct |
48 |
Correct |
190 ms |
11860 KB |
Output is correct |
49 |
Correct |
182 ms |
11724 KB |
Output is correct |
50 |
Correct |
187 ms |
11708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
356 KB |
Output is correct |
5 |
Correct |
0 ms |
608 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
356 KB |
Output is correct |
8 |
Correct |
0 ms |
356 KB |
Output is correct |
9 |
Correct |
0 ms |
356 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
588 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
356 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
356 KB |
Output is correct |
17 |
Correct |
1 ms |
356 KB |
Output is correct |
18 |
Correct |
1 ms |
380 KB |
Output is correct |
19 |
Correct |
2 ms |
952 KB |
Output is correct |
20 |
Correct |
2 ms |
868 KB |
Output is correct |
21 |
Correct |
3 ms |
868 KB |
Output is correct |
22 |
Correct |
11 ms |
860 KB |
Output is correct |
23 |
Correct |
12 ms |
1004 KB |
Output is correct |
24 |
Correct |
11 ms |
940 KB |
Output is correct |
25 |
Correct |
10 ms |
1012 KB |
Output is correct |
26 |
Correct |
10 ms |
864 KB |
Output is correct |
27 |
Correct |
132 ms |
27904 KB |
Output is correct |
28 |
Correct |
134 ms |
26308 KB |
Output is correct |
29 |
Correct |
146 ms |
27360 KB |
Output is correct |
30 |
Correct |
135 ms |
28040 KB |
Output is correct |
31 |
Correct |
180 ms |
24516 KB |
Output is correct |
32 |
Correct |
404 ms |
28096 KB |
Output is correct |
33 |
Correct |
223 ms |
25140 KB |
Output is correct |
34 |
Correct |
241 ms |
26632 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
283 ms |
11960 KB |
Output is correct |
37 |
Correct |
982 ms |
35016 KB |
Output is correct |
38 |
Correct |
934 ms |
36192 KB |
Output is correct |
39 |
Correct |
834 ms |
33916 KB |
Output is correct |
40 |
Correct |
325 ms |
17100 KB |
Output is correct |
41 |
Correct |
147 ms |
9144 KB |
Output is correct |
42 |
Correct |
24 ms |
2260 KB |
Output is correct |
43 |
Correct |
1014 ms |
34760 KB |
Output is correct |
44 |
Correct |
742 ms |
33768 KB |
Output is correct |
45 |
Correct |
802 ms |
35092 KB |
Output is correct |
46 |
Correct |
638 ms |
34604 KB |
Output is correct |
47 |
Correct |
257 ms |
29568 KB |
Output is correct |
48 |
Correct |
639 ms |
35716 KB |
Output is correct |
49 |
Correct |
646 ms |
35288 KB |
Output is correct |
50 |
Correct |
181 ms |
27912 KB |
Output is correct |
51 |
Correct |
5 ms |
1372 KB |
Output is correct |
52 |
Correct |
5 ms |
1372 KB |
Output is correct |
53 |
Correct |
5 ms |
1372 KB |
Output is correct |
54 |
Correct |
26 ms |
1448 KB |
Output is correct |
55 |
Correct |
22 ms |
1368 KB |
Output is correct |
56 |
Correct |
24 ms |
1372 KB |
Output is correct |
57 |
Correct |
45 ms |
9492 KB |
Output is correct |
58 |
Correct |
47 ms |
9668 KB |
Output is correct |
59 |
Correct |
51 ms |
9560 KB |
Output is correct |
60 |
Correct |
251 ms |
11724 KB |
Output is correct |
61 |
Correct |
272 ms |
11852 KB |
Output is correct |
62 |
Correct |
270 ms |
11764 KB |
Output is correct |
63 |
Correct |
235 ms |
10248 KB |
Output is correct |
64 |
Correct |
246 ms |
10212 KB |
Output is correct |
65 |
Correct |
226 ms |
10168 KB |
Output is correct |
66 |
Correct |
117 ms |
10880 KB |
Output is correct |
67 |
Correct |
183 ms |
11628 KB |
Output is correct |
68 |
Correct |
180 ms |
11724 KB |
Output is correct |
69 |
Correct |
196 ms |
11740 KB |
Output is correct |
70 |
Correct |
182 ms |
11720 KB |
Output is correct |
71 |
Correct |
183 ms |
11724 KB |
Output is correct |
72 |
Correct |
190 ms |
11860 KB |
Output is correct |
73 |
Correct |
182 ms |
11724 KB |
Output is correct |
74 |
Correct |
187 ms |
11708 KB |
Output is correct |
75 |
Correct |
160 ms |
28792 KB |
Output is correct |
76 |
Correct |
151 ms |
29380 KB |
Output is correct |
77 |
Correct |
135 ms |
29160 KB |
Output is correct |
78 |
Correct |
137 ms |
29848 KB |
Output is correct |
79 |
Correct |
190 ms |
28860 KB |
Output is correct |
80 |
Correct |
144 ms |
28236 KB |
Output is correct |
81 |
Correct |
953 ms |
35776 KB |
Output is correct |
82 |
Correct |
925 ms |
35000 KB |
Output is correct |
83 |
Correct |
944 ms |
35924 KB |
Output is correct |
84 |
Correct |
968 ms |
36736 KB |
Output is correct |
85 |
Correct |
926 ms |
35292 KB |
Output is correct |
86 |
Correct |
883 ms |
35012 KB |
Output is correct |
87 |
Correct |
1018 ms |
35776 KB |
Output is correct |
88 |
Correct |
821 ms |
31868 KB |
Output is correct |
89 |
Correct |
796 ms |
31724 KB |
Output is correct |
90 |
Correct |
817 ms |
31676 KB |
Output is correct |
91 |
Correct |
813 ms |
30052 KB |
Output is correct |
92 |
Correct |
823 ms |
31296 KB |
Output is correct |
93 |
Correct |
751 ms |
35012 KB |
Output is correct |
94 |
Correct |
770 ms |
34496 KB |
Output is correct |
95 |
Correct |
770 ms |
34944 KB |
Output is correct |
96 |
Correct |
750 ms |
34608 KB |
Output is correct |
97 |
Correct |
992 ms |
35528 KB |
Output is correct |
98 |
Correct |
514 ms |
31576 KB |
Output is correct |
99 |
Correct |
762 ms |
34672 KB |
Output is correct |
100 |
Correct |
661 ms |
33984 KB |
Output is correct |
101 |
Correct |
627 ms |
33728 KB |
Output is correct |
102 |
Correct |
729 ms |
35472 KB |
Output is correct |
103 |
Correct |
939 ms |
35324 KB |
Output is correct |
104 |
Correct |
749 ms |
35264 KB |
Output is correct |
105 |
Correct |
475 ms |
31772 KB |
Output is correct |
106 |
Correct |
607 ms |
35056 KB |
Output is correct |
107 |
Correct |
637 ms |
34164 KB |
Output is correct |
108 |
Correct |
629 ms |
35060 KB |
Output is correct |
109 |
Correct |
608 ms |
35524 KB |
Output is correct |
110 |
Correct |
598 ms |
34752 KB |
Output is correct |
111 |
Correct |
581 ms |
34308 KB |
Output is correct |
112 |
Correct |
603 ms |
34800 KB |
Output is correct |
113 |
Correct |
613 ms |
34260 KB |
Output is correct |
114 |
Correct |
586 ms |
34756 KB |
Output is correct |
115 |
Correct |
582 ms |
35524 KB |
Output is correct |
116 |
Correct |
570 ms |
35720 KB |
Output is correct |