#include <bits/stdc++.h>
using namespace std;
const int N = 4e6;
int root, ls[N], rs[N], tsz;
set<pair<long long, int>> st[N];
vector<int> qv;
void Insert(int& x, int l, int r, int i, pair<long long, 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<long long, 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, long long L, long long 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<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(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<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 Delete(int&, int, int, int, std::pair<long long 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, long long int, long long int)':
circle_selection.cpp:55:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
55 | int mid = l + r >> 1;
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
189268 KB |
Output is correct |
2 |
Correct |
36 ms |
189300 KB |
Output is correct |
3 |
Correct |
42 ms |
189400 KB |
Output is correct |
4 |
Correct |
38 ms |
189528 KB |
Output is correct |
5 |
Correct |
36 ms |
189404 KB |
Output is correct |
6 |
Correct |
36 ms |
189276 KB |
Output is correct |
7 |
Correct |
36 ms |
189396 KB |
Output is correct |
8 |
Correct |
38 ms |
189264 KB |
Output is correct |
9 |
Correct |
36 ms |
189264 KB |
Output is correct |
10 |
Correct |
41 ms |
189480 KB |
Output is correct |
11 |
Correct |
38 ms |
189276 KB |
Output is correct |
12 |
Correct |
36 ms |
189268 KB |
Output is correct |
13 |
Correct |
37 ms |
189268 KB |
Output is correct |
14 |
Correct |
36 ms |
189348 KB |
Output is correct |
15 |
Correct |
37 ms |
189408 KB |
Output is correct |
16 |
Correct |
39 ms |
190088 KB |
Output is correct |
17 |
Correct |
44 ms |
190412 KB |
Output is correct |
18 |
Correct |
40 ms |
190300 KB |
Output is correct |
19 |
Correct |
56 ms |
194388 KB |
Output is correct |
20 |
Correct |
56 ms |
194528 KB |
Output is correct |
21 |
Correct |
59 ms |
194416 KB |
Output is correct |
22 |
Correct |
61 ms |
194552 KB |
Output is correct |
23 |
Correct |
61 ms |
194388 KB |
Output is correct |
24 |
Correct |
61 ms |
194388 KB |
Output is correct |
25 |
Correct |
63 ms |
194412 KB |
Output is correct |
26 |
Correct |
73 ms |
194488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3066 ms |
591868 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
36 ms |
189272 KB |
Output is correct |
2 |
Correct |
2158 ms |
319764 KB |
Output is correct |
3 |
Execution timed out |
3081 ms |
517712 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3041 ms |
523324 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
189268 KB |
Output is correct |
2 |
Correct |
36 ms |
189300 KB |
Output is correct |
3 |
Correct |
42 ms |
189400 KB |
Output is correct |
4 |
Correct |
38 ms |
189528 KB |
Output is correct |
5 |
Correct |
36 ms |
189404 KB |
Output is correct |
6 |
Correct |
36 ms |
189276 KB |
Output is correct |
7 |
Correct |
36 ms |
189396 KB |
Output is correct |
8 |
Correct |
38 ms |
189264 KB |
Output is correct |
9 |
Correct |
36 ms |
189264 KB |
Output is correct |
10 |
Correct |
41 ms |
189480 KB |
Output is correct |
11 |
Correct |
38 ms |
189276 KB |
Output is correct |
12 |
Correct |
36 ms |
189268 KB |
Output is correct |
13 |
Correct |
37 ms |
189268 KB |
Output is correct |
14 |
Correct |
36 ms |
189348 KB |
Output is correct |
15 |
Correct |
37 ms |
189408 KB |
Output is correct |
16 |
Correct |
39 ms |
190088 KB |
Output is correct |
17 |
Correct |
44 ms |
190412 KB |
Output is correct |
18 |
Correct |
40 ms |
190300 KB |
Output is correct |
19 |
Correct |
56 ms |
194388 KB |
Output is correct |
20 |
Correct |
56 ms |
194528 KB |
Output is correct |
21 |
Correct |
59 ms |
194416 KB |
Output is correct |
22 |
Correct |
61 ms |
194552 KB |
Output is correct |
23 |
Correct |
61 ms |
194388 KB |
Output is correct |
24 |
Correct |
61 ms |
194388 KB |
Output is correct |
25 |
Correct |
63 ms |
194412 KB |
Output is correct |
26 |
Correct |
73 ms |
194488 KB |
Output is correct |
27 |
Correct |
100 ms |
200272 KB |
Output is correct |
28 |
Correct |
84 ms |
200400 KB |
Output is correct |
29 |
Correct |
84 ms |
200312 KB |
Output is correct |
30 |
Correct |
103 ms |
200332 KB |
Output is correct |
31 |
Correct |
99 ms |
200364 KB |
Output is correct |
32 |
Correct |
98 ms |
200352 KB |
Output is correct |
33 |
Correct |
1348 ms |
321632 KB |
Output is correct |
34 |
Correct |
1377 ms |
321836 KB |
Output is correct |
35 |
Correct |
1376 ms |
322084 KB |
Output is correct |
36 |
Correct |
2004 ms |
321288 KB |
Output is correct |
37 |
Correct |
2039 ms |
321872 KB |
Output is correct |
38 |
Correct |
2300 ms |
322476 KB |
Output is correct |
39 |
Correct |
2178 ms |
265056 KB |
Output is correct |
40 |
Correct |
2168 ms |
266652 KB |
Output is correct |
41 |
Correct |
2186 ms |
265144 KB |
Output is correct |
42 |
Correct |
1232 ms |
276764 KB |
Output is correct |
43 |
Correct |
1040 ms |
322632 KB |
Output is correct |
44 |
Correct |
1093 ms |
323008 KB |
Output is correct |
45 |
Correct |
1077 ms |
323452 KB |
Output is correct |
46 |
Correct |
1050 ms |
323228 KB |
Output is correct |
47 |
Correct |
1049 ms |
322752 KB |
Output is correct |
48 |
Correct |
1022 ms |
321540 KB |
Output is correct |
49 |
Correct |
1014 ms |
323132 KB |
Output is correct |
50 |
Correct |
1079 ms |
321436 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
189268 KB |
Output is correct |
2 |
Correct |
36 ms |
189300 KB |
Output is correct |
3 |
Correct |
42 ms |
189400 KB |
Output is correct |
4 |
Correct |
38 ms |
189528 KB |
Output is correct |
5 |
Correct |
36 ms |
189404 KB |
Output is correct |
6 |
Correct |
36 ms |
189276 KB |
Output is correct |
7 |
Correct |
36 ms |
189396 KB |
Output is correct |
8 |
Correct |
38 ms |
189264 KB |
Output is correct |
9 |
Correct |
36 ms |
189264 KB |
Output is correct |
10 |
Correct |
41 ms |
189480 KB |
Output is correct |
11 |
Correct |
38 ms |
189276 KB |
Output is correct |
12 |
Correct |
36 ms |
189268 KB |
Output is correct |
13 |
Correct |
37 ms |
189268 KB |
Output is correct |
14 |
Correct |
36 ms |
189348 KB |
Output is correct |
15 |
Correct |
37 ms |
189408 KB |
Output is correct |
16 |
Correct |
39 ms |
190088 KB |
Output is correct |
17 |
Correct |
44 ms |
190412 KB |
Output is correct |
18 |
Correct |
40 ms |
190300 KB |
Output is correct |
19 |
Correct |
56 ms |
194388 KB |
Output is correct |
20 |
Correct |
56 ms |
194528 KB |
Output is correct |
21 |
Correct |
59 ms |
194416 KB |
Output is correct |
22 |
Correct |
61 ms |
194552 KB |
Output is correct |
23 |
Correct |
61 ms |
194388 KB |
Output is correct |
24 |
Correct |
61 ms |
194388 KB |
Output is correct |
25 |
Correct |
63 ms |
194412 KB |
Output is correct |
26 |
Correct |
73 ms |
194488 KB |
Output is correct |
27 |
Execution timed out |
3066 ms |
591868 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |