#include <bits/stdc++.h>
using namespace std;
const int N = 4e6;
int root, ls[N], rs[N], tsz;
set<pair<int, int>> st[N];
vector<int> qv;
void Insert(int& x, int l, int r, int i, pair<int, int> v) {
if (!x) {
x = ++tsz;
}
st[x].insert(v);
if (l == r) {
return;
}
int mid = l + r >> 1;
if (i <= mid) {
Insert(ls[x], l, mid, i, v);
} else {
Insert(rs[x], mid + 1, r, i, v);
}
}
void Delete(int& x, int l, int r, int i, pair<int, int> v) {
if (!x) {
x = ++tsz;
}
st[x].erase(v);
if (l == r) {
return;
}
int mid = l + r >> 1;
if (i <= mid) {
Delete(ls[x], l, mid, i, v);
} else {
Delete(rs[x], mid + 1, r, i, v);
}
}
void Query(int& x, int l, int r, int ll, int rr, int L, int R) {
if (!x) {
x = ++tsz;
}
if (ll <= l && r <= rr) {
auto it = st[x].lower_bound({L, -1});
while (it != st[x].end() && it->first <= R) {
qv.push_back(it->second);
it = next(it);
}
return;
}
int mid = l + r >> 1;
if (rr <= mid) {
Query(ls[x], l, mid, ll, rr, L, R);
} else if (ll > mid) {
Query(rs[x], mid + 1, r, ll, rr, L, R);
} else {
Query(ls[x], l, mid, ll, rr, L, R);
Query(rs[x], mid + 1, r, ll, rr, L, R);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> 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<int> 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(root, 0, k - 1, p, make_pair(y[i], i));
}
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(root, 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(root, 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(root, 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<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 Delete(int&, int, int, int, std::pair<int, int>)':
circle_selection.cpp:35:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
35 | int mid = l + r >> 1;
| ~~^~~
circle_selection.cpp: In function 'void Query(int&, int, int, int, int, int, int)':
circle_selection.cpp:55:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
55 | int mid = l + r >> 1;
| ~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
189392 KB |
Output is correct |
2 |
Correct |
36 ms |
189516 KB |
Output is correct |
3 |
Correct |
36 ms |
189272 KB |
Output is correct |
4 |
Correct |
36 ms |
189300 KB |
Output is correct |
5 |
Correct |
40 ms |
189268 KB |
Output is correct |
6 |
Runtime error |
208 ms |
415340 KB |
Execution killed with signal 11 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3061 ms |
507248 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
189264 KB |
Output is correct |
2 |
Correct |
1960 ms |
289256 KB |
Output is correct |
3 |
Execution timed out |
3080 ms |
469524 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3102 ms |
468372 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
189392 KB |
Output is correct |
2 |
Correct |
36 ms |
189516 KB |
Output is correct |
3 |
Correct |
36 ms |
189272 KB |
Output is correct |
4 |
Correct |
36 ms |
189300 KB |
Output is correct |
5 |
Correct |
40 ms |
189268 KB |
Output is correct |
6 |
Runtime error |
208 ms |
415340 KB |
Execution killed with signal 11 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
189392 KB |
Output is correct |
2 |
Correct |
36 ms |
189516 KB |
Output is correct |
3 |
Correct |
36 ms |
189272 KB |
Output is correct |
4 |
Correct |
36 ms |
189300 KB |
Output is correct |
5 |
Correct |
40 ms |
189268 KB |
Output is correct |
6 |
Runtime error |
208 ms |
415340 KB |
Execution killed with signal 11 |
7 |
Halted |
0 ms |
0 KB |
- |