This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |