#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("O2")
static const int K = 31;
static const int INF = 1000000000;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
int *x = new int[n];
int *y = new int[n];
int *r = new int[n];
int *ans = new int[n]();
vector<ll> pw;
for(ll v = 1; v <= 2LL*INF; v *= 10) pw.push_back(v);
int m = pw.size();
vector<unordered_map<ll, vector<int>>> mp(m);
for(int i = 0; i < n; i++){
cin >> x[i] >> y[i] >> r[i];
x[i] += INF;
y[i] += INF;
for(int j = 0; j < m; j++){
ll bx = x[i] / pw[j];
ll by = y[i] / pw[j];
ll key = (bx << K) | by;
mp[j][key].push_back(i);
}
}
vector<int> ord(n);
iota(ord.begin(), ord.end(), 0);
sort(ord.begin(), ord.end(), [&](int a,int b){
return (r[a] > r[b]) || (r[a] == r[b] && a < b);
});
auto overlap = [&](int i,int j){
ll dx = ll(x[i]) - x[j];
ll dy = ll(y[i]) - y[j];
ll R = ll(r[i]) + r[j];
return dx*dx + dy*dy <= R*R;
};
for(int idx: ord){
if(ans[idx]) continue;
int t = 0;
while(t < m && pw[t] < r[idx]) t++;
ll bx = x[idx] / pw[t];
ll by = y[idx] / pw[t];
for(int dxg = -2; dxg <= 2; dxg++){
for(int dyg = -2; dyg <= 2; dyg++){
ll cx = bx + dxg;
ll cy = by + dyg;
ll key = (cx << K) | cy;
auto it = mp[t].find(key);
if(it == mp[t].end()) continue;
auto &bucket = it->second;
vector<int> keep;
keep.reserve(bucket.size());
for(int j: bucket){
if(ans[j]) continue;
if(overlap(idx,j)) ans[j] = idx+1;
else keep.push_back(j);
}
if(keep.empty()) mp[t].erase(it);
else bucket.swap(keep);
}
}
}
for(int i = 0; i < n; i++) cout << ans[i] << ' ';
cout << '\n';
return 0;
}
# | 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... |