#include <bits/stdc++.h>
using namespace std;
const int mxN = 3e5 + 5;
int x[mxN], y[mxN], r[mxN], pos[mxN], ans[mxN];
set<pair<int, int>> st[2 * 4 * mxN];
void update(int x, int lx, int rx, int l, int r, int i) {
if (l > rx || lx > r) return;
if (l <= lx && r >= rx) {
st[x].insert({y[i], i});
return;
}
int mx = (lx + rx) >> 1;
update(x << 1, lx, mx, l, r, i);
update(x << 1 | 1, mx + 1, rx, l, r, i);
}
bool intersect(int a, int b) {
return 1LL * (x[a] - x[b]) * (x[a] - x[b]) + 1LL * (y[a] - y[b]) * (y[a] - y[b]) <= 1LL * (r[a] + r[b]) * (r[a] + r[b]);
}
void update(int a, int b) {
if (!intersect(a, b)) return;
if (pos[b] < pos[ans[a]]) ans[a] = b;
}
void check(int x, int i) {
auto it = lower_bound(st[x].begin(), st[x].end(), pair<int, int> {y[i], -2e9});
int cnt = 5;
while (it != st[x].end()) {
update(i, (*it).second);
cnt--;
it++;
if (!cnt) break;
}
it = lower_bound(st[x].begin(), st[x].end(), pair<int, int> {y[i], -2e9});
if (it == st[x].begin()) return;
--it;
cnt = 5;
while (true) {
update(i, (*it).second);
if (it == st[x].begin()) break;
cnt--;
it--;
if (!cnt) break;
}
}
void query(int x, int lx, int rx, int p, int i) {
check(x, i);
if (lx == rx) return;
int mx = (lx + rx) >> 1;
if (p <= mx) query(x << 1, lx, mx, p, i);
else query(x << 1 | 1, mx + 1, rx, p, i);
}
void testCase() {
int n;
cin >> n;
vector<int> all;
for (int i = 0; i < n; i++) {
cin >> x[i] >> y[i] >> r[i];
all.push_back(x[i] - r[i]);
all.push_back(x[i] + r[i]);
}
vector<int> ord(n);
iota(ord.begin(), ord.end(), 0);
sort(ord.begin(), ord.end(), [&](int i, int j) {
if (r[i] != r[j]) return r[i] > r[j];
return i < j;
});
for (int i = 0; i < n; i++) {
pos[ord[i]] = i;
}
sort(all.begin(), all.end());
all.erase(unique(all.begin(), all.end()), all.end());
int N = all.size();
for (int i = 0; i < n; i++) ans[i] = i;
for (int i = 0; i < n; i++) {
int ii = ord[i];
int L = lower_bound(all.begin(), all.end(), x[ii] - r[ii]) - all.begin() + 1;
int R = lower_bound(all.begin(), all.end(), x[ii] + r[ii]) - all.begin() + 1;
query(1, 1, N, L, ii);
query(1, 1, N, R, ii);
if (ans[ii] == ii) {
update(1, 1, N, L, R, ii);
}
}
for (int i = 0; i < n; i++) cout << ans[i] + 1 << " ";
cout << "\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
testCase();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
113036 KB |
Output is correct |
2 |
Correct |
30 ms |
112984 KB |
Output is correct |
3 |
Correct |
29 ms |
112988 KB |
Output is correct |
4 |
Correct |
28 ms |
112984 KB |
Output is correct |
5 |
Correct |
29 ms |
113184 KB |
Output is correct |
6 |
Correct |
30 ms |
112976 KB |
Output is correct |
7 |
Correct |
33 ms |
112984 KB |
Output is correct |
8 |
Correct |
28 ms |
112988 KB |
Output is correct |
9 |
Correct |
29 ms |
112984 KB |
Output is correct |
10 |
Correct |
31 ms |
113204 KB |
Output is correct |
11 |
Correct |
33 ms |
113200 KB |
Output is correct |
12 |
Correct |
29 ms |
112976 KB |
Output is correct |
13 |
Correct |
30 ms |
112988 KB |
Output is correct |
14 |
Correct |
28 ms |
112988 KB |
Output is correct |
15 |
Correct |
30 ms |
112984 KB |
Output is correct |
16 |
Correct |
30 ms |
113160 KB |
Output is correct |
17 |
Correct |
34 ms |
113200 KB |
Output is correct |
18 |
Correct |
30 ms |
113240 KB |
Output is correct |
19 |
Correct |
36 ms |
113336 KB |
Output is correct |
20 |
Correct |
35 ms |
113500 KB |
Output is correct |
21 |
Correct |
37 ms |
113340 KB |
Output is correct |
22 |
Correct |
37 ms |
114004 KB |
Output is correct |
23 |
Correct |
48 ms |
114748 KB |
Output is correct |
24 |
Correct |
35 ms |
114012 KB |
Output is correct |
25 |
Correct |
37 ms |
113816 KB |
Output is correct |
26 |
Correct |
38 ms |
113744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
741 ms |
128460 KB |
Output is correct |
2 |
Correct |
723 ms |
131304 KB |
Output is correct |
3 |
Correct |
755 ms |
131272 KB |
Output is correct |
4 |
Correct |
798 ms |
131608 KB |
Output is correct |
5 |
Correct |
602 ms |
130336 KB |
Output is correct |
6 |
Correct |
709 ms |
140420 KB |
Output is correct |
7 |
Correct |
736 ms |
132180 KB |
Output is correct |
8 |
Correct |
760 ms |
134120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
28 ms |
112984 KB |
Output is correct |
2 |
Correct |
585 ms |
141260 KB |
Output is correct |
3 |
Correct |
1969 ms |
195480 KB |
Output is correct |
4 |
Correct |
1901 ms |
198620 KB |
Output is correct |
5 |
Execution timed out |
3050 ms |
192164 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1310 ms |
188808 KB |
Output is correct |
2 |
Correct |
628 ms |
153600 KB |
Output is correct |
3 |
Execution timed out |
3089 ms |
138888 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
113036 KB |
Output is correct |
2 |
Correct |
30 ms |
112984 KB |
Output is correct |
3 |
Correct |
29 ms |
112988 KB |
Output is correct |
4 |
Correct |
28 ms |
112984 KB |
Output is correct |
5 |
Correct |
29 ms |
113184 KB |
Output is correct |
6 |
Correct |
30 ms |
112976 KB |
Output is correct |
7 |
Correct |
33 ms |
112984 KB |
Output is correct |
8 |
Correct |
28 ms |
112988 KB |
Output is correct |
9 |
Correct |
29 ms |
112984 KB |
Output is correct |
10 |
Correct |
31 ms |
113204 KB |
Output is correct |
11 |
Correct |
33 ms |
113200 KB |
Output is correct |
12 |
Correct |
29 ms |
112976 KB |
Output is correct |
13 |
Correct |
30 ms |
112988 KB |
Output is correct |
14 |
Correct |
28 ms |
112988 KB |
Output is correct |
15 |
Correct |
30 ms |
112984 KB |
Output is correct |
16 |
Correct |
30 ms |
113160 KB |
Output is correct |
17 |
Correct |
34 ms |
113200 KB |
Output is correct |
18 |
Correct |
30 ms |
113240 KB |
Output is correct |
19 |
Correct |
36 ms |
113336 KB |
Output is correct |
20 |
Correct |
35 ms |
113500 KB |
Output is correct |
21 |
Correct |
37 ms |
113340 KB |
Output is correct |
22 |
Correct |
37 ms |
114004 KB |
Output is correct |
23 |
Correct |
48 ms |
114748 KB |
Output is correct |
24 |
Correct |
35 ms |
114012 KB |
Output is correct |
25 |
Correct |
37 ms |
113816 KB |
Output is correct |
26 |
Correct |
38 ms |
113744 KB |
Output is correct |
27 |
Correct |
41 ms |
113756 KB |
Output is correct |
28 |
Correct |
48 ms |
113748 KB |
Output is correct |
29 |
Correct |
41 ms |
113844 KB |
Output is correct |
30 |
Correct |
51 ms |
115652 KB |
Output is correct |
31 |
Correct |
44 ms |
114780 KB |
Output is correct |
32 |
Correct |
47 ms |
114776 KB |
Output is correct |
33 |
Correct |
175 ms |
119756 KB |
Output is correct |
34 |
Correct |
190 ms |
119756 KB |
Output is correct |
35 |
Correct |
231 ms |
119408 KB |
Output is correct |
36 |
Correct |
262 ms |
132300 KB |
Output is correct |
37 |
Correct |
328 ms |
132644 KB |
Output is correct |
38 |
Correct |
316 ms |
134872 KB |
Output is correct |
39 |
Correct |
1093 ms |
121132 KB |
Output is correct |
40 |
Correct |
1107 ms |
123816 KB |
Output is correct |
41 |
Correct |
1087 ms |
123852 KB |
Output is correct |
42 |
Correct |
799 ms |
124192 KB |
Output is correct |
43 |
Correct |
232 ms |
126372 KB |
Output is correct |
44 |
Correct |
240 ms |
126492 KB |
Output is correct |
45 |
Correct |
211 ms |
126448 KB |
Output is correct |
46 |
Correct |
226 ms |
126392 KB |
Output is correct |
47 |
Correct |
225 ms |
126308 KB |
Output is correct |
48 |
Correct |
200 ms |
129220 KB |
Output is correct |
49 |
Correct |
208 ms |
129148 KB |
Output is correct |
50 |
Correct |
222 ms |
126416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
113036 KB |
Output is correct |
2 |
Correct |
30 ms |
112984 KB |
Output is correct |
3 |
Correct |
29 ms |
112988 KB |
Output is correct |
4 |
Correct |
28 ms |
112984 KB |
Output is correct |
5 |
Correct |
29 ms |
113184 KB |
Output is correct |
6 |
Correct |
30 ms |
112976 KB |
Output is correct |
7 |
Correct |
33 ms |
112984 KB |
Output is correct |
8 |
Correct |
28 ms |
112988 KB |
Output is correct |
9 |
Correct |
29 ms |
112984 KB |
Output is correct |
10 |
Correct |
31 ms |
113204 KB |
Output is correct |
11 |
Correct |
33 ms |
113200 KB |
Output is correct |
12 |
Correct |
29 ms |
112976 KB |
Output is correct |
13 |
Correct |
30 ms |
112988 KB |
Output is correct |
14 |
Correct |
28 ms |
112988 KB |
Output is correct |
15 |
Correct |
30 ms |
112984 KB |
Output is correct |
16 |
Correct |
30 ms |
113160 KB |
Output is correct |
17 |
Correct |
34 ms |
113200 KB |
Output is correct |
18 |
Correct |
30 ms |
113240 KB |
Output is correct |
19 |
Correct |
36 ms |
113336 KB |
Output is correct |
20 |
Correct |
35 ms |
113500 KB |
Output is correct |
21 |
Correct |
37 ms |
113340 KB |
Output is correct |
22 |
Correct |
37 ms |
114004 KB |
Output is correct |
23 |
Correct |
48 ms |
114748 KB |
Output is correct |
24 |
Correct |
35 ms |
114012 KB |
Output is correct |
25 |
Correct |
37 ms |
113816 KB |
Output is correct |
26 |
Correct |
38 ms |
113744 KB |
Output is correct |
27 |
Correct |
741 ms |
128460 KB |
Output is correct |
28 |
Correct |
723 ms |
131304 KB |
Output is correct |
29 |
Correct |
755 ms |
131272 KB |
Output is correct |
30 |
Correct |
798 ms |
131608 KB |
Output is correct |
31 |
Correct |
602 ms |
130336 KB |
Output is correct |
32 |
Correct |
709 ms |
140420 KB |
Output is correct |
33 |
Correct |
736 ms |
132180 KB |
Output is correct |
34 |
Correct |
760 ms |
134120 KB |
Output is correct |
35 |
Correct |
28 ms |
112984 KB |
Output is correct |
36 |
Correct |
585 ms |
141260 KB |
Output is correct |
37 |
Correct |
1969 ms |
195480 KB |
Output is correct |
38 |
Correct |
1901 ms |
198620 KB |
Output is correct |
39 |
Execution timed out |
3050 ms |
192164 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |