#include <bits/stdc++.h>
using namespace std;
const int MAX = 3e5;
const int N = 4e6;
long long x[MAX], y[MAX], r[MAX];
int res[MAX], len, cur;
vector<pair<long long, int>> vec[N];
vector<int> xs;
vector<int> mn[N];
vector<int> mx[N];
vector<int> fa[N];
vector<bool> rem[N];
void Insert(int i, pair<long long, int> v) {
vec[i + len].push_back(v);
}
void Build() {
for (int x = len; x < 2 * len; x++) {
sort(vec[x].begin(), vec[x].end());
int k = (int) vec[x].size();
mn[x] = vector<int>(k);
mx[x] = vector<int>(k);
fa[x] = vector<int>(k);
rem[x] = vector<bool>(k);
iota(mn[x].begin(), mn[x].end(), 0);
iota(mx[x].begin(), mx[x].end(), 0);
iota(fa[x].begin(), fa[x].end(), 0);
}
for (int x = len - 1; x >= 1; x--) {
int pl = 0, pr = 0;
while (pl < (int) vec[x << 1].size() || pr < (int) vec[x << 1 | 1].size()) {
if (pl == (int) vec[x << 1].size()) {
vec[x].push_back(vec[x << 1 | 1][pr++]);
} else if (pr == (int) vec[x << 1 | 1].size()) {
vec[x].push_back(vec[x << 1][pl++]);
} else if (vec[x << 1][pl] < vec[x << 1 | 1][pr]) {
vec[x].push_back(vec[x << 1][pl++]);
} else {
vec[x].push_back(vec[x << 1 | 1][pr++]);
}
}
int k = (int) vec[x].size();
mn[x] = vector<int>(k);
mx[x] = vector<int>(k);
fa[x] = vector<int>(k);
rem[x] = vector<bool>(k);
iota(mn[x].begin(), mn[x].end(), 0);
iota(mx[x].begin(), mx[x].end(), 0);
iota(fa[x].begin(), fa[x].end(), 0);
}
}
void Unite(int x, int a, int b) {
a = fa[x][a];
b = fa[x][b];
if (mx[x][a] - mn[x][a] > mx[x][b] - mn[x][b]) {
swap(a, b);
}
for (int i = mn[x][a]; i <= mx[x][a]; i++) {
fa[x][i] = b;
}
mx[x][b] = max(mx[x][b], mx[x][a]);
mn[x][b] = min(mn[x][b], mn[x][a]);
}
void Delete(int i, pair<long long, int> v) {
for (int x = i + len; x > 0; x >>= 1) {
int idx = (int) (lower_bound(vec[x].begin(), vec[x].end(), v) - vec[x].begin());
rem[x][idx] = true;
if (idx > 0 && rem[x][idx - 1]) {
Unite(x, idx - 1, idx);
}
if (idx + 1 < (int) vec[x].size() && rem[x][idx + 1]) {
Unite(x, idx, idx + 1);
}
}
}
void Check(int &idx) {
if ((x[cur] - x[idx]) * 1LL * (x[cur] - x[idx]) + (y[cur] - y[idx]) * 1LL * (y[cur] - y[idx]) <= (r[cur] + r[idx]) * 1LL * (r[cur] + r[idx])) {
res[idx] = cur;
Delete((int) (lower_bound(xs.begin(), xs.end(), x[idx]) - xs.begin()), make_pair(y[idx], idx));
}
}
void Add(int x, long long L, long long R) {
int idx = (int) (lower_bound(vec[x].begin(), vec[x].end(), make_pair(L, -1)) - vec[x].begin());
while (idx < (int) vec[x].size() && vec[x][idx].first <= R) {
if (rem[x][idx]) {
idx = mx[x][fa[x][idx]] + 1;
continue;
}
Check(vec[x][idx].second);
idx += 1;
}
}
void Query(int l, int r, long long L, long long R) {
for (l += len, r += len + 1; l < r; l >>= 1, r >>= 1) {
if (l & 1) {
Add(l++, L, R);
}
if (r & 1) {
Add(--r, L, R);
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> x[i] >> y[i] >> r[i];
}
vector<int> order(n);
iota(order.begin(), order.end(), 0);
sort(order.begin(), order.end(), [&](int i, int j) {
if (r[i] != r[j]) {
return r[i] > r[j];
} else {
return i < j;
}
});
for (int i = 0; i < n; i++) {
xs.push_back(x[i] - 2 * r[i]);
xs.push_back(x[i]);
xs.push_back(x[i] + 2 * r[i]);
}
sort(xs.begin(), xs.end());
xs.erase(unique(xs.begin(), xs.end()), xs.end());
int k = (int) xs.size();
len = 1;
while (len < k) {
len *= 2;
}
for (int i = 0; i < n; i++) {
res[i] = i;
int p = (int) (lower_bound(xs.begin(), xs.end(), x[i]) - xs.begin());
Insert(p, make_pair(y[i], i));
}
Build();
for (int i : order) {
if (res[i] != i) {
continue;
}
cur = i;
int p = (int) (lower_bound(xs.begin(), xs.end(), x[i]) - xs.begin());
Delete(p, make_pair(y[i], i));
int L = (int) (lower_bound(xs.begin(), xs.end(), x[i] - 2 * r[i]) - xs.begin());
int R = (int) (lower_bound(xs.begin(), xs.end(), x[i] + 2 * r[i]) - xs.begin());
Query(L, R, y[i] - 2 * r[i], y[i] + 2 * r[i]);
}
for (int i = 0; i < n; i++) {
cout << res[i] + 1 << " ";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
198 ms |
534156 KB |
Output is correct |
2 |
Correct |
151 ms |
534100 KB |
Output is correct |
3 |
Correct |
146 ms |
534100 KB |
Output is correct |
4 |
Correct |
146 ms |
534016 KB |
Output is correct |
5 |
Correct |
152 ms |
534104 KB |
Output is correct |
6 |
Correct |
149 ms |
534096 KB |
Output is correct |
7 |
Correct |
134 ms |
534132 KB |
Output is correct |
8 |
Correct |
138 ms |
534292 KB |
Output is correct |
9 |
Correct |
135 ms |
534100 KB |
Output is correct |
10 |
Correct |
133 ms |
533976 KB |
Output is correct |
11 |
Correct |
132 ms |
534228 KB |
Output is correct |
12 |
Correct |
138 ms |
534120 KB |
Output is correct |
13 |
Correct |
133 ms |
534100 KB |
Output is correct |
14 |
Correct |
135 ms |
534228 KB |
Output is correct |
15 |
Correct |
133 ms |
534156 KB |
Output is correct |
16 |
Correct |
141 ms |
534864 KB |
Output is correct |
17 |
Correct |
136 ms |
534864 KB |
Output is correct |
18 |
Correct |
134 ms |
534864 KB |
Output is correct |
19 |
Correct |
157 ms |
537976 KB |
Output is correct |
20 |
Correct |
142 ms |
537840 KB |
Output is correct |
21 |
Correct |
144 ms |
537784 KB |
Output is correct |
22 |
Correct |
145 ms |
542800 KB |
Output is correct |
23 |
Correct |
137 ms |
542800 KB |
Output is correct |
24 |
Correct |
134 ms |
542808 KB |
Output is correct |
25 |
Correct |
147 ms |
543056 KB |
Output is correct |
26 |
Correct |
134 ms |
542804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1867 ms |
848832 KB |
Output is correct |
2 |
Correct |
1925 ms |
852020 KB |
Output is correct |
3 |
Correct |
1914 ms |
848880 KB |
Output is correct |
4 |
Correct |
1879 ms |
852068 KB |
Output is correct |
5 |
Correct |
2070 ms |
791664 KB |
Output is correct |
6 |
Execution timed out |
3056 ms |
869016 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
117 ms |
538192 KB |
Output is correct |
2 |
Correct |
1122 ms |
647272 KB |
Output is correct |
3 |
Execution timed out |
3041 ms |
873520 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3050 ms |
870896 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
198 ms |
534156 KB |
Output is correct |
2 |
Correct |
151 ms |
534100 KB |
Output is correct |
3 |
Correct |
146 ms |
534100 KB |
Output is correct |
4 |
Correct |
146 ms |
534016 KB |
Output is correct |
5 |
Correct |
152 ms |
534104 KB |
Output is correct |
6 |
Correct |
149 ms |
534096 KB |
Output is correct |
7 |
Correct |
134 ms |
534132 KB |
Output is correct |
8 |
Correct |
138 ms |
534292 KB |
Output is correct |
9 |
Correct |
135 ms |
534100 KB |
Output is correct |
10 |
Correct |
133 ms |
533976 KB |
Output is correct |
11 |
Correct |
132 ms |
534228 KB |
Output is correct |
12 |
Correct |
138 ms |
534120 KB |
Output is correct |
13 |
Correct |
133 ms |
534100 KB |
Output is correct |
14 |
Correct |
135 ms |
534228 KB |
Output is correct |
15 |
Correct |
133 ms |
534156 KB |
Output is correct |
16 |
Correct |
141 ms |
534864 KB |
Output is correct |
17 |
Correct |
136 ms |
534864 KB |
Output is correct |
18 |
Correct |
134 ms |
534864 KB |
Output is correct |
19 |
Correct |
157 ms |
537976 KB |
Output is correct |
20 |
Correct |
142 ms |
537840 KB |
Output is correct |
21 |
Correct |
144 ms |
537784 KB |
Output is correct |
22 |
Correct |
145 ms |
542800 KB |
Output is correct |
23 |
Correct |
137 ms |
542800 KB |
Output is correct |
24 |
Correct |
134 ms |
542808 KB |
Output is correct |
25 |
Correct |
147 ms |
543056 KB |
Output is correct |
26 |
Correct |
134 ms |
542804 KB |
Output is correct |
27 |
Correct |
145 ms |
546444 KB |
Output is correct |
28 |
Correct |
141 ms |
546428 KB |
Output is correct |
29 |
Correct |
144 ms |
546548 KB |
Output is correct |
30 |
Correct |
157 ms |
547764 KB |
Output is correct |
31 |
Correct |
163 ms |
547876 KB |
Output is correct |
32 |
Correct |
164 ms |
547920 KB |
Output is correct |
33 |
Correct |
595 ms |
630988 KB |
Output is correct |
34 |
Correct |
601 ms |
637300 KB |
Output is correct |
35 |
Correct |
624 ms |
640160 KB |
Output is correct |
36 |
Correct |
1088 ms |
648156 KB |
Output is correct |
37 |
Correct |
1121 ms |
648044 KB |
Output is correct |
38 |
Correct |
1062 ms |
647852 KB |
Output is correct |
39 |
Correct |
565 ms |
577484 KB |
Output is correct |
40 |
Correct |
526 ms |
577412 KB |
Output is correct |
41 |
Correct |
549 ms |
577348 KB |
Output is correct |
42 |
Correct |
512 ms |
585396 KB |
Output is correct |
43 |
Correct |
971 ms |
651356 KB |
Output is correct |
44 |
Correct |
983 ms |
651380 KB |
Output is correct |
45 |
Correct |
1008 ms |
651620 KB |
Output is correct |
46 |
Correct |
972 ms |
651492 KB |
Output is correct |
47 |
Correct |
934 ms |
651456 KB |
Output is correct |
48 |
Correct |
979 ms |
651356 KB |
Output is correct |
49 |
Correct |
963 ms |
651724 KB |
Output is correct |
50 |
Correct |
961 ms |
651464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
198 ms |
534156 KB |
Output is correct |
2 |
Correct |
151 ms |
534100 KB |
Output is correct |
3 |
Correct |
146 ms |
534100 KB |
Output is correct |
4 |
Correct |
146 ms |
534016 KB |
Output is correct |
5 |
Correct |
152 ms |
534104 KB |
Output is correct |
6 |
Correct |
149 ms |
534096 KB |
Output is correct |
7 |
Correct |
134 ms |
534132 KB |
Output is correct |
8 |
Correct |
138 ms |
534292 KB |
Output is correct |
9 |
Correct |
135 ms |
534100 KB |
Output is correct |
10 |
Correct |
133 ms |
533976 KB |
Output is correct |
11 |
Correct |
132 ms |
534228 KB |
Output is correct |
12 |
Correct |
138 ms |
534120 KB |
Output is correct |
13 |
Correct |
133 ms |
534100 KB |
Output is correct |
14 |
Correct |
135 ms |
534228 KB |
Output is correct |
15 |
Correct |
133 ms |
534156 KB |
Output is correct |
16 |
Correct |
141 ms |
534864 KB |
Output is correct |
17 |
Correct |
136 ms |
534864 KB |
Output is correct |
18 |
Correct |
134 ms |
534864 KB |
Output is correct |
19 |
Correct |
157 ms |
537976 KB |
Output is correct |
20 |
Correct |
142 ms |
537840 KB |
Output is correct |
21 |
Correct |
144 ms |
537784 KB |
Output is correct |
22 |
Correct |
145 ms |
542800 KB |
Output is correct |
23 |
Correct |
137 ms |
542800 KB |
Output is correct |
24 |
Correct |
134 ms |
542808 KB |
Output is correct |
25 |
Correct |
147 ms |
543056 KB |
Output is correct |
26 |
Correct |
134 ms |
542804 KB |
Output is correct |
27 |
Correct |
1867 ms |
848832 KB |
Output is correct |
28 |
Correct |
1925 ms |
852020 KB |
Output is correct |
29 |
Correct |
1914 ms |
848880 KB |
Output is correct |
30 |
Correct |
1879 ms |
852068 KB |
Output is correct |
31 |
Correct |
2070 ms |
791664 KB |
Output is correct |
32 |
Execution timed out |
3056 ms |
869016 KB |
Time limit exceeded |
33 |
Halted |
0 ms |
0 KB |
- |