#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 = 2;
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 = 2;
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 |
37 ms |
117332 KB |
Output is correct |
2 |
Correct |
36 ms |
113060 KB |
Output is correct |
3 |
Correct |
42 ms |
112988 KB |
Output is correct |
4 |
Correct |
35 ms |
113068 KB |
Output is correct |
5 |
Correct |
37 ms |
113440 KB |
Output is correct |
6 |
Correct |
37 ms |
113164 KB |
Output is correct |
7 |
Correct |
37 ms |
112988 KB |
Output is correct |
8 |
Correct |
26 ms |
117592 KB |
Output is correct |
9 |
Correct |
34 ms |
113196 KB |
Output is correct |
10 |
Correct |
36 ms |
112980 KB |
Output is correct |
11 |
Correct |
25 ms |
117592 KB |
Output is correct |
12 |
Correct |
38 ms |
113196 KB |
Output is correct |
13 |
Correct |
32 ms |
112988 KB |
Output is correct |
14 |
Correct |
26 ms |
117592 KB |
Output is correct |
15 |
Correct |
48 ms |
112976 KB |
Output is correct |
16 |
Correct |
25 ms |
117596 KB |
Output is correct |
17 |
Correct |
47 ms |
113192 KB |
Output is correct |
18 |
Correct |
25 ms |
117592 KB |
Output is correct |
19 |
Correct |
49 ms |
113708 KB |
Output is correct |
20 |
Correct |
40 ms |
113500 KB |
Output is correct |
21 |
Correct |
31 ms |
117804 KB |
Output is correct |
22 |
Correct |
36 ms |
118352 KB |
Output is correct |
23 |
Correct |
41 ms |
118820 KB |
Output is correct |
24 |
Correct |
32 ms |
118108 KB |
Output is correct |
25 |
Correct |
39 ms |
118196 KB |
Output is correct |
26 |
Correct |
35 ms |
118096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
691 ms |
128568 KB |
Output is correct |
2 |
Correct |
687 ms |
129216 KB |
Output is correct |
3 |
Correct |
704 ms |
128688 KB |
Output is correct |
4 |
Correct |
719 ms |
129300 KB |
Output is correct |
5 |
Correct |
612 ms |
128244 KB |
Output is correct |
6 |
Correct |
675 ms |
139712 KB |
Output is correct |
7 |
Correct |
726 ms |
130108 KB |
Output is correct |
8 |
Correct |
680 ms |
132100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
117328 KB |
Output is correct |
2 |
Correct |
507 ms |
144176 KB |
Output is correct |
3 |
Correct |
2011 ms |
196120 KB |
Output is correct |
4 |
Correct |
1916 ms |
195516 KB |
Output is correct |
5 |
Execution timed out |
3022 ms |
184620 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1241 ms |
183136 KB |
Output is correct |
2 |
Correct |
604 ms |
146840 KB |
Output is correct |
3 |
Correct |
2846 ms |
133144 KB |
Output is correct |
4 |
Correct |
653 ms |
158956 KB |
Output is correct |
5 |
Correct |
649 ms |
156348 KB |
Output is correct |
6 |
Correct |
2208 ms |
134116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
117332 KB |
Output is correct |
2 |
Correct |
36 ms |
113060 KB |
Output is correct |
3 |
Correct |
42 ms |
112988 KB |
Output is correct |
4 |
Correct |
35 ms |
113068 KB |
Output is correct |
5 |
Correct |
37 ms |
113440 KB |
Output is correct |
6 |
Correct |
37 ms |
113164 KB |
Output is correct |
7 |
Correct |
37 ms |
112988 KB |
Output is correct |
8 |
Correct |
26 ms |
117592 KB |
Output is correct |
9 |
Correct |
34 ms |
113196 KB |
Output is correct |
10 |
Correct |
36 ms |
112980 KB |
Output is correct |
11 |
Correct |
25 ms |
117592 KB |
Output is correct |
12 |
Correct |
38 ms |
113196 KB |
Output is correct |
13 |
Correct |
32 ms |
112988 KB |
Output is correct |
14 |
Correct |
26 ms |
117592 KB |
Output is correct |
15 |
Correct |
48 ms |
112976 KB |
Output is correct |
16 |
Correct |
25 ms |
117596 KB |
Output is correct |
17 |
Correct |
47 ms |
113192 KB |
Output is correct |
18 |
Correct |
25 ms |
117592 KB |
Output is correct |
19 |
Correct |
49 ms |
113708 KB |
Output is correct |
20 |
Correct |
40 ms |
113500 KB |
Output is correct |
21 |
Correct |
31 ms |
117804 KB |
Output is correct |
22 |
Correct |
36 ms |
118352 KB |
Output is correct |
23 |
Correct |
41 ms |
118820 KB |
Output is correct |
24 |
Correct |
32 ms |
118108 KB |
Output is correct |
25 |
Correct |
39 ms |
118196 KB |
Output is correct |
26 |
Correct |
35 ms |
118096 KB |
Output is correct |
27 |
Correct |
36 ms |
117840 KB |
Output is correct |
28 |
Correct |
36 ms |
117844 KB |
Output is correct |
29 |
Correct |
36 ms |
117852 KB |
Output is correct |
30 |
Correct |
45 ms |
119644 KB |
Output is correct |
31 |
Correct |
42 ms |
118872 KB |
Output is correct |
32 |
Correct |
39 ms |
118864 KB |
Output is correct |
33 |
Correct |
173 ms |
119756 KB |
Output is correct |
34 |
Correct |
179 ms |
119532 KB |
Output is correct |
35 |
Correct |
184 ms |
119700 KB |
Output is correct |
36 |
Correct |
267 ms |
132728 KB |
Output is correct |
37 |
Correct |
278 ms |
133068 KB |
Output is correct |
38 |
Correct |
316 ms |
135540 KB |
Output is correct |
39 |
Correct |
996 ms |
122504 KB |
Output is correct |
40 |
Correct |
991 ms |
122496 KB |
Output is correct |
41 |
Correct |
995 ms |
122796 KB |
Output is correct |
42 |
Correct |
688 ms |
122492 KB |
Output is correct |
43 |
Correct |
195 ms |
126924 KB |
Output is correct |
44 |
Correct |
207 ms |
126988 KB |
Output is correct |
45 |
Correct |
189 ms |
126924 KB |
Output is correct |
46 |
Correct |
189 ms |
127044 KB |
Output is correct |
47 |
Correct |
199 ms |
127056 KB |
Output is correct |
48 |
Correct |
192 ms |
127068 KB |
Output is correct |
49 |
Correct |
210 ms |
127068 KB |
Output is correct |
50 |
Correct |
189 ms |
126992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
117332 KB |
Output is correct |
2 |
Correct |
36 ms |
113060 KB |
Output is correct |
3 |
Correct |
42 ms |
112988 KB |
Output is correct |
4 |
Correct |
35 ms |
113068 KB |
Output is correct |
5 |
Correct |
37 ms |
113440 KB |
Output is correct |
6 |
Correct |
37 ms |
113164 KB |
Output is correct |
7 |
Correct |
37 ms |
112988 KB |
Output is correct |
8 |
Correct |
26 ms |
117592 KB |
Output is correct |
9 |
Correct |
34 ms |
113196 KB |
Output is correct |
10 |
Correct |
36 ms |
112980 KB |
Output is correct |
11 |
Correct |
25 ms |
117592 KB |
Output is correct |
12 |
Correct |
38 ms |
113196 KB |
Output is correct |
13 |
Correct |
32 ms |
112988 KB |
Output is correct |
14 |
Correct |
26 ms |
117592 KB |
Output is correct |
15 |
Correct |
48 ms |
112976 KB |
Output is correct |
16 |
Correct |
25 ms |
117596 KB |
Output is correct |
17 |
Correct |
47 ms |
113192 KB |
Output is correct |
18 |
Correct |
25 ms |
117592 KB |
Output is correct |
19 |
Correct |
49 ms |
113708 KB |
Output is correct |
20 |
Correct |
40 ms |
113500 KB |
Output is correct |
21 |
Correct |
31 ms |
117804 KB |
Output is correct |
22 |
Correct |
36 ms |
118352 KB |
Output is correct |
23 |
Correct |
41 ms |
118820 KB |
Output is correct |
24 |
Correct |
32 ms |
118108 KB |
Output is correct |
25 |
Correct |
39 ms |
118196 KB |
Output is correct |
26 |
Correct |
35 ms |
118096 KB |
Output is correct |
27 |
Correct |
691 ms |
128568 KB |
Output is correct |
28 |
Correct |
687 ms |
129216 KB |
Output is correct |
29 |
Correct |
704 ms |
128688 KB |
Output is correct |
30 |
Correct |
719 ms |
129300 KB |
Output is correct |
31 |
Correct |
612 ms |
128244 KB |
Output is correct |
32 |
Correct |
675 ms |
139712 KB |
Output is correct |
33 |
Correct |
726 ms |
130108 KB |
Output is correct |
34 |
Correct |
680 ms |
132100 KB |
Output is correct |
35 |
Correct |
24 ms |
117328 KB |
Output is correct |
36 |
Correct |
507 ms |
144176 KB |
Output is correct |
37 |
Correct |
2011 ms |
196120 KB |
Output is correct |
38 |
Correct |
1916 ms |
195516 KB |
Output is correct |
39 |
Execution timed out |
3022 ms |
184620 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |