#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1'000'000;
int n, x[N + 10], y[N + 10], r[N + 10];
int ans[N + 10], id[N + 10], sizeVecX;
int mark[N + 10], cnt[N + 10];
vector<int> vecX, vec;
set<pair<int, int>> s[4 * N + 10];
pair<int, int> p[N + 10];
void readInput() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> x[i] >> y[i] >> r[i];
p[i] = {-r[i], i};
}
}
void calcId() {
sort(p + 1, p + n + 1);
for (int i = 1; i <= n; i++)
id[i] = p[i].second;
}
void calcVecX() {
for (int i = 1; i <= n; i++) {
vecX.push_back(x[i] - r[i]);
vecX.push_back(x[i] + r[i]);
}
sort(vecX.begin(), vecX.end());
vecX.resize(unique(vecX.begin(), vecX.end()) - vecX.begin());
sizeVecX = (int) vecX.size();
}
int getIdx(int x) {
return lower_bound(vecX.begin(), vecX.end(), x) - vecX.begin();
}
void update(int idx, pair<int, int> p, int d, int id = 1, int l = 0, int r = sizeVecX) {
if (idx < l || r <= idx)
return;
if (d == 1)
s[id].insert(p);
else
s[id].erase(p);
if (l + 1 == r)
return;
int mid = (l + r) >> 1;
update(idx, p, d, id << 1, l, mid);
update(idx, p, d, id << 1 | 1, mid, r);
}
void changePoint(int idx, int d) {
for (int i = -1; i <= 1; i += 2)
for (int j = -1; j <= 1; j += 2) {
int nx = x[idx] + r[idx] * i;
int ny = y[idx] + r[idx] * j;
update(getIdx(nx), {ny, idx}, d);
}
}
void build() {
for (int i = 1; i <= n; i++)
changePoint(i, 1);
}
void check(int id, int l, int r) {
auto au = s[id].lower_bound({l, 0});
while (au != s[id].end() && au -> first <= r) {
vec.push_back(au -> second);
au++;
}
}
void get(int st, int en, int x, int y, int id = 1, int l = 0, int r = sizeVecX) {
if (en <= l || r <= st)
return;
if (st <= l && r <= en) {
check(id, x, y);
return;
}
int mid = (l + r) >> 1;
get(st, en, x, y, id << 1, l, mid);
get(st, en, x, y, id << 1 | 1, mid, r);
}
bool isGood(int i, int j) {
ll dx = x[i] - x[j], dy = y[i] - y[j];
return dx * dx + dy * dy <= (ll) (r[i] + r[j]) * (r[i] + r[j]) ;
}
void newPoint(int idx) {
vec.clear();
get(getIdx(x[idx] - r[idx]), getIdx(x[idx] + r[idx]) + 1, y[idx] - r[idx], y[idx] + r[idx]);
for (auto x: vec)
if (!mark[x]) {
if (isGood(x, idx)) {
ans[x] = idx;
changePoint(x, -1);
}
mark[x] = true;
cnt[x]++;
}
for (auto x: vec)
mark[x] = false;
}
void solve() {
for (int i = 1; i <= n; i++)
if (!ans[id[i]])
newPoint(id[i]);
}
void writeOutput() {
for (int i = 1; i <= n; i++)
cout << ans[i] << ' ';
cout.flush();
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
readInput();
calcId();
calcVecX();
build();
solve();
writeOutput();
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... |