#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;
while (true) {
auto nxt = rng.upper_bound({l[a], 0});
if (nxt == rng.end() || nxt->first > r[a]) 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});
}
}
}
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:75:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
75 | for (int i = 1; i <= n; i++) cout << p[i] << ' '; cout << endl;
| ^~~
circle_selection.cpp:75:55: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
75 | for (int i = 1; i <= n; i++) cout << p[i] << ' '; cout << endl;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
2 ms |
596 KB |
Output is correct |
18 |
Correct |
2 ms |
596 KB |
Output is correct |
19 |
Correct |
6 ms |
1900 KB |
Output is correct |
20 |
Correct |
6 ms |
1820 KB |
Output is correct |
21 |
Correct |
7 ms |
1748 KB |
Output is correct |
22 |
Correct |
182 ms |
1464 KB |
Output is correct |
23 |
Correct |
190 ms |
1464 KB |
Output is correct |
24 |
Correct |
184 ms |
1484 KB |
Output is correct |
25 |
Correct |
182 ms |
1460 KB |
Output is correct |
26 |
Correct |
183 ms |
1460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1182 ms |
70904 KB |
Output is correct |
2 |
Correct |
1205 ms |
70764 KB |
Output is correct |
3 |
Correct |
1214 ms |
70932 KB |
Output is correct |
4 |
Correct |
1225 ms |
70952 KB |
Output is correct |
5 |
Correct |
943 ms |
70956 KB |
Output is correct |
6 |
Correct |
983 ms |
75580 KB |
Output is correct |
7 |
Correct |
975 ms |
75620 KB |
Output is correct |
8 |
Correct |
968 ms |
75600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
3089 ms |
22716 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3092 ms |
66136 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
2 ms |
596 KB |
Output is correct |
18 |
Correct |
2 ms |
596 KB |
Output is correct |
19 |
Correct |
6 ms |
1900 KB |
Output is correct |
20 |
Correct |
6 ms |
1820 KB |
Output is correct |
21 |
Correct |
7 ms |
1748 KB |
Output is correct |
22 |
Correct |
182 ms |
1464 KB |
Output is correct |
23 |
Correct |
190 ms |
1464 KB |
Output is correct |
24 |
Correct |
184 ms |
1484 KB |
Output is correct |
25 |
Correct |
182 ms |
1460 KB |
Output is correct |
26 |
Correct |
183 ms |
1460 KB |
Output is correct |
27 |
Correct |
14 ms |
3408 KB |
Output is correct |
28 |
Correct |
15 ms |
3412 KB |
Output is correct |
29 |
Correct |
13 ms |
3344 KB |
Output is correct |
30 |
Correct |
947 ms |
2596 KB |
Output is correct |
31 |
Correct |
934 ms |
2584 KB |
Output is correct |
32 |
Correct |
938 ms |
2588 KB |
Output is correct |
33 |
Correct |
269 ms |
31344 KB |
Output is correct |
34 |
Correct |
241 ms |
31364 KB |
Output is correct |
35 |
Correct |
268 ms |
30408 KB |
Output is correct |
36 |
Execution timed out |
3097 ms |
22808 KB |
Time limit exceeded |
37 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
596 KB |
Output is correct |
17 |
Correct |
2 ms |
596 KB |
Output is correct |
18 |
Correct |
2 ms |
596 KB |
Output is correct |
19 |
Correct |
6 ms |
1900 KB |
Output is correct |
20 |
Correct |
6 ms |
1820 KB |
Output is correct |
21 |
Correct |
7 ms |
1748 KB |
Output is correct |
22 |
Correct |
182 ms |
1464 KB |
Output is correct |
23 |
Correct |
190 ms |
1464 KB |
Output is correct |
24 |
Correct |
184 ms |
1484 KB |
Output is correct |
25 |
Correct |
182 ms |
1460 KB |
Output is correct |
26 |
Correct |
183 ms |
1460 KB |
Output is correct |
27 |
Correct |
1182 ms |
70904 KB |
Output is correct |
28 |
Correct |
1205 ms |
70764 KB |
Output is correct |
29 |
Correct |
1214 ms |
70932 KB |
Output is correct |
30 |
Correct |
1225 ms |
70952 KB |
Output is correct |
31 |
Correct |
943 ms |
70956 KB |
Output is correct |
32 |
Correct |
983 ms |
75580 KB |
Output is correct |
33 |
Correct |
975 ms |
75620 KB |
Output is correct |
34 |
Correct |
968 ms |
75600 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Execution timed out |
3089 ms |
22716 KB |
Time limit exceeded |
37 |
Halted |
0 ms |
0 KB |
- |