#pragma GCC optimize("O1,O2,O3,Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
const char nl = '\n';
void fastIO() {
ios::sync_with_stdio(false);
cin.tie(0);
}
bool intersect(int x1, int y1, int x2, int y2, int r1, int r2) {
ll dx = abs(x1 - x2);
ll dy = abs(y1 - y2);
ll dt = r1 + r2;
if (dt * dt >= dx * dx + dy * dy)
return true;
return false;
}
int main() {
fastIO();
int N;
cin>>N;
vector<pair<ii, int>> cr(N);
// {{x, y}, r}
set<pair<ii, ii>> all;
// {{r, -id}, {x, y}}
map<int, set<pair<int, ii>>> allx; // maps x coord to all {y, {r, id}}
for (int i = 0; i < N; i++) {
int x, y, r;
cin>>x>>y>>r;
all.insert({{r, -i}, {x, y}});
allx[x].insert({y, {r, i}});
}
vi par(N, -1);
int rem = N;
while (rem > 0) {
auto it = --all.end();
int r = (*it).fi.fi;
int id = -(*it).fi.se;
int x = (*it).se.fi;
int y = (*it).se.se;
// cout<<"at "<<id<<endl;
// consider all from x in x-2r to x+2r, y in y-2r to r+2r
int xl = max((ll)(x) - 2 * (ll)(r), (ll)(-2e9));
int xh = min((ll)(x) + 2 * (ll)(r), (ll)(2e9));
auto it2 = allx.lower_bound(xl);
while (it2 != allx.end() && (*it2).fi <= xh) {
// do another search inside
int cx = (*it2).fi;
vector<pair<ll, ii>> toremove;
int dx = abs(xh - cx);
// can do up to sqrt for yh
ll dy = (int)(pow(4 * (double)(r) * (double)(r) - (double)(dx) * (double)(dx), 0.5) + 2);
int yl = max(y - dy, (ll)(-2e9));
int yh = min(y + dy, (ll)(2e9));
auto it3 = allx[cx].lower_bound({yl, {-1, -1}});
while (it3 != allx[cx].end() && (*it3).fi <= yh) {
int cy = (*it3).fi;
int cr = (*it3).se.fi;
int cid = (*it3).se.se;
if (intersect(x, y, cx, cy, r, cr)) {
toremove.pb(*it3);
}
it3++;
}
for (pair<int, ii> p : toremove) {
par[p.se.se] = id;
// cout<<"erased "<<p.se.se<<endl;
allx[cx].erase(p);
all.erase({{p.se.fi, -p.se.se}, {cx, p.fi}});
rem--;
}
it2++;
}
}
// cout<<"ANSWER: ";
for (int x : par)
cout<<(x + 1)<<" ";
cout<<endl;
}
Compilation message
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:70:9: warning: unused variable 'cid' [-Wunused-variable]
70 | int cid = (*it3).se.se;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2143 ms |
72944 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1685 ms |
72864 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |