#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300005;
const int offs = 1e9 + 100;
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=31; 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 + offs) >> i, (a[j].y + offs) >> 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 + offs) >> i) + k;
int py = ((a[j].y + offs) >> 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:47: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:17:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
~~~~~^~~~~~~~~
circle_selection.cpp:19: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);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
488 KB |
Output is correct |
3 |
Correct |
2 ms |
488 KB |
Output is correct |
4 |
Correct |
2 ms |
496 KB |
Output is correct |
5 |
Correct |
2 ms |
496 KB |
Output is correct |
6 |
Correct |
2 ms |
556 KB |
Output is correct |
7 |
Correct |
2 ms |
568 KB |
Output is correct |
8 |
Correct |
2 ms |
612 KB |
Output is correct |
9 |
Correct |
2 ms |
612 KB |
Output is correct |
10 |
Incorrect |
2 ms |
612 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
347 ms |
23996 KB |
Output is correct |
2 |
Incorrect |
370 ms |
24204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
24204 KB |
Output is correct |
2 |
Correct |
384 ms |
24204 KB |
Output is correct |
3 |
Correct |
1341 ms |
24204 KB |
Output is correct |
4 |
Correct |
1304 ms |
24204 KB |
Output is correct |
5 |
Correct |
1144 ms |
24204 KB |
Output is correct |
6 |
Correct |
546 ms |
24204 KB |
Output is correct |
7 |
Correct |
274 ms |
24204 KB |
Output is correct |
8 |
Correct |
54 ms |
24204 KB |
Output is correct |
9 |
Correct |
1307 ms |
24204 KB |
Output is correct |
10 |
Correct |
1075 ms |
24396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1199 ms |
24396 KB |
Output is correct |
2 |
Correct |
1732 ms |
24396 KB |
Output is correct |
3 |
Incorrect |
644 ms |
24396 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
488 KB |
Output is correct |
3 |
Correct |
2 ms |
488 KB |
Output is correct |
4 |
Correct |
2 ms |
496 KB |
Output is correct |
5 |
Correct |
2 ms |
496 KB |
Output is correct |
6 |
Correct |
2 ms |
556 KB |
Output is correct |
7 |
Correct |
2 ms |
568 KB |
Output is correct |
8 |
Correct |
2 ms |
612 KB |
Output is correct |
9 |
Correct |
2 ms |
612 KB |
Output is correct |
10 |
Incorrect |
2 ms |
612 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
488 KB |
Output is correct |
3 |
Correct |
2 ms |
488 KB |
Output is correct |
4 |
Correct |
2 ms |
496 KB |
Output is correct |
5 |
Correct |
2 ms |
496 KB |
Output is correct |
6 |
Correct |
2 ms |
556 KB |
Output is correct |
7 |
Correct |
2 ms |
568 KB |
Output is correct |
8 |
Correct |
2 ms |
612 KB |
Output is correct |
9 |
Correct |
2 ms |
612 KB |
Output is correct |
10 |
Incorrect |
2 ms |
612 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |