This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cassert>
#include <vector>
#include <unordered_map>
typedef long long ll;
typedef double ld;
typedef std::vector<int> Vint;
#define radius x
#define idx y
const int LEN = 3e5 + 5;
inline ll sq(const ll& x) { return x * x; }
int N;
int V[LEN];
struct Pos {
ll x, y;
Pos(ll X = 0, ll Y = 0) : x(X), y(Y) {}
Pos operator + (const Pos& p) const { return { x + p.x, y + p.y }; }
Pos operator - (const Pos& p) const { return { x - p.x, y - p.y }; }
Pos operator * (const int& n) const { return { x * n, y * n }; }
Pos operator / (const int& n) const { return { x / n, y / n }; }
Pos operator ^ (const Pos& p) const { return { x * p.x, y * p.y }; }
Pos& operator += (const Pos& p) { x += p.x; y += p.y; return *this; }
ll Euc() const { return (ll)x * x + (ll)y * y; }
friend std::istream& operator >> (std::istream& is, Pos& p) { is >> p.x >> p.y; return is; }
friend std::ostream& operator << (std::ostream& os, const Pos& p) { os << p.x << " " << p.y; return os; }
};
typedef std::vector<Pos> Polygon;
struct Circle {
Pos c;
ll r;
Circle(Pos C = Pos(0, 0), ll R = 0) : c(C), r(R) {}
bool meet(const Circle& q) const { return sq(r + q.r) >= (c - q.c).Euc(); }
friend std::istream& operator >> (std::istream& is, Circle& c) { is >> c.c >> c.r; return is; }
friend std::ostream& operator << (std::ostream& os, const Circle& c) { os << c.c << " " << c.r; return os; }
};
bool cmpri(const Pos& p, const Pos& q) { return p.radius == q.radius ? p.idx < q.idx : p.radius > q.radius; }
typedef std::vector<Circle> Disks;
typedef std::unordered_map<ll, Vint> Table;
Table idxs;
ll key(const Pos& p, const int& ex) { return ((p.x / (1ll << ex)) << 32) | (p.y / (1ll << ex)); }
void grid_init(Table& T, const Disks& C, const int& ex) {
T.clear();
int sz = C.size();
for (int i = 0; i < sz; i++) {
if (V[i]) continue;
const Pos& p = C[i].c;
T[key(p, ex)].push_back(i);
}
return;
}
void solve() {
std::cin.tie(0)->sync_with_stdio(0);
std::cout.tie(0);
std::cout << std::fixed;
std::cout.precision(15);
std::cin >> N;
Polygon R(N);
Disks C(N);
Pos w = Pos(1ll << 30, 1ll << 30);
for (int i = 0; i < N; i++) {
std::cin >> C[i];
C[i].c += w;
R[i] = Pos(C[i].r, i);
}
std::sort(R.begin(), R.end(), cmpri);
memset(V, 0, sizeof V);
int ex = 30;//exponent of the interval dividing the grid
while ((1ll << ex) >= (R[0].radius) * 2) ex--;
grid_init(idxs, C, ex);
for (int i = 0; i < N; i++) {
if (V[R[i].idx]) continue;
if ((1ll << ex) >= (R[i].radius) * 2) {
while ((1ll << ex) >= (R[i].radius) * 2) ex--;
grid_init(idxs, C, ex);
}
int I = R[i].idx;
Pos p = C[I].c;
for (int x = -2; x <= 2; x++) {
for (int y = -2; y <= 2; y++) {
ll dx = (1ll << ex) * x, dy = (1ll << ex) * y;
ll K = key(p + Pos(dx, dy), ex);
if (!idxs.count(K)) continue;
const Vint& vi = idxs[K];
for (const int& v : vi) {
if (V[v]) continue;
if (C[I].meet(C[v])) V[v] = I + 1;
}
}
}
}
for (int i = 0; i < N; i++) std::cout << V[i] << " ";
return;
}
int main() { solve(); return 0; }//APIO 2018 B boj15767 Circle selection
//refer to jjang36524
//https://jjang36524.tistory.com/26
//https://codeforces.com/blog/entry/59650
# | 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... |