#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
const int MAX = 3e5 + 9;
int N, par[MAX];
bool removed[MAX];
struct Circle {
i64 x, y;
i64 radius;
int index;
} circles[MAX], sweep[MAX];
pair<int, int> seg[MAX];
bool cmpX(Circle& a, Circle& b) {
if (a.x == b.x) return a.radius > b.radius;
return a.x < b.x;
}
bool intercept(Circle& a, Circle& b) {
i64 dx = a.x - b.x;
i64 dy = a.y - b.y;
i64 dist2 = dx * dx * 1LL + dy * dy * 1LL;
i64 r2 = (a.radius * 1LL + b.radius * 1LL) * (a.radius * 1LL + b.radius * 1LL) * 1LL;
if (dist2 <= r2) {
return true;
} else {
return false;
}
}
bool cmp(Circle& a, Circle& b) {
if (a.radius == b.radius)
return a.x < b.x;
return a.radius > b.radius;
}
int main() {
scanf("%d", &N);
for (int i = 0; i < N; ++i) {
scanf("%lld%lld%lld", &circles[i].x, &circles[i].y, &circles[i].radius);
circles[i].index = i;
}
for (int i = 0; i < N; ++i)
sweep[i] = circles[i];
sort(sweep, sweep + N, cmpX);
int j = 0;
for (int i = 1; i < N; ++i) {
while (j < i && !intercept(sweep[i], sweep[j])) {
j += 1;
}
int u = sweep[i].index;
seg[u].first = j;
}
for (int i = 0; i < N; ++i) {
while (j < N && intercept(sweep[i], sweep[j])) {
j += 1;
}
int u = sweep[i].index;
seg[u].second = j - 1;
}
// for (int i = 0; i < N; ++i) {
// printf("%d/%d/%d ", i + 1, sweep[seg[i].first].index + 1, sweep[seg[i].second].index + 1);
// }
// printf("\n");
sort(circles, circles + N, cmp);
for (int i = 0; i < N; ++i)
removed[i] = false;
for (int i = 0; i < N; ++i) {
int u = circles[i].index;
if (removed[u])
continue;
par[u] = u;
for (int j = seg[u].first; j <= seg[u].second; ++j) {
int v = sweep[j].index;
if (removed[v])
continue;
par[v] = u;
removed[v] = true;
}
removed[u] = true;
}
for (int i = 0; i < N; ++i) {
printf("%d ", par[i] + 1);
}
printf("\n");
}
Compilation message
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:43:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
43 | scanf("%d", &N);
| ~~~~~^~~~~~~~~~
circle_selection.cpp:45:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
45 | scanf("%lld%lld%lld", &circles[i].x, &circles[i].y, &circles[i].radius);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
235 ms |
24924 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
251 ms |
24568 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |