// https://oj.uz/submission/77965
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
const int INF = 1000 * 1000 * 1000 + 8;
int64_t sqr(int x) { return (int64_t) x * x; }
void minimize(int &x, int y) { x = (x < y ? x : y); }
void maximize(int &x, int y) { x = (x > y ? x : y); }
struct Box
{
int x0, x1, y0, y1;
Box(int _x0 = INF, int _x1 = -INF, int _y0 = INF, int _y1 = -INF): x0(_x0), x1(_x1), y0(_y0), y1(_y1) {}
bool intersect(const Box &b) const { return (x0 <= b.x1 && b.x0 <= x1 && y0 <= b.y1 && b.y0 <= y1); }
void expand(const Box &b) { minimize(x0, b.x0), minimize(y0, b.y0), maximize(x1, b.x1), maximize(y1, b.y1); }
};
struct Circle
{
int x, y, r, i;
bool intersect(const Circle &c) const { return sqr(c.x - x) + sqr(c.y - y) <= sqr(r + c.r); }
Box toBox() { return Box(x - r, x + r, y - r, y + r); }
};
bool compX(const Circle &a, const Circle &b) { return (a.x == b.x ? (a.y < b.y) : (a.x < b.x)); }
bool compY(const Circle &a, const Circle &b) { return (a.y == b.y ? (a.x < b.x) : (a.y < b.y)); }
bool compR(const Circle &a, const Circle &b) { return (a.r == b.r ? (a.i < b.i) : (a.r > b.r)); }
int n;
vector<int> ans;
vector<Circle> circles, cirTree;
vector<Box> boxTree;
void build(int lo = 0, int hi = n - 1, bool byX = 0)
{
int mid = (lo + hi) >> 1;
nth_element(cirTree.begin() + lo, cirTree.begin() + mid, cirTree.begin() + hi + 1, (byX ? compX : compY));
boxTree[mid] = cirTree[mid].toBox();
if (lo < mid) {
build(lo, mid - 1, !byX);
boxTree[mid].expand(boxTree[(lo + mid - 1) >> 1]);
}
if (mid < hi) {
build(mid + 1, hi, !byX);
boxTree[mid].expand(boxTree[(mid + 1 + hi) >> 1]);
}
// cout << mid << ' ' << lo << ' ' << hi << ' ' << cirTree[mid].i << ": ";
// cout << boxTree[mid].x0 << ' ' << boxTree[mid].x1 << ' ' << boxTree[mid].y0 << ' ' << boxTree[mid].y1 << endl;
}
void get(Circle &c, Box &b, int lo = 0, int hi = n - 1, bool byX = 0)
{
int mid = (lo + hi) >> 1;
if (ans[cirTree[mid].i] == -1 && cirTree[mid].intersect(c)) ans[cirTree[mid].i] = c.i;
// cout << c.i << ": " << lo << ' ' << hi << ' ' << cirTree[mid].i << " - ";
// cout << boxTree[mid].x0 << ' ' << boxTree[mid].x1 << ' ' << boxTree[mid].y0 << ' ' << boxTree[mid].y1 << endl;
boxTree[mid] = Box(INF, -INF, INF, -INF);
if (ans[cirTree[mid].i] == -1) boxTree[mid] = cirTree[mid].toBox();
int lc = (lo + mid - 1) >> 1, rc = (mid + 1 + hi) >> 1;
if (lo < mid) {
if (boxTree[lc].intersect(b)) get(c, b, lo, mid - 1, !byX);
boxTree[mid].expand(boxTree[lc]);
}
if (mid < hi) {
if (boxTree[rc].intersect(b)) get(c, b, mid + 1, hi, !byX);
boxTree[mid].expand(boxTree[rc]);
}
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> n;
circles.resize(n);
for (int i = 0; i < n; ++i) {
cin >> circles[i].x >> circles[i].y >> circles[i].r;
circles[i].i = i;
}
sort(circles.begin(), circles.end(), compR);
cirTree = circles;
boxTree.resize(n);
ans.assign(n, -1);
build();
for (auto &c : circles) if (ans[c.i] == -1) {
ans[c.i] = c.i;
Box b = c.toBox();
get(c, b);
}
for (int i = 0; i < n; ++i) cout << ans[i] + 1 << ' ';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 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 |
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 |
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 |
10 ms |
768 KB |
Output is correct |
20 |
Correct |
9 ms |
768 KB |
Output is correct |
21 |
Correct |
9 ms |
768 KB |
Output is correct |
22 |
Correct |
11 ms |
768 KB |
Output is correct |
23 |
Correct |
10 ms |
768 KB |
Output is correct |
24 |
Correct |
11 ms |
768 KB |
Output is correct |
25 |
Correct |
10 ms |
768 KB |
Output is correct |
26 |
Correct |
10 ms |
768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
261 ms |
19320 KB |
Output is correct |
2 |
Correct |
260 ms |
19320 KB |
Output is correct |
3 |
Correct |
267 ms |
18936 KB |
Output is correct |
4 |
Correct |
260 ms |
19320 KB |
Output is correct |
5 |
Correct |
260 ms |
19064 KB |
Output is correct |
6 |
Correct |
321 ms |
19192 KB |
Output is correct |
7 |
Correct |
263 ms |
19192 KB |
Output is correct |
8 |
Correct |
271 ms |
19192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
153 ms |
7412 KB |
Output is correct |
3 |
Correct |
567 ms |
19264 KB |
Output is correct |
4 |
Correct |
568 ms |
19448 KB |
Output is correct |
5 |
Correct |
489 ms |
19064 KB |
Output is correct |
6 |
Correct |
217 ms |
11132 KB |
Output is correct |
7 |
Correct |
107 ms |
6776 KB |
Output is correct |
8 |
Correct |
24 ms |
1792 KB |
Output is correct |
9 |
Correct |
542 ms |
19448 KB |
Output is correct |
10 |
Correct |
454 ms |
19448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
546 ms |
19064 KB |
Output is correct |
2 |
Correct |
548 ms |
19448 KB |
Output is correct |
3 |
Correct |
311 ms |
18680 KB |
Output is correct |
4 |
Correct |
551 ms |
19064 KB |
Output is correct |
5 |
Correct |
527 ms |
19192 KB |
Output is correct |
6 |
Correct |
305 ms |
18424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 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 |
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 |
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 |
10 ms |
768 KB |
Output is correct |
20 |
Correct |
9 ms |
768 KB |
Output is correct |
21 |
Correct |
9 ms |
768 KB |
Output is correct |
22 |
Correct |
11 ms |
768 KB |
Output is correct |
23 |
Correct |
10 ms |
768 KB |
Output is correct |
24 |
Correct |
11 ms |
768 KB |
Output is correct |
25 |
Correct |
10 ms |
768 KB |
Output is correct |
26 |
Correct |
10 ms |
768 KB |
Output is correct |
27 |
Correct |
14 ms |
1280 KB |
Output is correct |
28 |
Correct |
13 ms |
1256 KB |
Output is correct |
29 |
Correct |
13 ms |
1152 KB |
Output is correct |
30 |
Correct |
16 ms |
1152 KB |
Output is correct |
31 |
Correct |
16 ms |
1152 KB |
Output is correct |
32 |
Correct |
17 ms |
1152 KB |
Output is correct |
33 |
Correct |
98 ms |
7544 KB |
Output is correct |
34 |
Correct |
101 ms |
7544 KB |
Output is correct |
35 |
Correct |
100 ms |
7544 KB |
Output is correct |
36 |
Correct |
148 ms |
7544 KB |
Output is correct |
37 |
Correct |
149 ms |
7800 KB |
Output is correct |
38 |
Correct |
147 ms |
7672 KB |
Output is correct |
39 |
Correct |
116 ms |
6904 KB |
Output is correct |
40 |
Correct |
118 ms |
6904 KB |
Output is correct |
41 |
Correct |
120 ms |
6904 KB |
Output is correct |
42 |
Correct |
104 ms |
7416 KB |
Output is correct |
43 |
Correct |
132 ms |
7672 KB |
Output is correct |
44 |
Correct |
131 ms |
7672 KB |
Output is correct |
45 |
Correct |
130 ms |
7672 KB |
Output is correct |
46 |
Correct |
134 ms |
7672 KB |
Output is correct |
47 |
Correct |
131 ms |
7672 KB |
Output is correct |
48 |
Correct |
132 ms |
7672 KB |
Output is correct |
49 |
Correct |
132 ms |
7672 KB |
Output is correct |
50 |
Correct |
128 ms |
7800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 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 |
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 |
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 |
10 ms |
768 KB |
Output is correct |
20 |
Correct |
9 ms |
768 KB |
Output is correct |
21 |
Correct |
9 ms |
768 KB |
Output is correct |
22 |
Correct |
11 ms |
768 KB |
Output is correct |
23 |
Correct |
10 ms |
768 KB |
Output is correct |
24 |
Correct |
11 ms |
768 KB |
Output is correct |
25 |
Correct |
10 ms |
768 KB |
Output is correct |
26 |
Correct |
10 ms |
768 KB |
Output is correct |
27 |
Correct |
261 ms |
19320 KB |
Output is correct |
28 |
Correct |
260 ms |
19320 KB |
Output is correct |
29 |
Correct |
267 ms |
18936 KB |
Output is correct |
30 |
Correct |
260 ms |
19320 KB |
Output is correct |
31 |
Correct |
260 ms |
19064 KB |
Output is correct |
32 |
Correct |
321 ms |
19192 KB |
Output is correct |
33 |
Correct |
263 ms |
19192 KB |
Output is correct |
34 |
Correct |
271 ms |
19192 KB |
Output is correct |
35 |
Correct |
5 ms |
384 KB |
Output is correct |
36 |
Correct |
153 ms |
7412 KB |
Output is correct |
37 |
Correct |
567 ms |
19264 KB |
Output is correct |
38 |
Correct |
568 ms |
19448 KB |
Output is correct |
39 |
Correct |
489 ms |
19064 KB |
Output is correct |
40 |
Correct |
217 ms |
11132 KB |
Output is correct |
41 |
Correct |
107 ms |
6776 KB |
Output is correct |
42 |
Correct |
24 ms |
1792 KB |
Output is correct |
43 |
Correct |
542 ms |
19448 KB |
Output is correct |
44 |
Correct |
454 ms |
19448 KB |
Output is correct |
45 |
Correct |
546 ms |
19064 KB |
Output is correct |
46 |
Correct |
548 ms |
19448 KB |
Output is correct |
47 |
Correct |
311 ms |
18680 KB |
Output is correct |
48 |
Correct |
551 ms |
19064 KB |
Output is correct |
49 |
Correct |
527 ms |
19192 KB |
Output is correct |
50 |
Correct |
305 ms |
18424 KB |
Output is correct |
51 |
Correct |
14 ms |
1280 KB |
Output is correct |
52 |
Correct |
13 ms |
1256 KB |
Output is correct |
53 |
Correct |
13 ms |
1152 KB |
Output is correct |
54 |
Correct |
16 ms |
1152 KB |
Output is correct |
55 |
Correct |
16 ms |
1152 KB |
Output is correct |
56 |
Correct |
17 ms |
1152 KB |
Output is correct |
57 |
Correct |
98 ms |
7544 KB |
Output is correct |
58 |
Correct |
101 ms |
7544 KB |
Output is correct |
59 |
Correct |
100 ms |
7544 KB |
Output is correct |
60 |
Correct |
148 ms |
7544 KB |
Output is correct |
61 |
Correct |
149 ms |
7800 KB |
Output is correct |
62 |
Correct |
147 ms |
7672 KB |
Output is correct |
63 |
Correct |
116 ms |
6904 KB |
Output is correct |
64 |
Correct |
118 ms |
6904 KB |
Output is correct |
65 |
Correct |
120 ms |
6904 KB |
Output is correct |
66 |
Correct |
104 ms |
7416 KB |
Output is correct |
67 |
Correct |
132 ms |
7672 KB |
Output is correct |
68 |
Correct |
131 ms |
7672 KB |
Output is correct |
69 |
Correct |
130 ms |
7672 KB |
Output is correct |
70 |
Correct |
134 ms |
7672 KB |
Output is correct |
71 |
Correct |
131 ms |
7672 KB |
Output is correct |
72 |
Correct |
132 ms |
7672 KB |
Output is correct |
73 |
Correct |
132 ms |
7672 KB |
Output is correct |
74 |
Correct |
128 ms |
7800 KB |
Output is correct |
75 |
Correct |
303 ms |
18928 KB |
Output is correct |
76 |
Correct |
312 ms |
19192 KB |
Output is correct |
77 |
Correct |
295 ms |
19320 KB |
Output is correct |
78 |
Correct |
298 ms |
18936 KB |
Output is correct |
79 |
Correct |
317 ms |
19272 KB |
Output is correct |
80 |
Correct |
293 ms |
18936 KB |
Output is correct |
81 |
Correct |
631 ms |
19192 KB |
Output is correct |
82 |
Correct |
560 ms |
19064 KB |
Output is correct |
83 |
Correct |
572 ms |
19064 KB |
Output is correct |
84 |
Correct |
646 ms |
19168 KB |
Output is correct |
85 |
Correct |
608 ms |
19192 KB |
Output is correct |
86 |
Correct |
579 ms |
19064 KB |
Output is correct |
87 |
Correct |
569 ms |
19192 KB |
Output is correct |
88 |
Correct |
447 ms |
19064 KB |
Output is correct |
89 |
Correct |
414 ms |
19064 KB |
Output is correct |
90 |
Correct |
430 ms |
19320 KB |
Output is correct |
91 |
Correct |
516 ms |
19448 KB |
Output is correct |
92 |
Correct |
452 ms |
19516 KB |
Output is correct |
93 |
Correct |
1536 ms |
19560 KB |
Output is correct |
94 |
Execution timed out |
3078 ms |
17504 KB |
Time limit exceeded |
95 |
Halted |
0 ms |
0 KB |
- |