#include <bits/stdc++.h>
using namespace std;
struct Circle {
int x, y, r, id;
Circle() {}
Circle(int x, int y, int r, int id) : x(x), y(y), r(r), id(id) {}
bool operator < (const Circle &o) const { return r > o.r || (r == o.r && id < o.id); }
};
bool Intersect(Circle a, Circle b) {
return (1ll * (b.x - a.x) * (b.x - a.x) +
1ll * (b.y - a.y) * (b.y - a.y) <=
1ll * (b.r + a.r) * (b.r + a.r));
}
using Point = pair<int, int>;
int N;
vector<Circle> circles;
vector<int> revpos;
vector<bool> deleted;
vector<int> answer;
vector<pair<Point, vector<int>>> areas;
void Resize(int lg) {
int side = 1 << lg;
vector<Point> points;
for (int i = 0; i < N; i++) if (!deleted[circles[i].id]) {
points.emplace_back(circles[i].x / side, circles[i].y / side);
}
sort(begin(points), end(points));
points.resize(unique(begin(points), end(points)) - begin(points));
areas.clear();
for (auto p : points) {
areas.emplace_back(p, vector<int>());
}
for (int i = 0; i < N; i++) if (!deleted[circles[i].id]) {
auto pos = lower_bound(begin(points), end(points), Point(circles[i].x / side, circles[i].y / side));
areas[(pos - begin(points))].second.emplace_back(circles[i].id);
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> N;
for (int i = 0; i < N; i++) {
int x, y, r;
cin >> x >> y >> r;
x += 1e9, y += 1e9;
circles.emplace_back(x, y, r, i);
deleted.emplace_back(false);
answer.emplace_back(-1);
}
sort(begin(circles), end(circles));
revpos.resize(N);
for (int i = 0; i < N; i++) {
revpos[circles[i].id] = i;
}
int lg = 30;
Resize(lg);
for (auto c : circles) if (!deleted[c.id]) {
while ((1 << (lg - 1)) >= c.r) {
Resize(--lg);
}
int side = 1 << lg;
int x = c.x / side;
int y = c.y / side;
for (int dx = -2; dx <= 2; dx++) {
for (int dy = -2; dy <= 2; dy++) {
auto it = lower_bound(begin(areas), end(areas),
pair<Point, vector<int>>{{x + dx, y + dy}, vector<int>()});
if (it == end(areas) || it->first != make_pair(x + dx, y + dy)) {
continue;
}
for (auto j : it->second) {
if (Intersect(c, circles[revpos[j]]) && !deleted[j]) {
answer[j] = c.id;
deleted[j] = true;
}
}
}
}
}
for (int i = 0; i < N; i++) {
cout << answer[i] + 1 << " \n"[i + 1 == N];
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
6 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
8 ms |
640 KB |
Output is correct |
20 |
Correct |
8 ms |
640 KB |
Output is correct |
21 |
Correct |
8 ms |
640 KB |
Output is correct |
22 |
Correct |
32 ms |
960 KB |
Output is correct |
23 |
Correct |
34 ms |
1024 KB |
Output is correct |
24 |
Correct |
31 ms |
1004 KB |
Output is correct |
25 |
Correct |
33 ms |
1024 KB |
Output is correct |
26 |
Correct |
31 ms |
956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
218 ms |
15764 KB |
Output is correct |
2 |
Correct |
249 ms |
16916 KB |
Output is correct |
3 |
Correct |
243 ms |
18196 KB |
Output is correct |
4 |
Correct |
200 ms |
16404 KB |
Output is correct |
5 |
Correct |
1002 ms |
16276 KB |
Output is correct |
6 |
Correct |
1657 ms |
26028 KB |
Output is correct |
7 |
Correct |
1014 ms |
21412 KB |
Output is correct |
8 |
Correct |
1233 ms |
24924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
670 ms |
11104 KB |
Output is correct |
3 |
Correct |
2662 ms |
38712 KB |
Output is correct |
4 |
Correct |
2695 ms |
38516 KB |
Output is correct |
5 |
Correct |
2161 ms |
30308 KB |
Output is correct |
6 |
Correct |
929 ms |
19752 KB |
Output is correct |
7 |
Correct |
458 ms |
10596 KB |
Output is correct |
8 |
Correct |
94 ms |
2476 KB |
Output is correct |
9 |
Correct |
2523 ms |
46264 KB |
Output is correct |
10 |
Correct |
1836 ms |
37112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2848 ms |
38480 KB |
Output is correct |
2 |
Execution timed out |
3089 ms |
45804 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
6 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
8 ms |
640 KB |
Output is correct |
20 |
Correct |
8 ms |
640 KB |
Output is correct |
21 |
Correct |
8 ms |
640 KB |
Output is correct |
22 |
Correct |
32 ms |
960 KB |
Output is correct |
23 |
Correct |
34 ms |
1024 KB |
Output is correct |
24 |
Correct |
31 ms |
1004 KB |
Output is correct |
25 |
Correct |
33 ms |
1024 KB |
Output is correct |
26 |
Correct |
31 ms |
956 KB |
Output is correct |
27 |
Correct |
13 ms |
960 KB |
Output is correct |
28 |
Correct |
12 ms |
960 KB |
Output is correct |
29 |
Correct |
11 ms |
960 KB |
Output is correct |
30 |
Correct |
63 ms |
1636 KB |
Output is correct |
31 |
Correct |
60 ms |
1568 KB |
Output is correct |
32 |
Correct |
67 ms |
1576 KB |
Output is correct |
33 |
Correct |
74 ms |
5160 KB |
Output is correct |
34 |
Correct |
73 ms |
5160 KB |
Output is correct |
35 |
Correct |
90 ms |
5416 KB |
Output is correct |
36 |
Correct |
772 ms |
11472 KB |
Output is correct |
37 |
Correct |
785 ms |
11532 KB |
Output is correct |
38 |
Correct |
767 ms |
11348 KB |
Output is correct |
39 |
Correct |
533 ms |
10392 KB |
Output is correct |
40 |
Correct |
533 ms |
11628 KB |
Output is correct |
41 |
Correct |
537 ms |
11596 KB |
Output is correct |
42 |
Correct |
381 ms |
10376 KB |
Output is correct |
43 |
Correct |
737 ms |
13892 KB |
Output is correct |
44 |
Correct |
743 ms |
14284 KB |
Output is correct |
45 |
Correct |
719 ms |
13748 KB |
Output is correct |
46 |
Correct |
732 ms |
13808 KB |
Output is correct |
47 |
Correct |
714 ms |
13876 KB |
Output is correct |
48 |
Correct |
738 ms |
13976 KB |
Output is correct |
49 |
Correct |
724 ms |
13924 KB |
Output is correct |
50 |
Correct |
719 ms |
13808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
6 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
8 ms |
640 KB |
Output is correct |
20 |
Correct |
8 ms |
640 KB |
Output is correct |
21 |
Correct |
8 ms |
640 KB |
Output is correct |
22 |
Correct |
32 ms |
960 KB |
Output is correct |
23 |
Correct |
34 ms |
1024 KB |
Output is correct |
24 |
Correct |
31 ms |
1004 KB |
Output is correct |
25 |
Correct |
33 ms |
1024 KB |
Output is correct |
26 |
Correct |
31 ms |
956 KB |
Output is correct |
27 |
Correct |
218 ms |
15764 KB |
Output is correct |
28 |
Correct |
249 ms |
16916 KB |
Output is correct |
29 |
Correct |
243 ms |
18196 KB |
Output is correct |
30 |
Correct |
200 ms |
16404 KB |
Output is correct |
31 |
Correct |
1002 ms |
16276 KB |
Output is correct |
32 |
Correct |
1657 ms |
26028 KB |
Output is correct |
33 |
Correct |
1014 ms |
21412 KB |
Output is correct |
34 |
Correct |
1233 ms |
24924 KB |
Output is correct |
35 |
Correct |
5 ms |
384 KB |
Output is correct |
36 |
Correct |
670 ms |
11104 KB |
Output is correct |
37 |
Correct |
2662 ms |
38712 KB |
Output is correct |
38 |
Correct |
2695 ms |
38516 KB |
Output is correct |
39 |
Correct |
2161 ms |
30308 KB |
Output is correct |
40 |
Correct |
929 ms |
19752 KB |
Output is correct |
41 |
Correct |
458 ms |
10596 KB |
Output is correct |
42 |
Correct |
94 ms |
2476 KB |
Output is correct |
43 |
Correct |
2523 ms |
46264 KB |
Output is correct |
44 |
Correct |
1836 ms |
37112 KB |
Output is correct |
45 |
Correct |
2848 ms |
38480 KB |
Output is correct |
46 |
Execution timed out |
3089 ms |
45804 KB |
Time limit exceeded |
47 |
Halted |
0 ms |
0 KB |
- |