#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int M = 3e5+5, MOD = 1e9;
struct circle {int x, y, r, i;};
bool operator<(circle a, circle b) {if (a.r == b.r) return a.i < b.i; return a.r > b.r;};
int p[M], l[M], r[M];
int sq(int a) {return a*a;}
int dist(circle a, circle b) {
return sq(a.x-b.x) + sq(a.y-b.y);
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
int n;
cin >> n;
int mx = INT_MIN;
set<circle> v;
set<pair<int, int>> rng;
for (int i = 1; i <= n; i++) {
int x, y, r_;
cin >> x >> y >> r_;
l[i] = x-r_;
r[i] = x+r_;
mx = max(mx, y);
rng.insert({l[i], i});
rng.insert({r[i], i});
v.insert({x, y, r_, i});
}
if (mx) {
while (v.size()) {
auto a = *v.begin();
v.erase(v.begin());
// cout << a.i << ": ";
p[a.i] = a.i;
set<circle> st;
for (auto b:v) {
if (dist(a, b) <= sq(a.r+b.r)) {
p[b.i] = a.i;
// cout << b.i << ' ';
st.insert(b);
}
} //cout << endl;
for (auto c:st) v.erase(c);
}
} else {
vector<int> ind;
for (int i = 1; i <= n; i++) ind.push_back(i);
sort(ind.begin(), ind.end(), [](int a, int b) {if (r[a]-l[a] == r[b]-l[b]) return a < b; return r[a]-l[a] > r[b]-l[b];});
for (int a:ind) {
if (rng.find({l[a], a}) == rng.end()) continue;
p[a] = a;
auto end = rng.find({r[a], a});
while (true) {
auto nxt = rng.upper_bound({l[a], a});
if (nxt == end) break;
// cout << l[nxt->second] << ',' << r[nxt->second] << ' ' << nxt->second << endl;
// for (auto [a, b]:rng) cout <<"{"<< a << ", " << b << "}, "; cout << endl;
p[nxt->second] = a;
rng.erase({l[nxt->second], nxt->second});
rng.erase({r[nxt->second], nxt->second});
}
auto begin = rng.lower_bound({l[a], a});
rng.erase(begin);
rng.erase(end);
}
}
for (int i = 1; i <= n; i++) cout << p[i] << ' '; cout << endl;
return 0;
}
/*
11
9 9 2
13 2 1
11 8 2
3 3 2
3 12 1
12 14 1
9 8 5
2 8 2
5 2 1
14 4 2
14 14 1
-------
7
0 0 2
-1 0 1
0 0 1
1 0 1
10 0 5
11 0 5
50 0 1
-------
*/
Compilation message
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:81:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
81 | for (int i = 1; i <= n; i++) cout << p[i] << ' '; cout << endl;
| ^~~
circle_selection.cpp:81:55: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
81 | for (int i = 1; i <= n; i++) cout << p[i] << ' '; cout << endl;
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
324 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
680 KB |
Output is correct |
17 |
Correct |
2 ms |
596 KB |
Output is correct |
18 |
Correct |
2 ms |
596 KB |
Output is correct |
19 |
Correct |
7 ms |
2004 KB |
Output is correct |
20 |
Correct |
6 ms |
2004 KB |
Output is correct |
21 |
Correct |
7 ms |
1876 KB |
Output is correct |
22 |
Correct |
188 ms |
1592 KB |
Output is correct |
23 |
Correct |
182 ms |
1604 KB |
Output is correct |
24 |
Correct |
185 ms |
1600 KB |
Output is correct |
25 |
Correct |
184 ms |
1600 KB |
Output is correct |
26 |
Correct |
185 ms |
1592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1218 ms |
70864 KB |
Output is correct |
2 |
Correct |
1178 ms |
77488 KB |
Output is correct |
3 |
Correct |
1213 ms |
77452 KB |
Output is correct |
4 |
Correct |
1181 ms |
77552 KB |
Output is correct |
5 |
Incorrect |
974 ms |
75568 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Execution timed out |
3068 ms |
25588 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3079 ms |
66064 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
324 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
680 KB |
Output is correct |
17 |
Correct |
2 ms |
596 KB |
Output is correct |
18 |
Correct |
2 ms |
596 KB |
Output is correct |
19 |
Correct |
7 ms |
2004 KB |
Output is correct |
20 |
Correct |
6 ms |
2004 KB |
Output is correct |
21 |
Correct |
7 ms |
1876 KB |
Output is correct |
22 |
Correct |
188 ms |
1592 KB |
Output is correct |
23 |
Correct |
182 ms |
1604 KB |
Output is correct |
24 |
Correct |
185 ms |
1600 KB |
Output is correct |
25 |
Correct |
184 ms |
1600 KB |
Output is correct |
26 |
Correct |
185 ms |
1592 KB |
Output is correct |
27 |
Correct |
15 ms |
3668 KB |
Output is correct |
28 |
Correct |
15 ms |
3648 KB |
Output is correct |
29 |
Correct |
16 ms |
3660 KB |
Output is correct |
30 |
Correct |
933 ms |
2848 KB |
Output is correct |
31 |
Correct |
926 ms |
2896 KB |
Output is correct |
32 |
Correct |
930 ms |
2856 KB |
Output is correct |
33 |
Correct |
250 ms |
32668 KB |
Output is correct |
34 |
Correct |
263 ms |
34540 KB |
Output is correct |
35 |
Correct |
255 ms |
33344 KB |
Output is correct |
36 |
Execution timed out |
3078 ms |
25408 KB |
Time limit exceeded |
37 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
324 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
680 KB |
Output is correct |
17 |
Correct |
2 ms |
596 KB |
Output is correct |
18 |
Correct |
2 ms |
596 KB |
Output is correct |
19 |
Correct |
7 ms |
2004 KB |
Output is correct |
20 |
Correct |
6 ms |
2004 KB |
Output is correct |
21 |
Correct |
7 ms |
1876 KB |
Output is correct |
22 |
Correct |
188 ms |
1592 KB |
Output is correct |
23 |
Correct |
182 ms |
1604 KB |
Output is correct |
24 |
Correct |
185 ms |
1600 KB |
Output is correct |
25 |
Correct |
184 ms |
1600 KB |
Output is correct |
26 |
Correct |
185 ms |
1592 KB |
Output is correct |
27 |
Correct |
1218 ms |
70864 KB |
Output is correct |
28 |
Correct |
1178 ms |
77488 KB |
Output is correct |
29 |
Correct |
1213 ms |
77452 KB |
Output is correct |
30 |
Correct |
1181 ms |
77552 KB |
Output is correct |
31 |
Incorrect |
974 ms |
75568 KB |
Output isn't correct |
32 |
Halted |
0 ms |
0 KB |
- |