#include <bits/stdc++.h>
using namespace std;
const int N = 4e6;
vector<pair<long long, int>> vec[N];
vector<int> qv;
vector<int> sz[N];
vector<int> mx[N];
vector<int> fa[N];
vector<bool> rem[N];
void Insert(int x, int l, int r, int i, pair<long long, int> v) {
vec[x].push_back(v);
if (l == r) {
return;
}
int mid = l + r >> 1;
if (i <= mid) {
Insert(x << 1, l, mid, i, v);
} else {
Insert(x << 1 | 1, mid + 1, r, i, v);
}
}
void Build(int x, int l, int r) {
sort(vec[x].begin(), vec[x].end());
int k = (int) vec[x].size();
sz[x] = vector<int>(k, 1);
mx[x] = vector<int>(k);
fa[x] = vector<int>(k);
rem[x] = vector<bool>(k);
iota(mx[x].begin(), mx[x].end(), 0);
iota(fa[x].begin(), fa[x].end(), 0);
if (l == r) {
return;
}
int mid = l + r >> 1;
Build(x << 1, l, mid);
Build(x << 1 | 1, mid + 1, r);
}
int GetPar(int x, int a) {
return fa[x][a] == a ? a : fa[x][a] = GetPar(x, fa[x][a]);
}
void Unite(int x, int a, int b) {
a = GetPar(x, a);
b = GetPar(x, b);
if (a == b) {
return;
}
if (sz[x][a] > sz[x][b]) {
swap(sz[x][a], sz[x][b]);
}
sz[x][b] += sz[x][a];
mx[x][b] = max(mx[x][b], mx[x][a]);
fa[x][a] = b;
}
void Delete(int x, int l, int r, int i, pair<long long, int> v) {
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);
}
if (l == r) {
return;
}
int mid = l + r >> 1;
if (i <= mid) {
Delete(x << 1, l, mid, i, v);
} else {
Delete(x << 1 | 1, mid + 1, r, i, v);
}
}
void Query(int x, int l, int r, int ll, int rr, long long L, long long R) {
if (ll <= l && r <= rr) {
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][GetPar(x, idx)] + 1;
continue;
}
qv.push_back(vec[x][idx].second);
idx += 1;
}
return;
}
int mid = l + r >> 1;
if (rr <= mid) {
Query(x << 1, l, mid, ll, rr, L, R);
} else if (ll > mid) {
Query(x << 1 | 1, mid + 1, r, ll, rr, L, R);
} else {
Query(x << 1, l, mid, ll, rr, L, R);
Query(x << 1 | 1, mid + 1, r, ll, rr, L, R);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<long long> x(n), y(n), r(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;
}
});
vector<long long> xs;
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();
vector<int> res(n);
for (int i = 0; i < n; i++) {
res[i] = i;
int p = (int) (lower_bound(xs.begin(), xs.end(), x[i]) - xs.begin());
Insert(1, 0, k - 1, p, make_pair(y[i], i));
}
Build(1, 0, k - 1);
for (int i : order) {
if (res[i] != i) {
continue;
}
qv.clear();
int p = (int) (lower_bound(xs.begin(), xs.end(), x[i]) - xs.begin());
Delete(1, 0, k - 1, 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(1, 0, k - 1, L, R, y[i] - 2 * r[i], y[i] + 2 * r[i]);
for (int j : qv) {
if ((x[i] - x[j]) * 1LL * (x[i] - x[j]) + (y[i] - y[j]) * 1LL * (y[i] - y[j]) <= (r[i] + r[j]) * 1LL * (r[i] + r[j])) {
res[j] = i;
Delete(1, 0, k - 1, (int) (lower_bound(xs.begin(), xs.end(), x[j]) - xs.begin()), make_pair(y[j], j));
}
}
}
for (int i = 0; i < n; i++) {
cout << res[i] + 1 << " ";
}
return 0;
}
Compilation message
circle_selection.cpp: In function 'void Insert(int, int, int, int, std::pair<long long int, int>)':
circle_selection.cpp:19:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
19 | int mid = l + r >> 1;
| ~~^~~
circle_selection.cpp: In function 'void Build(int, int, int)':
circle_selection.cpp:39:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
39 | int mid = l + r >> 1;
| ~~^~~
circle_selection.cpp: In function 'void Delete(int, int, int, int, std::pair<long long int, int>)':
circle_selection.cpp:74:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
74 | int mid = l + r >> 1;
| ~~^~~
circle_selection.cpp: In function 'void Query(int, int, int, int, int, long long int, long long int)':
circle_selection.cpp:95:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
95 | int mid = l + r >> 1;
| ~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
164 ms |
532696 KB |
Output is correct |
2 |
Correct |
111 ms |
532828 KB |
Output is correct |
3 |
Correct |
110 ms |
532568 KB |
Output is correct |
4 |
Correct |
112 ms |
532560 KB |
Output is correct |
5 |
Correct |
112 ms |
532904 KB |
Output is correct |
6 |
Correct |
110 ms |
532560 KB |
Output is correct |
7 |
Correct |
112 ms |
532564 KB |
Output is correct |
8 |
Correct |
109 ms |
532628 KB |
Output is correct |
9 |
Correct |
110 ms |
532544 KB |
Output is correct |
10 |
Correct |
110 ms |
532732 KB |
Output is correct |
11 |
Correct |
113 ms |
532564 KB |
Output is correct |
12 |
Correct |
111 ms |
532688 KB |
Output is correct |
13 |
Correct |
111 ms |
532636 KB |
Output is correct |
14 |
Correct |
117 ms |
532728 KB |
Output is correct |
15 |
Correct |
111 ms |
532728 KB |
Output is correct |
16 |
Correct |
113 ms |
533456 KB |
Output is correct |
17 |
Correct |
113 ms |
533332 KB |
Output is correct |
18 |
Correct |
114 ms |
533412 KB |
Output is correct |
19 |
Correct |
128 ms |
536404 KB |
Output is correct |
20 |
Correct |
129 ms |
536404 KB |
Output is correct |
21 |
Correct |
128 ms |
536588 KB |
Output is correct |
22 |
Correct |
136 ms |
537428 KB |
Output is correct |
23 |
Correct |
138 ms |
537168 KB |
Output is correct |
24 |
Correct |
136 ms |
537428 KB |
Output is correct |
25 |
Correct |
138 ms |
537548 KB |
Output is correct |
26 |
Correct |
138 ms |
537512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2517 ms |
857528 KB |
Output is correct |
2 |
Correct |
2563 ms |
857528 KB |
Output is correct |
3 |
Correct |
2541 ms |
856964 KB |
Output is correct |
4 |
Correct |
2458 ms |
848912 KB |
Output is correct |
5 |
Correct |
2483 ms |
808368 KB |
Output is correct |
6 |
Execution timed out |
3029 ms |
882032 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
111 ms |
532560 KB |
Output is correct |
2 |
Correct |
1377 ms |
639024 KB |
Output is correct |
3 |
Execution timed out |
3067 ms |
880560 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3075 ms |
878124 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
164 ms |
532696 KB |
Output is correct |
2 |
Correct |
111 ms |
532828 KB |
Output is correct |
3 |
Correct |
110 ms |
532568 KB |
Output is correct |
4 |
Correct |
112 ms |
532560 KB |
Output is correct |
5 |
Correct |
112 ms |
532904 KB |
Output is correct |
6 |
Correct |
110 ms |
532560 KB |
Output is correct |
7 |
Correct |
112 ms |
532564 KB |
Output is correct |
8 |
Correct |
109 ms |
532628 KB |
Output is correct |
9 |
Correct |
110 ms |
532544 KB |
Output is correct |
10 |
Correct |
110 ms |
532732 KB |
Output is correct |
11 |
Correct |
113 ms |
532564 KB |
Output is correct |
12 |
Correct |
111 ms |
532688 KB |
Output is correct |
13 |
Correct |
111 ms |
532636 KB |
Output is correct |
14 |
Correct |
117 ms |
532728 KB |
Output is correct |
15 |
Correct |
111 ms |
532728 KB |
Output is correct |
16 |
Correct |
113 ms |
533456 KB |
Output is correct |
17 |
Correct |
113 ms |
533332 KB |
Output is correct |
18 |
Correct |
114 ms |
533412 KB |
Output is correct |
19 |
Correct |
128 ms |
536404 KB |
Output is correct |
20 |
Correct |
129 ms |
536404 KB |
Output is correct |
21 |
Correct |
128 ms |
536588 KB |
Output is correct |
22 |
Correct |
136 ms |
537428 KB |
Output is correct |
23 |
Correct |
138 ms |
537168 KB |
Output is correct |
24 |
Correct |
136 ms |
537428 KB |
Output is correct |
25 |
Correct |
138 ms |
537548 KB |
Output is correct |
26 |
Correct |
138 ms |
537512 KB |
Output is correct |
27 |
Correct |
156 ms |
541348 KB |
Output is correct |
28 |
Correct |
152 ms |
541392 KB |
Output is correct |
29 |
Correct |
153 ms |
541644 KB |
Output is correct |
30 |
Correct |
169 ms |
542412 KB |
Output is correct |
31 |
Correct |
169 ms |
542780 KB |
Output is correct |
32 |
Correct |
173 ms |
542604 KB |
Output is correct |
33 |
Correct |
777 ms |
624432 KB |
Output is correct |
34 |
Correct |
790 ms |
627672 KB |
Output is correct |
35 |
Correct |
865 ms |
636084 KB |
Output is correct |
36 |
Correct |
1310 ms |
638956 KB |
Output is correct |
37 |
Correct |
1310 ms |
639236 KB |
Output is correct |
38 |
Correct |
1317 ms |
638656 KB |
Output is correct |
39 |
Correct |
600 ms |
576196 KB |
Output is correct |
40 |
Correct |
581 ms |
576244 KB |
Output is correct |
41 |
Correct |
591 ms |
574656 KB |
Output is correct |
42 |
Correct |
545 ms |
580292 KB |
Output is correct |
43 |
Correct |
1239 ms |
641476 KB |
Output is correct |
44 |
Correct |
1215 ms |
641216 KB |
Output is correct |
45 |
Correct |
1245 ms |
642676 KB |
Output is correct |
46 |
Correct |
1231 ms |
641388 KB |
Output is correct |
47 |
Correct |
1257 ms |
642864 KB |
Output is correct |
48 |
Correct |
1234 ms |
641352 KB |
Output is correct |
49 |
Correct |
1267 ms |
641996 KB |
Output is correct |
50 |
Correct |
1239 ms |
641408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
164 ms |
532696 KB |
Output is correct |
2 |
Correct |
111 ms |
532828 KB |
Output is correct |
3 |
Correct |
110 ms |
532568 KB |
Output is correct |
4 |
Correct |
112 ms |
532560 KB |
Output is correct |
5 |
Correct |
112 ms |
532904 KB |
Output is correct |
6 |
Correct |
110 ms |
532560 KB |
Output is correct |
7 |
Correct |
112 ms |
532564 KB |
Output is correct |
8 |
Correct |
109 ms |
532628 KB |
Output is correct |
9 |
Correct |
110 ms |
532544 KB |
Output is correct |
10 |
Correct |
110 ms |
532732 KB |
Output is correct |
11 |
Correct |
113 ms |
532564 KB |
Output is correct |
12 |
Correct |
111 ms |
532688 KB |
Output is correct |
13 |
Correct |
111 ms |
532636 KB |
Output is correct |
14 |
Correct |
117 ms |
532728 KB |
Output is correct |
15 |
Correct |
111 ms |
532728 KB |
Output is correct |
16 |
Correct |
113 ms |
533456 KB |
Output is correct |
17 |
Correct |
113 ms |
533332 KB |
Output is correct |
18 |
Correct |
114 ms |
533412 KB |
Output is correct |
19 |
Correct |
128 ms |
536404 KB |
Output is correct |
20 |
Correct |
129 ms |
536404 KB |
Output is correct |
21 |
Correct |
128 ms |
536588 KB |
Output is correct |
22 |
Correct |
136 ms |
537428 KB |
Output is correct |
23 |
Correct |
138 ms |
537168 KB |
Output is correct |
24 |
Correct |
136 ms |
537428 KB |
Output is correct |
25 |
Correct |
138 ms |
537548 KB |
Output is correct |
26 |
Correct |
138 ms |
537512 KB |
Output is correct |
27 |
Correct |
2517 ms |
857528 KB |
Output is correct |
28 |
Correct |
2563 ms |
857528 KB |
Output is correct |
29 |
Correct |
2541 ms |
856964 KB |
Output is correct |
30 |
Correct |
2458 ms |
848912 KB |
Output is correct |
31 |
Correct |
2483 ms |
808368 KB |
Output is correct |
32 |
Execution timed out |
3029 ms |
882032 KB |
Time limit exceeded |
33 |
Halted |
0 ms |
0 KB |
- |