#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 3e5+10;
const int add = 1e9;
ll R;
struct Circle
{
ll x, y, r;
int ind;
bool operator<(const ll &o) const
{
return y/R < o;
}
} circle[maxn];
vector<vector<Circle>> V;
int ans[maxn];
bool comp1(Circle a, Circle b)
{
if (a.x/R == b.x/R) return a.y < b.y;
return a.x < b.x;
}
bool comp2(Circle a, Circle b)
{
if (a.r == b.r) return a.ind < b.ind;
return a.r > b.r;
}
bool intersect(Circle a, Circle b)
{
ll dx = a.x-b.x, dy = a.y-b.y, dr = a.r+b.r;
return dx*dx + dy*dy <= dr*dr;
}
void doit(int pos, int c)
{
ll y = circle[c].y;
ll l_y = y/R - 2, r_y = y/R + 3;
auto it = lower_bound(V[pos].begin(), V[pos].end(), l_y);
for (; it != V[pos].end() && it->y/R <= r_y; it++)
if (intersect(circle[c], *it) && !ans[it->ind])
ans[it->ind] = circle[c].ind;
}
int main(void)
{
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++)
{
scanf("%lld %lld %lld", &circle[i].x, &circle[i].y, &circle[i].r);
circle[i].x += add, circle[i].y += add;
circle[i].ind = i;
}
R = circle[1].r;
sort(circle+1, circle+n+1, comp1);
for (int i = 1; i <= n; i++)
{
if (i == 1 || circle[i].x/R > circle[i-1].x/R)
V.push_back(vector<Circle>());
V.back().push_back(circle[i]);
}
sort(circle+1, circle+n+1, comp2);
for (int i = 1; i <= n; i++)
{
if (ans[circle[i].ind]) continue;
ll x = circle[i].x;
ll l_x = x/R - 2, r_x = x/R + 3;
int p_l, p_r;
int ini = 0, fim = (int)V.size()-1;
while (ini <= fim)
{
int mid = (ini+fim)>>1;
if (V[mid][0].x/R >= l_x) p_l = mid, fim = mid-1;
else ini = mid+1;
}
ini = 0, fim = (int)V.size()-1;
while (ini <= fim)
{
int mid = (ini+fim)>>1;
if (V[mid][0].x/R <= r_x) p_r = mid, ini = mid+1;
else fim = mid-1;
}
for (int j = p_l; j <= p_r; j++)
doit(j, i);
}
for (int i = 1; i <= n; i++)
printf("%d ", ans[i]);
printf("\n");
}
Compilation message
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:61:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
61 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
circle_selection.cpp:65:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
65 | scanf("%lld %lld %lld", &circle[i].x, &circle[i].y, &circle[i].r);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
circle_selection.cpp:92:12: warning: 'p_r' may be used uninitialized in this function [-Wmaybe-uninitialized]
92 | int p_l, p_r;
| ^~~
circle_selection.cpp:114:3: warning: 'p_l' may be used uninitialized in this function [-Wmaybe-uninitialized]
114 | for (int j = p_l; j <= p_r; j++)
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Incorrect |
0 ms |
364 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
288 ms |
22640 KB |
Output is correct |
2 |
Correct |
295 ms |
24528 KB |
Output is correct |
3 |
Incorrect |
286 ms |
23396 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
742 ms |
27932 KB |
Output is correct |
2 |
Correct |
742 ms |
34712 KB |
Output is correct |
3 |
Correct |
386 ms |
23788 KB |
Output is correct |
4 |
Correct |
727 ms |
35376 KB |
Output is correct |
5 |
Correct |
725 ms |
34712 KB |
Output is correct |
6 |
Correct |
366 ms |
21996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Incorrect |
0 ms |
364 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Incorrect |
0 ms |
364 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |