#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(a, 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;
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
146 ms |
532564 KB |
Output is correct |
2 |
Correct |
115 ms |
532720 KB |
Output is correct |
3 |
Correct |
119 ms |
532556 KB |
Output is correct |
4 |
Correct |
114 ms |
532732 KB |
Output is correct |
5 |
Correct |
111 ms |
532648 KB |
Output is correct |
6 |
Correct |
110 ms |
532788 KB |
Output is correct |
7 |
Correct |
115 ms |
532568 KB |
Output is correct |
8 |
Correct |
111 ms |
532568 KB |
Output is correct |
9 |
Correct |
112 ms |
532796 KB |
Output is correct |
10 |
Correct |
111 ms |
532564 KB |
Output is correct |
11 |
Correct |
112 ms |
532568 KB |
Output is correct |
12 |
Correct |
114 ms |
532776 KB |
Output is correct |
13 |
Correct |
113 ms |
533060 KB |
Output is correct |
14 |
Correct |
118 ms |
532804 KB |
Output is correct |
15 |
Correct |
111 ms |
532564 KB |
Output is correct |
16 |
Correct |
115 ms |
533344 KB |
Output is correct |
17 |
Correct |
114 ms |
533328 KB |
Output is correct |
18 |
Correct |
118 ms |
533380 KB |
Output is correct |
19 |
Correct |
132 ms |
536656 KB |
Output is correct |
20 |
Correct |
128 ms |
536380 KB |
Output is correct |
21 |
Correct |
130 ms |
536732 KB |
Output is correct |
22 |
Correct |
137 ms |
537496 KB |
Output is correct |
23 |
Correct |
139 ms |
537424 KB |
Output is correct |
24 |
Correct |
136 ms |
537644 KB |
Output is correct |
25 |
Correct |
136 ms |
537680 KB |
Output is correct |
26 |
Correct |
137 ms |
537500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2695 ms |
861180 KB |
Output is correct |
2 |
Correct |
2660 ms |
851748 KB |
Output is correct |
3 |
Correct |
2659 ms |
850220 KB |
Output is correct |
4 |
Correct |
2660 ms |
838268 KB |
Output is correct |
5 |
Correct |
2573 ms |
803304 KB |
Output is correct |
6 |
Execution timed out |
3095 ms |
878188 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
116 ms |
532520 KB |
Output is correct |
2 |
Correct |
1412 ms |
635840 KB |
Output is correct |
3 |
Execution timed out |
3034 ms |
876896 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3048 ms |
876532 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
146 ms |
532564 KB |
Output is correct |
2 |
Correct |
115 ms |
532720 KB |
Output is correct |
3 |
Correct |
119 ms |
532556 KB |
Output is correct |
4 |
Correct |
114 ms |
532732 KB |
Output is correct |
5 |
Correct |
111 ms |
532648 KB |
Output is correct |
6 |
Correct |
110 ms |
532788 KB |
Output is correct |
7 |
Correct |
115 ms |
532568 KB |
Output is correct |
8 |
Correct |
111 ms |
532568 KB |
Output is correct |
9 |
Correct |
112 ms |
532796 KB |
Output is correct |
10 |
Correct |
111 ms |
532564 KB |
Output is correct |
11 |
Correct |
112 ms |
532568 KB |
Output is correct |
12 |
Correct |
114 ms |
532776 KB |
Output is correct |
13 |
Correct |
113 ms |
533060 KB |
Output is correct |
14 |
Correct |
118 ms |
532804 KB |
Output is correct |
15 |
Correct |
111 ms |
532564 KB |
Output is correct |
16 |
Correct |
115 ms |
533344 KB |
Output is correct |
17 |
Correct |
114 ms |
533328 KB |
Output is correct |
18 |
Correct |
118 ms |
533380 KB |
Output is correct |
19 |
Correct |
132 ms |
536656 KB |
Output is correct |
20 |
Correct |
128 ms |
536380 KB |
Output is correct |
21 |
Correct |
130 ms |
536732 KB |
Output is correct |
22 |
Correct |
137 ms |
537496 KB |
Output is correct |
23 |
Correct |
139 ms |
537424 KB |
Output is correct |
24 |
Correct |
136 ms |
537644 KB |
Output is correct |
25 |
Correct |
136 ms |
537680 KB |
Output is correct |
26 |
Correct |
137 ms |
537500 KB |
Output is correct |
27 |
Correct |
155 ms |
540884 KB |
Output is correct |
28 |
Correct |
151 ms |
541104 KB |
Output is correct |
29 |
Correct |
151 ms |
541132 KB |
Output is correct |
30 |
Correct |
171 ms |
542160 KB |
Output is correct |
31 |
Correct |
177 ms |
542520 KB |
Output is correct |
32 |
Correct |
175 ms |
542272 KB |
Output is correct |
33 |
Correct |
810 ms |
622888 KB |
Output is correct |
34 |
Correct |
884 ms |
627232 KB |
Output is correct |
35 |
Correct |
875 ms |
633280 KB |
Output is correct |
36 |
Correct |
1350 ms |
637988 KB |
Output is correct |
37 |
Correct |
1318 ms |
636864 KB |
Output is correct |
38 |
Correct |
1365 ms |
637644 KB |
Output is correct |
39 |
Correct |
591 ms |
573892 KB |
Output is correct |
40 |
Correct |
641 ms |
574884 KB |
Output is correct |
41 |
Correct |
597 ms |
575472 KB |
Output is correct |
42 |
Correct |
545 ms |
578752 KB |
Output is correct |
43 |
Correct |
1231 ms |
640864 KB |
Output is correct |
44 |
Correct |
1285 ms |
640552 KB |
Output is correct |
45 |
Correct |
1312 ms |
640200 KB |
Output is correct |
46 |
Correct |
1289 ms |
641224 KB |
Output is correct |
47 |
Correct |
1300 ms |
639476 KB |
Output is correct |
48 |
Correct |
1287 ms |
640964 KB |
Output is correct |
49 |
Correct |
1317 ms |
639664 KB |
Output is correct |
50 |
Correct |
1268 ms |
639556 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
146 ms |
532564 KB |
Output is correct |
2 |
Correct |
115 ms |
532720 KB |
Output is correct |
3 |
Correct |
119 ms |
532556 KB |
Output is correct |
4 |
Correct |
114 ms |
532732 KB |
Output is correct |
5 |
Correct |
111 ms |
532648 KB |
Output is correct |
6 |
Correct |
110 ms |
532788 KB |
Output is correct |
7 |
Correct |
115 ms |
532568 KB |
Output is correct |
8 |
Correct |
111 ms |
532568 KB |
Output is correct |
9 |
Correct |
112 ms |
532796 KB |
Output is correct |
10 |
Correct |
111 ms |
532564 KB |
Output is correct |
11 |
Correct |
112 ms |
532568 KB |
Output is correct |
12 |
Correct |
114 ms |
532776 KB |
Output is correct |
13 |
Correct |
113 ms |
533060 KB |
Output is correct |
14 |
Correct |
118 ms |
532804 KB |
Output is correct |
15 |
Correct |
111 ms |
532564 KB |
Output is correct |
16 |
Correct |
115 ms |
533344 KB |
Output is correct |
17 |
Correct |
114 ms |
533328 KB |
Output is correct |
18 |
Correct |
118 ms |
533380 KB |
Output is correct |
19 |
Correct |
132 ms |
536656 KB |
Output is correct |
20 |
Correct |
128 ms |
536380 KB |
Output is correct |
21 |
Correct |
130 ms |
536732 KB |
Output is correct |
22 |
Correct |
137 ms |
537496 KB |
Output is correct |
23 |
Correct |
139 ms |
537424 KB |
Output is correct |
24 |
Correct |
136 ms |
537644 KB |
Output is correct |
25 |
Correct |
136 ms |
537680 KB |
Output is correct |
26 |
Correct |
137 ms |
537500 KB |
Output is correct |
27 |
Correct |
2695 ms |
861180 KB |
Output is correct |
28 |
Correct |
2660 ms |
851748 KB |
Output is correct |
29 |
Correct |
2659 ms |
850220 KB |
Output is correct |
30 |
Correct |
2660 ms |
838268 KB |
Output is correct |
31 |
Correct |
2573 ms |
803304 KB |
Output is correct |
32 |
Execution timed out |
3095 ms |
878188 KB |
Time limit exceeded |
33 |
Halted |
0 ms |
0 KB |
- |