#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int long long
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;
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 /= 2;
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;
}
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
244 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
320 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
316 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
320 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
2 ms |
520 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 |
1492 KB |
Output is correct |
20 |
Correct |
4 ms |
1492 KB |
Output is correct |
21 |
Correct |
6 ms |
1684 KB |
Output is correct |
22 |
Correct |
11 ms |
1868 KB |
Output is correct |
23 |
Correct |
11 ms |
1888 KB |
Output is correct |
24 |
Correct |
11 ms |
1868 KB |
Output is correct |
25 |
Correct |
13 ms |
1788 KB |
Output is correct |
26 |
Correct |
11 ms |
1868 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
330 ms |
72052 KB |
Output is correct |
2 |
Correct |
326 ms |
65544 KB |
Output is correct |
3 |
Correct |
277 ms |
57948 KB |
Output is correct |
4 |
Correct |
389 ms |
67044 KB |
Output is correct |
5 |
Correct |
459 ms |
73680 KB |
Output is correct |
6 |
Correct |
738 ms |
95832 KB |
Output is correct |
7 |
Correct |
631 ms |
86616 KB |
Output is correct |
8 |
Correct |
603 ms |
87244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
401 ms |
28852 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
361 ms |
50388 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
244 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
320 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
316 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
320 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
2 ms |
520 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 |
1492 KB |
Output is correct |
20 |
Correct |
4 ms |
1492 KB |
Output is correct |
21 |
Correct |
6 ms |
1684 KB |
Output is correct |
22 |
Correct |
11 ms |
1868 KB |
Output is correct |
23 |
Correct |
11 ms |
1888 KB |
Output is correct |
24 |
Correct |
11 ms |
1868 KB |
Output is correct |
25 |
Correct |
13 ms |
1788 KB |
Output is correct |
26 |
Correct |
11 ms |
1868 KB |
Output is correct |
27 |
Correct |
15 ms |
3076 KB |
Output is correct |
28 |
Correct |
7 ms |
2508 KB |
Output is correct |
29 |
Correct |
8 ms |
2380 KB |
Output is correct |
30 |
Correct |
23 ms |
3252 KB |
Output is correct |
31 |
Correct |
22 ms |
3344 KB |
Output is correct |
32 |
Correct |
23 ms |
3344 KB |
Output is correct |
33 |
Correct |
82 ms |
22356 KB |
Output is correct |
34 |
Correct |
81 ms |
21976 KB |
Output is correct |
35 |
Correct |
235 ms |
24140 KB |
Output is correct |
36 |
Correct |
327 ms |
31624 KB |
Output is correct |
37 |
Correct |
354 ms |
33344 KB |
Output is correct |
38 |
Correct |
350 ms |
31280 KB |
Output is correct |
39 |
Correct |
401 ms |
26712 KB |
Output is correct |
40 |
Correct |
418 ms |
30216 KB |
Output is correct |
41 |
Correct |
415 ms |
26832 KB |
Output is correct |
42 |
Correct |
73 ms |
17660 KB |
Output is correct |
43 |
Incorrect |
105 ms |
22372 KB |
Output isn't correct |
44 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
244 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
320 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
316 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
320 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
2 ms |
520 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 |
1492 KB |
Output is correct |
20 |
Correct |
4 ms |
1492 KB |
Output is correct |
21 |
Correct |
6 ms |
1684 KB |
Output is correct |
22 |
Correct |
11 ms |
1868 KB |
Output is correct |
23 |
Correct |
11 ms |
1888 KB |
Output is correct |
24 |
Correct |
11 ms |
1868 KB |
Output is correct |
25 |
Correct |
13 ms |
1788 KB |
Output is correct |
26 |
Correct |
11 ms |
1868 KB |
Output is correct |
27 |
Correct |
330 ms |
72052 KB |
Output is correct |
28 |
Correct |
326 ms |
65544 KB |
Output is correct |
29 |
Correct |
277 ms |
57948 KB |
Output is correct |
30 |
Correct |
389 ms |
67044 KB |
Output is correct |
31 |
Correct |
459 ms |
73680 KB |
Output is correct |
32 |
Correct |
738 ms |
95832 KB |
Output is correct |
33 |
Correct |
631 ms |
86616 KB |
Output is correct |
34 |
Correct |
603 ms |
87244 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Incorrect |
401 ms |
28852 KB |
Output isn't correct |
37 |
Halted |
0 ms |
0 KB |
- |