/*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)
{
ll ret = x + 157674864 * y;
ret %= 300000;
if (ret < 0)
ret += 300000;
return ret;
}
deque<int>xx[300000];
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) + 1568;
y[i] += ll(1e9) + 489484;
}
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);
deque<ll>liko;
deque<ll>::iterator itas[n];
for (ll i = 0; i < n; i++)
{
liko.push_back(i);
itas[i] = (--liko.end());
}
for (int i = 0; i < 300000; i++)
xx[i].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;
for (int c = 0; c < 300000; c++)
xx[c].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++)
{
deque<int>&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";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
212 ms |
202232 KB |
Output is correct |
2 |
Correct |
219 ms |
202328 KB |
Output is correct |
3 |
Correct |
213 ms |
202328 KB |
Output is correct |
4 |
Correct |
222 ms |
202360 KB |
Output is correct |
5 |
Correct |
208 ms |
202424 KB |
Output is correct |
6 |
Correct |
205 ms |
202296 KB |
Output is correct |
7 |
Correct |
209 ms |
202232 KB |
Output is correct |
8 |
Incorrect |
226 ms |
202336 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
675 ms |
460472 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
225 ms |
202360 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1217 ms |
462744 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
212 ms |
202232 KB |
Output is correct |
2 |
Correct |
219 ms |
202328 KB |
Output is correct |
3 |
Correct |
213 ms |
202328 KB |
Output is correct |
4 |
Correct |
222 ms |
202360 KB |
Output is correct |
5 |
Correct |
208 ms |
202424 KB |
Output is correct |
6 |
Correct |
205 ms |
202296 KB |
Output is correct |
7 |
Correct |
209 ms |
202232 KB |
Output is correct |
8 |
Incorrect |
226 ms |
202336 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
212 ms |
202232 KB |
Output is correct |
2 |
Correct |
219 ms |
202328 KB |
Output is correct |
3 |
Correct |
213 ms |
202328 KB |
Output is correct |
4 |
Correct |
222 ms |
202360 KB |
Output is correct |
5 |
Correct |
208 ms |
202424 KB |
Output is correct |
6 |
Correct |
205 ms |
202296 KB |
Output is correct |
7 |
Correct |
209 ms |
202232 KB |
Output is correct |
8 |
Incorrect |
226 ms |
202336 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |