#include<iostream>
#include<map>
#include<algorithm>
using namespace std;
using pii=pair<int, int>;
#define forn(i, n) for(int i=0; i<(int)n; ++i)
struct circle{
int x, y, r, ind;
circle(int X=0, int Y=0, int R=0) : x(X), y(Y), r(R){}
};
bool operator< (circle a, circle b){
return a.r!=b.r? a.r>b.r : a.ind<b.ind;
}
const int MAXN=300010, LOG=32, dif[3]={-1, 0, 1};
int n, ans[MAXN];
circle arr[MAXN];
map<pii, circle> cir[LOG];
bool inters(circle a, circle b){
int dx=a.x-b.x, dy=a.y-b.y, sr=a.r+b.r;
return dx*dx <= sr*sr - dy*dy;
}
void insert(circle c){
int k=8*sizeof(int)-__builtin_clz(c.r);
cir[k][{c.x>>k, c.y>>k}]=c;
}
int check(circle c){
circle ret; ret.ind=-1;
forn(k, LOG){
int nx=c.x>>k, ny=c.y>>k;
forn(i, 3) forn(j, 3){
auto itr=cir[k].find({nx+dif[i], ny+dif[j]});
if(itr!=cir[k].end() && inters(itr->second, c)) ret=min(ret, itr->second);
}
}
return ret.ind;
}
int main(){
scanf("%d", &n);
forn(i, n) scanf("%d %d %d", &arr[i].x, &arr[i].y, &arr[i].r), arr[i].ind=i;
sort(arr, arr+n);
forn(i, n){
int val = check(arr[i]);
if(val==-1){
ans[arr[i].ind]=arr[i].ind;
insert(arr[i]);
}
else ans[arr[i].ind]=val;
}
forn(i, n) printf("%d ", ans[i]+1);
}
Compilation message
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:46:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
46 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
circle_selection.cpp:47:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
47 | forn(i, n) scanf("%d %d %d", &arr[i].x, &arr[i].y, &arr[i].r), arr[i].ind=i;
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
296 ms |
14820 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
4948 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
763 ms |
34832 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Incorrect |
3 ms |
4948 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |