#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, int>> points;
void Resize(int lg) {
int side = 1 << lg;
points.clear();
for (int i = 0; i < N; i++) if (!deleted[circles[i].id]) {
points.emplace_back(Point(circles[i].x / side, circles[i].y / side), circles[i].id);
}
sort(begin(points), end(points));
}
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(points), end(points), make_pair(Point(x + dx, y + dy), -1));
for (auto j = it; j != end(points) && j->first == make_pair(x + dx, y + dy); j++) {
if (Intersect(c, circles[revpos[j->second]]) && !deleted[j->second]) {
answer[j->second] = c.id;
deleted[j->second] = 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 |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
256 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 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 |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
4 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 |
308 KB |
Output is correct |
15 |
Correct |
5 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 |
768 KB |
Output is correct |
21 |
Correct |
8 ms |
640 KB |
Output is correct |
22 |
Correct |
23 ms |
640 KB |
Output is correct |
23 |
Correct |
27 ms |
640 KB |
Output is correct |
24 |
Correct |
23 ms |
768 KB |
Output is correct |
25 |
Correct |
23 ms |
640 KB |
Output is correct |
26 |
Correct |
23 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
263 ms |
19348 KB |
Output is correct |
2 |
Correct |
308 ms |
19376 KB |
Output is correct |
3 |
Correct |
312 ms |
19220 KB |
Output is correct |
4 |
Correct |
221 ms |
19348 KB |
Output is correct |
5 |
Correct |
1037 ms |
19092 KB |
Output is correct |
6 |
Correct |
1280 ms |
19220 KB |
Output is correct |
7 |
Correct |
1031 ms |
19220 KB |
Output is correct |
8 |
Correct |
1121 ms |
19220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
459 ms |
5996 KB |
Output is correct |
3 |
Correct |
1514 ms |
19220 KB |
Output is correct |
4 |
Correct |
1513 ms |
19188 KB |
Output is correct |
5 |
Correct |
1337 ms |
18908 KB |
Output is correct |
6 |
Correct |
597 ms |
10132 KB |
Output is correct |
7 |
Correct |
300 ms |
5420 KB |
Output is correct |
8 |
Correct |
60 ms |
1460 KB |
Output is correct |
9 |
Correct |
1532 ms |
19220 KB |
Output is correct |
10 |
Correct |
1164 ms |
19220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1607 ms |
19180 KB |
Output is correct |
2 |
Correct |
1868 ms |
19352 KB |
Output is correct |
3 |
Correct |
699 ms |
27340 KB |
Output is correct |
4 |
Correct |
1592 ms |
26684 KB |
Output is correct |
5 |
Correct |
1592 ms |
26900 KB |
Output is correct |
6 |
Correct |
580 ms |
27156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
256 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 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 |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
4 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 |
308 KB |
Output is correct |
15 |
Correct |
5 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 |
768 KB |
Output is correct |
21 |
Correct |
8 ms |
640 KB |
Output is correct |
22 |
Correct |
23 ms |
640 KB |
Output is correct |
23 |
Correct |
27 ms |
640 KB |
Output is correct |
24 |
Correct |
23 ms |
768 KB |
Output is correct |
25 |
Correct |
23 ms |
640 KB |
Output is correct |
26 |
Correct |
23 ms |
640 KB |
Output is correct |
27 |
Correct |
14 ms |
1036 KB |
Output is correct |
28 |
Correct |
14 ms |
960 KB |
Output is correct |
29 |
Correct |
12 ms |
960 KB |
Output is correct |
30 |
Correct |
48 ms |
960 KB |
Output is correct |
31 |
Correct |
44 ms |
960 KB |
Output is correct |
32 |
Correct |
45 ms |
960 KB |
Output is correct |
33 |
Correct |
81 ms |
6056 KB |
Output is correct |
34 |
Correct |
84 ms |
6056 KB |
Output is correct |
35 |
Correct |
108 ms |
6056 KB |
Output is correct |
36 |
Correct |
489 ms |
6056 KB |
Output is correct |
37 |
Correct |
486 ms |
6056 KB |
Output is correct |
38 |
Correct |
493 ms |
6056 KB |
Output is correct |
39 |
Correct |
632 ms |
6056 KB |
Output is correct |
40 |
Correct |
643 ms |
6004 KB |
Output is correct |
41 |
Correct |
633 ms |
6056 KB |
Output is correct |
42 |
Correct |
308 ms |
5928 KB |
Output is correct |
43 |
Correct |
461 ms |
6056 KB |
Output is correct |
44 |
Correct |
463 ms |
6056 KB |
Output is correct |
45 |
Correct |
463 ms |
6056 KB |
Output is correct |
46 |
Correct |
467 ms |
6056 KB |
Output is correct |
47 |
Correct |
465 ms |
6060 KB |
Output is correct |
48 |
Correct |
468 ms |
6056 KB |
Output is correct |
49 |
Correct |
464 ms |
6104 KB |
Output is correct |
50 |
Correct |
475 ms |
6056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
256 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 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 |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
4 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 |
308 KB |
Output is correct |
15 |
Correct |
5 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 |
768 KB |
Output is correct |
21 |
Correct |
8 ms |
640 KB |
Output is correct |
22 |
Correct |
23 ms |
640 KB |
Output is correct |
23 |
Correct |
27 ms |
640 KB |
Output is correct |
24 |
Correct |
23 ms |
768 KB |
Output is correct |
25 |
Correct |
23 ms |
640 KB |
Output is correct |
26 |
Correct |
23 ms |
640 KB |
Output is correct |
27 |
Correct |
263 ms |
19348 KB |
Output is correct |
28 |
Correct |
308 ms |
19376 KB |
Output is correct |
29 |
Correct |
312 ms |
19220 KB |
Output is correct |
30 |
Correct |
221 ms |
19348 KB |
Output is correct |
31 |
Correct |
1037 ms |
19092 KB |
Output is correct |
32 |
Correct |
1280 ms |
19220 KB |
Output is correct |
33 |
Correct |
1031 ms |
19220 KB |
Output is correct |
34 |
Correct |
1121 ms |
19220 KB |
Output is correct |
35 |
Correct |
5 ms |
384 KB |
Output is correct |
36 |
Correct |
459 ms |
5996 KB |
Output is correct |
37 |
Correct |
1514 ms |
19220 KB |
Output is correct |
38 |
Correct |
1513 ms |
19188 KB |
Output is correct |
39 |
Correct |
1337 ms |
18908 KB |
Output is correct |
40 |
Correct |
597 ms |
10132 KB |
Output is correct |
41 |
Correct |
300 ms |
5420 KB |
Output is correct |
42 |
Correct |
60 ms |
1460 KB |
Output is correct |
43 |
Correct |
1532 ms |
19220 KB |
Output is correct |
44 |
Correct |
1164 ms |
19220 KB |
Output is correct |
45 |
Correct |
1607 ms |
19180 KB |
Output is correct |
46 |
Correct |
1868 ms |
19352 KB |
Output is correct |
47 |
Correct |
699 ms |
27340 KB |
Output is correct |
48 |
Correct |
1592 ms |
26684 KB |
Output is correct |
49 |
Correct |
1592 ms |
26900 KB |
Output is correct |
50 |
Correct |
580 ms |
27156 KB |
Output is correct |
51 |
Correct |
14 ms |
1036 KB |
Output is correct |
52 |
Correct |
14 ms |
960 KB |
Output is correct |
53 |
Correct |
12 ms |
960 KB |
Output is correct |
54 |
Correct |
48 ms |
960 KB |
Output is correct |
55 |
Correct |
44 ms |
960 KB |
Output is correct |
56 |
Correct |
45 ms |
960 KB |
Output is correct |
57 |
Correct |
81 ms |
6056 KB |
Output is correct |
58 |
Correct |
84 ms |
6056 KB |
Output is correct |
59 |
Correct |
108 ms |
6056 KB |
Output is correct |
60 |
Correct |
489 ms |
6056 KB |
Output is correct |
61 |
Correct |
486 ms |
6056 KB |
Output is correct |
62 |
Correct |
493 ms |
6056 KB |
Output is correct |
63 |
Correct |
632 ms |
6056 KB |
Output is correct |
64 |
Correct |
643 ms |
6004 KB |
Output is correct |
65 |
Correct |
633 ms |
6056 KB |
Output is correct |
66 |
Correct |
308 ms |
5928 KB |
Output is correct |
67 |
Correct |
461 ms |
6056 KB |
Output is correct |
68 |
Correct |
463 ms |
6056 KB |
Output is correct |
69 |
Correct |
463 ms |
6056 KB |
Output is correct |
70 |
Correct |
467 ms |
6056 KB |
Output is correct |
71 |
Correct |
465 ms |
6060 KB |
Output is correct |
72 |
Correct |
468 ms |
6056 KB |
Output is correct |
73 |
Correct |
464 ms |
6104 KB |
Output is correct |
74 |
Correct |
475 ms |
6056 KB |
Output is correct |
75 |
Correct |
314 ms |
28308 KB |
Output is correct |
76 |
Correct |
359 ms |
28184 KB |
Output is correct |
77 |
Correct |
326 ms |
28184 KB |
Output is correct |
78 |
Correct |
247 ms |
28052 KB |
Output is correct |
79 |
Correct |
452 ms |
28024 KB |
Output is correct |
80 |
Correct |
245 ms |
28096 KB |
Output is correct |
81 |
Correct |
1612 ms |
27284 KB |
Output is correct |
82 |
Correct |
1559 ms |
27156 KB |
Output is correct |
83 |
Correct |
1582 ms |
27088 KB |
Output is correct |
84 |
Correct |
1643 ms |
27676 KB |
Output is correct |
85 |
Correct |
1578 ms |
27156 KB |
Output is correct |
86 |
Correct |
1564 ms |
27156 KB |
Output is correct |
87 |
Correct |
1704 ms |
27248 KB |
Output is correct |
88 |
Correct |
2063 ms |
22416 KB |
Output is correct |
89 |
Correct |
2045 ms |
22548 KB |
Output is correct |
90 |
Correct |
2045 ms |
22420 KB |
Output is correct |
91 |
Correct |
2071 ms |
22424 KB |
Output is correct |
92 |
Correct |
2055 ms |
22420 KB |
Output is correct |
93 |
Correct |
1674 ms |
26132 KB |
Output is correct |
94 |
Correct |
1711 ms |
26644 KB |
Output is correct |
95 |
Correct |
1678 ms |
26388 KB |
Output is correct |
96 |
Correct |
1664 ms |
26312 KB |
Output is correct |
97 |
Correct |
2108 ms |
26132 KB |
Output is correct |
98 |
Correct |
1370 ms |
26648 KB |
Output is correct |
99 |
Correct |
1669 ms |
26388 KB |
Output is correct |
100 |
Correct |
1760 ms |
26000 KB |
Output is correct |
101 |
Correct |
1499 ms |
26516 KB |
Output is correct |
102 |
Correct |
1644 ms |
26156 KB |
Output is correct |
103 |
Correct |
1927 ms |
26172 KB |
Output is correct |
104 |
Correct |
1647 ms |
26004 KB |
Output is correct |
105 |
Correct |
1096 ms |
23956 KB |
Output is correct |
106 |
Correct |
1514 ms |
27028 KB |
Output is correct |
107 |
Correct |
1522 ms |
27028 KB |
Output is correct |
108 |
Correct |
1521 ms |
27248 KB |
Output is correct |
109 |
Correct |
1524 ms |
26936 KB |
Output is correct |
110 |
Correct |
1535 ms |
27028 KB |
Output is correct |
111 |
Correct |
1536 ms |
27084 KB |
Output is correct |
112 |
Correct |
1528 ms |
27060 KB |
Output is correct |
113 |
Correct |
1516 ms |
26964 KB |
Output is correct |
114 |
Correct |
1545 ms |
27028 KB |
Output is correct |
115 |
Correct |
1525 ms |
26960 KB |
Output is correct |
116 |
Correct |
1431 ms |
26900 KB |
Output is correct |