#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 rescale(void)
{
vector<vector<Circle>> aux;
for (int i = 0; i < V.size(); i++)
{
ll mn = 1e18, mx = 0;
for (auto c: V[i])
{
mn = min(mn, c.x/R);
mx = max(mx, c.x/R);
}
ll med = mn;
for (auto c: V[i])
if (c.x/R != mn && c.x/R != mx)
med = c.x/R;
if (aux.size() == 0 || mn > aux.back()[0].x/R)
aux.push_back(vector<Circle>());
for (auto c: V[i])
if (c.x/R == mn)
aux.back().push_back(c);
if (med > mn)
{
aux.push_back(vector<Circle>());
for (auto c: V[i])
if (c.x/R == med)
aux.back().push_back(c);
}
if (mx > med)
{
aux.push_back(vector<Circle>());
for (auto c: V[i])
if (c.x/R == mx)
aux.back().push_back(c);
}
}
swap(aux, V);
}
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 = max(R, circle[i].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;
while (circle[i].r < R/2)
{
R /= 2;
rescale();
}
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 'void rescale()':
circle_selection.cpp:50:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<Circle> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for (int i = 0; i < V.size(); i++)
| ~~^~~~~~~~~~
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:109:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
109 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
circle_selection.cpp:113:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
113 | scanf("%lld %lld %lld", &circle[i].x, &circle[i].y, &circle[i].r);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
circle_selection.cpp:146:12: warning: 'p_r' may be used uninitialized in this function [-Wmaybe-uninitialized]
146 | int p_l, p_r;
| ^~~
circle_selection.cpp:168:3: warning: 'p_l' may be used uninitialized in this function [-Wmaybe-uninitialized]
168 | for (int j = p_l; j <= p_r; j++)
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
2 ms |
492 KB |
Output is correct |
17 |
Correct |
1 ms |
492 KB |
Output is correct |
18 |
Correct |
1 ms |
492 KB |
Output is correct |
19 |
Correct |
5 ms |
1004 KB |
Output is correct |
20 |
Correct |
5 ms |
1004 KB |
Output is correct |
21 |
Correct |
7 ms |
1340 KB |
Output is correct |
22 |
Incorrect |
14 ms |
1692 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
316 ms |
35192 KB |
Output is correct |
2 |
Correct |
350 ms |
34344 KB |
Output is correct |
3 |
Correct |
278 ms |
22632 KB |
Output is correct |
4 |
Correct |
306 ms |
43812 KB |
Output is correct |
5 |
Correct |
515 ms |
48076 KB |
Output is correct |
6 |
Correct |
692 ms |
67780 KB |
Output is correct |
7 |
Correct |
592 ms |
62852 KB |
Output is correct |
8 |
Correct |
594 ms |
62592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
396 KB |
Output is correct |
2 |
Incorrect |
370 ms |
24368 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
741 ms |
27972 KB |
Output is correct |
2 |
Correct |
729 ms |
34444 KB |
Output is correct |
3 |
Correct |
370 ms |
23660 KB |
Output is correct |
4 |
Correct |
724 ms |
35096 KB |
Output is correct |
5 |
Correct |
734 ms |
34876 KB |
Output is correct |
6 |
Correct |
339 ms |
22000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
2 ms |
492 KB |
Output is correct |
17 |
Correct |
1 ms |
492 KB |
Output is correct |
18 |
Correct |
1 ms |
492 KB |
Output is correct |
19 |
Correct |
5 ms |
1004 KB |
Output is correct |
20 |
Correct |
5 ms |
1004 KB |
Output is correct |
21 |
Correct |
7 ms |
1340 KB |
Output is correct |
22 |
Incorrect |
14 ms |
1692 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
2 ms |
492 KB |
Output is correct |
17 |
Correct |
1 ms |
492 KB |
Output is correct |
18 |
Correct |
1 ms |
492 KB |
Output is correct |
19 |
Correct |
5 ms |
1004 KB |
Output is correct |
20 |
Correct |
5 ms |
1004 KB |
Output is correct |
21 |
Correct |
7 ms |
1340 KB |
Output is correct |
22 |
Incorrect |
14 ms |
1692 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |