/*input
11
9 9 2
13 2 1
11 8 2
3 3 2
3 12 1
12 14 1
9 8 5
2 8 2
5 2 1
14 4 2
14 14 1
*/
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
ll h(ll x, ll y)
{
return x + 15 * y + (x ^ y);
}
int main()
{
ios_base::sync_with_stdio(false);
ll n;
cin >> n;
ll x[n], y[n], r[n];
for (ll i = 0; i < n; i++)
{
cin >> x[i] >> y[i] >> r[i];
x[i] += ll(1e9);
y[i] += ll(1e9);
}
ll a[n];
iota(a, a + n, 0);
sort(a, a + n, [&](ll x, ll y) {
if (r[x] != r[y])
return r[x] > r[y];
else
return x < y;
});
ll ans[n];
fill_n(ans, n, -1);
ll g = (1 << 30);
cc_hash_table<ll, list<ll>>xx;
list<ll>liko;
list<ll>::iterator itas[n];
for (ll i = 0; i < n; i++)
{
liko.push_back(i);
itas[i] = (--liko.end());
}
xx.clear();
for (ll i = 0; i < n; i++)
{
xx[ h(x[i] / g, y[i] / g)].push_back(i);
}
for (ll i = 0; i < n; i++)
{
if (ans[a[i]] != -1)
continue;
while (g >= r[a[i]] * 2)
{
g /= 2;
xx.clear();
for (ll i : liko)
{
xx[h(x[i] / g, y[i] / g)].push_back(i);
}
}
ll aa = x[a[i]] / g;
ll bb = y[a[i]] / g;
for (ll dx = -2; dx <= 2; dx++)
{
for (ll dy = -2; dy <= 2; dy++)
{
list<ll>&kvad = xx[h(aa + dx, bb + dy)];
for (auto it = kvad.begin(); it != kvad.end();)
{
ll j = *it;
if ((x[a[i]] - x[j]) * (x[a[i]] - x[j]) +
(y[a[i]] - y[j]) * (y[a[i]] - y[j]) <=
(r[a[i]] + r[j]) * (r[a[i]] + r[j]))
{
ans[j] = a[i];
liko.erase(itas[j]);
it = kvad.erase(it);
}
else
it++;
}
}
}
}
for (ll i = 0; i < n; i++)
cout << ans[i] + 1 << " ";
cout << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
380 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
380 KB |
Output is correct |
12 |
Correct |
2 ms |
380 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
3 ms |
376 KB |
Output is correct |
16 |
Correct |
3 ms |
504 KB |
Output is correct |
17 |
Correct |
3 ms |
504 KB |
Output is correct |
18 |
Correct |
3 ms |
508 KB |
Output is correct |
19 |
Correct |
6 ms |
1016 KB |
Output is correct |
20 |
Correct |
6 ms |
1016 KB |
Output is correct |
21 |
Correct |
6 ms |
1016 KB |
Output is correct |
22 |
Correct |
37 ms |
2956 KB |
Output is correct |
23 |
Correct |
39 ms |
4036 KB |
Output is correct |
24 |
Correct |
33 ms |
2516 KB |
Output is correct |
25 |
Correct |
38 ms |
2932 KB |
Output is correct |
26 |
Correct |
37 ms |
3012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
276 ms |
33416 KB |
Output is correct |
2 |
Correct |
317 ms |
33364 KB |
Output is correct |
3 |
Correct |
341 ms |
35320 KB |
Output is correct |
4 |
Correct |
258 ms |
33488 KB |
Output is correct |
5 |
Correct |
2494 ms |
33556 KB |
Output is correct |
6 |
Execution timed out |
3059 ms |
33700 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
743 ms |
13972 KB |
Output is correct |
3 |
Execution timed out |
3059 ms |
45308 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2377 ms |
76544 KB |
Output is correct |
2 |
Execution timed out |
3058 ms |
64912 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
380 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
380 KB |
Output is correct |
12 |
Correct |
2 ms |
380 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
3 ms |
376 KB |
Output is correct |
16 |
Correct |
3 ms |
504 KB |
Output is correct |
17 |
Correct |
3 ms |
504 KB |
Output is correct |
18 |
Correct |
3 ms |
508 KB |
Output is correct |
19 |
Correct |
6 ms |
1016 KB |
Output is correct |
20 |
Correct |
6 ms |
1016 KB |
Output is correct |
21 |
Correct |
6 ms |
1016 KB |
Output is correct |
22 |
Correct |
37 ms |
2956 KB |
Output is correct |
23 |
Correct |
39 ms |
4036 KB |
Output is correct |
24 |
Correct |
33 ms |
2516 KB |
Output is correct |
25 |
Correct |
38 ms |
2932 KB |
Output is correct |
26 |
Correct |
37 ms |
3012 KB |
Output is correct |
27 |
Correct |
12 ms |
1656 KB |
Output is correct |
28 |
Correct |
12 ms |
1624 KB |
Output is correct |
29 |
Correct |
12 ms |
1532 KB |
Output is correct |
30 |
Correct |
77 ms |
5628 KB |
Output is correct |
31 |
Correct |
61 ms |
4488 KB |
Output is correct |
32 |
Correct |
74 ms |
4716 KB |
Output is correct |
33 |
Correct |
87 ms |
11996 KB |
Output is correct |
34 |
Correct |
86 ms |
12024 KB |
Output is correct |
35 |
Correct |
109 ms |
11384 KB |
Output is correct |
36 |
Correct |
730 ms |
22916 KB |
Output is correct |
37 |
Correct |
913 ms |
34432 KB |
Output is correct |
38 |
Correct |
669 ms |
22492 KB |
Output is correct |
39 |
Correct |
748 ms |
12424 KB |
Output is correct |
40 |
Correct |
745 ms |
12508 KB |
Output is correct |
41 |
Correct |
731 ms |
12608 KB |
Output is correct |
42 |
Correct |
759 ms |
12348 KB |
Output is correct |
43 |
Correct |
1244 ms |
107036 KB |
Output is correct |
44 |
Correct |
1183 ms |
107084 KB |
Output is correct |
45 |
Correct |
1170 ms |
107276 KB |
Output is correct |
46 |
Correct |
1158 ms |
107196 KB |
Output is correct |
47 |
Correct |
1314 ms |
107232 KB |
Output is correct |
48 |
Correct |
1171 ms |
107248 KB |
Output is correct |
49 |
Correct |
1152 ms |
107120 KB |
Output is correct |
50 |
Correct |
1262 ms |
107116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
380 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
380 KB |
Output is correct |
12 |
Correct |
2 ms |
380 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
3 ms |
376 KB |
Output is correct |
16 |
Correct |
3 ms |
504 KB |
Output is correct |
17 |
Correct |
3 ms |
504 KB |
Output is correct |
18 |
Correct |
3 ms |
508 KB |
Output is correct |
19 |
Correct |
6 ms |
1016 KB |
Output is correct |
20 |
Correct |
6 ms |
1016 KB |
Output is correct |
21 |
Correct |
6 ms |
1016 KB |
Output is correct |
22 |
Correct |
37 ms |
2956 KB |
Output is correct |
23 |
Correct |
39 ms |
4036 KB |
Output is correct |
24 |
Correct |
33 ms |
2516 KB |
Output is correct |
25 |
Correct |
38 ms |
2932 KB |
Output is correct |
26 |
Correct |
37 ms |
3012 KB |
Output is correct |
27 |
Correct |
276 ms |
33416 KB |
Output is correct |
28 |
Correct |
317 ms |
33364 KB |
Output is correct |
29 |
Correct |
341 ms |
35320 KB |
Output is correct |
30 |
Correct |
258 ms |
33488 KB |
Output is correct |
31 |
Correct |
2494 ms |
33556 KB |
Output is correct |
32 |
Execution timed out |
3059 ms |
33700 KB |
Time limit exceeded |
33 |
Halted |
0 ms |
0 KB |
- |