#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300005;
using pi = pair<int, int>;
struct circ{
int x, y, r, idx;
bool operator<(const circ &c)const{
return pi(x, y) < pi(c.x, c.y);
}
}a[MAXN], orig_pos[MAXN];
int n, ans[MAXN];
int main(){
scanf("%d",&n);
for(int i=0; i<n; i++){
scanf("%d %d %d",&a[i].x,&a[i].y,&a[i].r);
a[i].idx = i + 1;
orig_pos[i + 1] = a[i];
}
auto inter = [&](circ a, circ b){
int dx = a.x - b.x;
int dy = a.y - b.y;
int dr = a.r + b.r;
return 1ll * dx * dx + 1ll * dy * dy <= 1ll * dr * dr;
};
sort(a, a+n, [&](const circ &a, const circ &b){
return pi(-a.r, a.idx) < pi(-b.r, b.idx);
});
for(int i=30; i; i--){
int lb = (1 << (i - 1)), rb = (1 << i) - 1;
vector<circ> v;
for(int j=0; j<n; j++){
if(!ans[a[j].idx] && a[j].r <= rb){
v.push_back((circ){a[j].x >> i, a[j].y >> i, a[j].r, a[j].idx});
}
}
sort(v.begin(), v.end());
for(int j=0; j<n; j++){
if(!ans[a[j].idx] && a[j].r <= rb && a[j].r >= lb){
for(int k=-2; k<=2; k++){
int px = (a[j].x >> i) + k;
int py = (a[j].y >> i) + -2;
auto itr = lower_bound(v.begin(), v.end(), (circ){px, py, -1, -1}) - v.begin();
while(itr < v.size() && pi(v[itr].x, v[itr].y) <= pi(px, py + 4)){
if(inter(orig_pos[v[itr].idx], a[j])){
ans[v[itr].idx] = a[j].idx;
}
itr++;
}
}
}
}
}
for(int i=1; i<=n; i++) printf("%d ", ans[i]);
}
Compilation message
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:46:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(itr < v.size() && pi(v[itr].x, v[itr].y) <= pi(px, py + 4)){
~~~~^~~~~~~~~~
circle_selection.cpp:16:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
~~~~~^~~~~~~~~
circle_selection.cpp:18:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d",&a[i].x,&a[i].y,&a[i].r);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
428 KB |
Output is correct |
4 |
Correct |
2 ms |
428 KB |
Output is correct |
5 |
Correct |
2 ms |
428 KB |
Output is correct |
6 |
Correct |
3 ms |
544 KB |
Output is correct |
7 |
Correct |
3 ms |
544 KB |
Output is correct |
8 |
Correct |
2 ms |
544 KB |
Output is correct |
9 |
Correct |
3 ms |
560 KB |
Output is correct |
10 |
Incorrect |
2 ms |
560 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
329 ms |
23948 KB |
Output is correct |
2 |
Incorrect |
347 ms |
23948 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
23948 KB |
Output is correct |
2 |
Correct |
402 ms |
23948 KB |
Output is correct |
3 |
Correct |
1358 ms |
24156 KB |
Output is correct |
4 |
Correct |
1309 ms |
24156 KB |
Output is correct |
5 |
Correct |
1208 ms |
24156 KB |
Output is correct |
6 |
Correct |
539 ms |
24156 KB |
Output is correct |
7 |
Correct |
287 ms |
24156 KB |
Output is correct |
8 |
Correct |
54 ms |
24156 KB |
Output is correct |
9 |
Correct |
1316 ms |
24156 KB |
Output is correct |
10 |
Correct |
1076 ms |
24156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1281 ms |
24160 KB |
Output is correct |
2 |
Correct |
1762 ms |
24312 KB |
Output is correct |
3 |
Incorrect |
579 ms |
24356 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
428 KB |
Output is correct |
4 |
Correct |
2 ms |
428 KB |
Output is correct |
5 |
Correct |
2 ms |
428 KB |
Output is correct |
6 |
Correct |
3 ms |
544 KB |
Output is correct |
7 |
Correct |
3 ms |
544 KB |
Output is correct |
8 |
Correct |
2 ms |
544 KB |
Output is correct |
9 |
Correct |
3 ms |
560 KB |
Output is correct |
10 |
Incorrect |
2 ms |
560 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
428 KB |
Output is correct |
4 |
Correct |
2 ms |
428 KB |
Output is correct |
5 |
Correct |
2 ms |
428 KB |
Output is correct |
6 |
Correct |
3 ms |
544 KB |
Output is correct |
7 |
Correct |
3 ms |
544 KB |
Output is correct |
8 |
Correct |
2 ms |
544 KB |
Output is correct |
9 |
Correct |
3 ms |
560 KB |
Output is correct |
10 |
Incorrect |
2 ms |
560 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |