#include <bits/stdc++.h>
using namespace std;
#define int long long
struct pt {int x, y;};
pt operator -(pt a, pt b) {return {a.x - b.x, a.y - b.y};}
pt operator +(pt a, pt b) {return {a.x + b.x, a.y + b.y};}
int lensqr(pt a) {return a.x * a.x + a.y * a.y;}
const int K = 31;
const int N = 310000;
const int INF = (int)(1e9);
int n, r[N], ans[N];
pt p[N];
map<array<int, 2>, vector<int>> mp[K];
bool good(int i, int j) {
return lensqr(p[i] - p[j]) <= (r[i] + r[j]) * (r[i] + r[j]);
}
int32_t main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> p[i].x >> p[i].y >> r[i];
p[i] = p[i] + pt(INF, INF);
for (int j = 0; j < K; j++)
mp[j][{p[i].x >> j, p[i].y >> j}].push_back(i);
}
vector<int> ord(n);
iota(begin(ord), end(ord), 1);
sort(begin(ord), end(ord), [&](int i, int j) {
return r[i] > r[j] || (r[i] == r[j] && i < j);
});
for (int k : ord) {
if (ans[k]) continue;
int t = 0;
while ((1ll << t) < r[k])
t++;
int bx = p[k].x >> t;
int by = p[k].y >> t;
for (int dx = -2; dx <= 2; dx++)
for (int dy = -2; dy <= 2; dy++) {
int cx = bx + dx;
int cy = by + dy;
vector<int> vec;
for (auto i : mp[t][{cx, cy}]) {
if (ans[i]) continue;
if (good(i, k)) ans[i] = k;
else vec.push_back(i);
}
mp[t][{cx, cy}] = vec;
}
}
for (int i = 1; i <= n; i++)
cout << ans[i] << ' ';
}
# | 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... |