#include <bits/stdc++.h>
using namespace std;
using ll = 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};}
ll lensqr(pt a) {return 1ll * a.x * a.x + 1ll * 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];
unordered_map<ll, vector<int>> mp[K];
bool good(int i, int j) {
return lensqr(p[i] - p[j]) <= 1ll * (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][(((ll) p[i].x >> j) << K) + (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;
int id = (((ll) cx >> t) << K) + (cy >> t);
if (mp[t].find(id) == mp[t].end())
continue;
if (mp[t][id].empty()) {
mp[t].erase(id);
continue;
}
vector<int> vec;
for (auto i : mp[t][id]) {
if (ans[i]) continue;
if (good(i, k)) ans[i] = k;
else vec.push_back(i);
}
mp[t][id] = 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... |