#include <bits/stdc++.h>
using namespace std;
constexpr int MAXN = 300005;
constexpr int MAXINT = 1073741823;
vector<int> all_numbers;
vector<int> neighbors[MAXN];
struct circles {
long long int x, y, radius;
} circle[MAXN];
int sorted[MAXN], answer[MAXN];
bitset<MAXN> deleted;
bool comparison(int x, int y) {
return (circle[x].radius == circle[y].radius? x < y : circle[x].radius > circle[y].radius);
}
map<int, vector<pair<int, int>>> to_add, to_delete;
set<pair<int, int>> s;
set<pair<int, int>>::iterator it;
bool check(circles u, circles v) {
long long int distance_2 = (u.x - v.x) * (u.x - v.x) + (u.y - v.y) * (u.y - v.y);
long long int radius_2 = (u.radius + v.radius) * (u.radius + v.radius);
return (radius_2 >= distance_2);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long int n, distance_2, radius_2;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> circle[i].x >> circle[i].y >> circle[i].radius;
all_numbers.push_back(circle[i].y - circle[i].radius);
all_numbers.push_back(circle[i].y + circle[i].radius);
to_add[circle[i].y - circle[i].radius].emplace_back(circle[i].x, i);
to_delete[circle[i].y + circle[i].radius].emplace_back(circle[i].x, i);
sorted[i] = i;
}
sort(sorted, sorted + n, comparison);
sort(all_numbers.begin(), all_numbers.end());
all_numbers.resize(distance(all_numbers.begin(), unique(all_numbers.begin(), all_numbers.end())));
for (int i : all_numbers) {
for (pair<int, int> j : to_add[i]) {
s.insert(j);
it = s.lower_bound(j);
if (it != s.begin()) {
it--;
if (check(circle[it->second], circle[j.second])) {
neighbors[it->second].push_back(j.second);
neighbors[j.second].push_back(it->second);
}
it++;
}
if (*it != *s.rbegin()) {
it++;
if (check(circle[it->second], circle[j.second])) {
neighbors[it->second].push_back(j.second);
neighbors[j.second].push_back(it->second);
}
it--;
}
}
for (pair<int, int> j : to_delete[i]) {
it = s.lower_bound(j);
if (it != s.begin()) {
it--;
if (check(circle[it->second], circle[j.second])) {
neighbors[it->second].push_back(j.second);
neighbors[j.second].push_back(it->second);
}
it++;
}
if (*it != *s.rbegin()) {
it++;
if (check(circle[it->second], circle[j.second])) {
neighbors[it->second].push_back(j.second);
neighbors[j.second].push_back(it->second);
}
it--;
}
s.erase(j);
}
}
for (int i = 0; i < n; i++)
if (!deleted[sorted[i]]) {
answer[sorted[i]] = sorted[i];
deleted[sorted[i]] = true;
for (int j : neighbors[sorted[i]]) {
if (deleted[j])
continue;
answer[j] = sorted[i];
deleted[j] = true;
}
}
for (int i = 0; i < n; i++)
cout << answer[i] + 1 << ' ';
return 0;
}
Compilation message
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:40:19: warning: unused variable 'distance_2' [-Wunused-variable]
40 | long long int n, distance_2, radius_2;
| ^~~~~~~~~~
circle_selection.cpp:40:31: warning: unused variable 'radius_2' [-Wunused-variable]
40 | long long int n, distance_2, radius_2;
| ^~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7372 KB |
Output is correct |
2 |
Correct |
4 ms |
7372 KB |
Output is correct |
3 |
Correct |
4 ms |
7372 KB |
Output is correct |
4 |
Correct |
4 ms |
7372 KB |
Output is correct |
5 |
Incorrect |
4 ms |
7372 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2473 ms |
157344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7372 KB |
Output is correct |
2 |
Correct |
384 ms |
49504 KB |
Output is correct |
3 |
Correct |
1287 ms |
141900 KB |
Output is correct |
4 |
Correct |
1268 ms |
142084 KB |
Output is correct |
5 |
Correct |
1386 ms |
143416 KB |
Output is correct |
6 |
Correct |
699 ms |
82516 KB |
Output is correct |
7 |
Correct |
311 ms |
46776 KB |
Output is correct |
8 |
Correct |
50 ms |
15448 KB |
Output is correct |
9 |
Correct |
1328 ms |
143072 KB |
Output is correct |
10 |
Correct |
1547 ms |
151632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1049 ms |
133736 KB |
Output is correct |
2 |
Correct |
876 ms |
140916 KB |
Output is correct |
3 |
Incorrect |
1559 ms |
159236 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7372 KB |
Output is correct |
2 |
Correct |
4 ms |
7372 KB |
Output is correct |
3 |
Correct |
4 ms |
7372 KB |
Output is correct |
4 |
Correct |
4 ms |
7372 KB |
Output is correct |
5 |
Incorrect |
4 ms |
7372 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7372 KB |
Output is correct |
2 |
Correct |
4 ms |
7372 KB |
Output is correct |
3 |
Correct |
4 ms |
7372 KB |
Output is correct |
4 |
Correct |
4 ms |
7372 KB |
Output is correct |
5 |
Incorrect |
4 ms |
7372 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |