# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
895812 | 2023-12-30T21:45:26 Z | MilosMilutinovic | Circle selection (APIO18_circle_selection) | C++14 | 0 ms | 0 KB |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<long long> x(n), y(n), r(n); for (int i = 0; i < n; i++) { cin >> x[i] >> y[i] >> r[i]; } vector<int> order(n); iota(order.begin(), order.end(), 0); sort(order.begin(), order.end(), [&](int i, int j) { if (r[i] != r[j]) { return r[i] > r[j]; } else { return i < j; } }); auto Good = [&](int i, int j) { return (x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]) <= (r[i] + r[j]) * (r[i] + r[j]); }; vector<int> res(n); iota(res.begin(), res.end(), 0); for (int pw = 30; pw >= 0; pw--) { int k = (1 << pw); vector<tuple<long long, long long, int>> v; for (int i = 0; i < n; i++) { if (res[i] != i) { continue; } v.emplace_back(x[i] / k, y[i] / k, i); } sort(v.begin(), v.end()); for (int i : order) { if (res[i] != i || r[i] < (1 << (j - 1))) { continue; } for (int dx = -2; dx <= 2; dx++) { int ptr = (int) (lower_bound(v.begin(), v.end(), make_tuple(x[i] / k - dx, y[i] / k - 2, -1)) - v.begin()); while (ptr < (int) v.size() && get<0>(v[ptr]) == x[i] / k - dx && abs((y[i] / k) - get<1>(v[ptr])) <= 2) { if (Good(i, get<2>(v[ptr]))) { int idx = get<2>(v[ptr]); if (res[idx] == idx && (r[idx] < r[i] || (r[i] == r[idx] && idx > i))) { res[idx] = i; } } ptr += 1; } } } } for (int i = 0; i < n; i++) { cout << res[i] + 1 << " "; } cout << '\n'; return 0; }