#pragma GCC optimize("trapv")
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
#define forn(i, n) for(int i=0; i<n; ++i)
#define F first
#define S second
#define PB push_back
struct circle{
pii c;
int r, ind;
};
struct quad{
pii a[4];
quad(pii A, pii B, pii C, pii D){a[0]=A, a[1]=B, a[2]=C, a[3]=D;}
};
pii reduce(pii a, int ind){
return {(a.F>>ind), (a.S>>ind)};
}
quad cover(pii c, int r, int i){
pii lelo={c.F-r, c.S-r}, lehi={c.F-r, c.S+r}, rilo={c.F+r, c.S-r}, rihi={c.F+r, c.S+r};
return quad(reduce(lelo, i), reduce(lehi, i), reduce(rilo, i), reduce(rihi, i));
}
bool inters(circle a, circle b){
ll dx=b.c.F-a.c.F, dy=b.c.S-a.c.S, sum=a.r+b.r;
return (dx*dx + dy*dy <= sum*sum);
}
const int MAXN=300010;
int n, ans[MAXN];
circle arr[MAXN];
map<pii, vector<int>> mp[36];
int main(){
scanf("%d", &n);
forn(i, n){
scanf("%d %d %d", &arr[i].c.F, &arr[i].c.S, &arr[i].r);
arr[i].c.F+=1000000010, arr[i].c.S+=1000000010;
arr[i].ind=i;
}
sort(arr, arr+n, [](circle a, circle b){
return a.r!=b.r? a.r>b.r : a.ind<b.ind;
});
forn(i, n){
int mn=i;
forn(j, 32) if((1LL<<j)>(2*arr[i].r)){
quad cov = cover(arr[i].c, arr[i].r, j);
forn(k, 4) for(int ind:mp[j][cov.a[k]]) if(inters(arr[i], arr[ind])) mn=min(mn, ind);
}
ans[arr[i].ind]=arr[mn].ind;
if(mn==i){
int ex = 8*sizeof(int)-__builtin_clz(arr[i].r)+1;
quad q = cover(arr[i].c, arr[i].r, ex);
forn(j, 4) mp[ex][q.a[j]].PB(i);
}
}
forn(i, n) printf("%d ", ans[i]+1);
}
Compilation message
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:46:17: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
46 | scanf("%d %d %d", &arr[i].c.F, &arr[i].c.S, &arr[i].r);
| ~^
| |
| int*
| %lld
circle_selection.cpp:46:20: warning: format '%d' expects argument of type 'int*', but argument 3 has type 'long long int*' [-Wformat=]
46 | scanf("%d %d %d", &arr[i].c.F, &arr[i].c.S, &arr[i].r);
| ~^
| |
| int*
| %lld
circle_selection.cpp:44:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
44 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
circle_selection.cpp:46:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
46 | scanf("%d %d %d", &arr[i].c.F, &arr[i].c.S, &arr[i].r);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7252 KB |
Output is correct |
2 |
Correct |
4 ms |
7252 KB |
Output is correct |
3 |
Correct |
4 ms |
7252 KB |
Output is correct |
4 |
Correct |
4 ms |
7252 KB |
Output is correct |
5 |
Correct |
4 ms |
7252 KB |
Output is correct |
6 |
Correct |
4 ms |
7252 KB |
Output is correct |
7 |
Correct |
4 ms |
7252 KB |
Output is correct |
8 |
Incorrect |
4 ms |
7252 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
257 ms |
10784 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
7252 KB |
Output is correct |
2 |
Correct |
1144 ms |
82708 KB |
Output is correct |
3 |
Execution timed out |
3068 ms |
196508 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3056 ms |
195004 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7252 KB |
Output is correct |
2 |
Correct |
4 ms |
7252 KB |
Output is correct |
3 |
Correct |
4 ms |
7252 KB |
Output is correct |
4 |
Correct |
4 ms |
7252 KB |
Output is correct |
5 |
Correct |
4 ms |
7252 KB |
Output is correct |
6 |
Correct |
4 ms |
7252 KB |
Output is correct |
7 |
Correct |
4 ms |
7252 KB |
Output is correct |
8 |
Incorrect |
4 ms |
7252 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7252 KB |
Output is correct |
2 |
Correct |
4 ms |
7252 KB |
Output is correct |
3 |
Correct |
4 ms |
7252 KB |
Output is correct |
4 |
Correct |
4 ms |
7252 KB |
Output is correct |
5 |
Correct |
4 ms |
7252 KB |
Output is correct |
6 |
Correct |
4 ms |
7252 KB |
Output is correct |
7 |
Correct |
4 ms |
7252 KB |
Output is correct |
8 |
Incorrect |
4 ms |
7252 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |