#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 long double ld;
typedef double ld;
typedef std::pair<int, int> pi;
typedef std::vector<int> Vint;
typedef std::vector<ld> Vld;
#define radius x
#define idx y
const ld INF = 1e17;
const ld TOL = 1e-10;
const ld PI = acos(-1);
const int LEN = 3e5 + 5;
inline bool zero(const ld& x) { return std::abs(x) < TOL; }
inline int sign(const ld& x) { return x < -TOL ? -1 : x > TOL; }
inline ll sq(const ll& x) { return x * x; }
int N, M, Q;
int V[LEN];
struct Pos {
ll x, y;
Pos(ll X = 0, ll Y = 0) : x(X), y(Y) {}
bool operator == (const Pos& p) const { return x == p.x && y == p.y; }
bool operator != (const Pos& p) const { return x != p.x || y != p.y; }
bool operator < (const Pos& p) const { return x == p.x ? y < p.y : x < p.x; }
bool operator <= (const Pos& p) const { return x == p.x ? y <= p.y : x <= p.x; }
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 }; }
ll operator * (const Pos& p) const { return (ll)x * p.x + (ll)y * p.y; }
ll operator / (const Pos& p) const { return (ll)x * p.y - (ll)y * p.x; }
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; }
Pos& operator -= (const Pos& p) { x -= p.x; y -= p.y; return *this; }
Pos& operator *= (const int& scale) { x *= scale; y *= scale; return *this; }
Pos& operator /= (const int& scale) { x /= scale; y /= scale; return *this; }
Pos operator - () const { return { -x, -y }; }
Pos operator ~ () const { return { -y, x }; }
Pos operator ! () const { return { y, x }; }
ll xy() const { return (ll)x * y; }
ll Euc() const { return (ll)x * x + (ll)y * y; }
ll Man() const { return std::abs(x) + std::abs(y); }
ld mag() const { return hypot(x, y); }
ld rad() const { return atan2(y, x); }
friend ld rad(const Pos& p1, const Pos& p2) { return atan2l(p1 / p2, p1 * p2); }
int quad() const { return y > 0 || y == 0 && x >= 0; }
friend bool cmpq(const Pos& a, const Pos& b) { return (a.quad() != b.quad()) ? a.quad() < b.quad() : a / b > 0; }
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; }
}; const Pos O = Pos(0, 0);
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 operator == (const Circle& q) const { return c == q.c && r == q.r; }
bool operator != (const Circle& q) const { return !(*this == q); }
bool operator < (const Circle& q) const { return r < q.r && (c - q.c).Euc() <= sq(q.r - r); }
bool operator <= (const Circle& q) const { return *this < q || *this == q; }
bool meet(const Circle& q) const { return sq(r + q.r) >= (c - q.c).Euc(); }
bool operator > (const Pos& p) const { return r > (c - p).mag(); }
bool operator >= (const Pos& p) const { return r + TOL > (c - p).mag(); }
bool operator < (const Pos& p) const { return r < (c - p).mag(); }
Circle operator + (const Circle& C) const { return { c + C.c, r + C.r }; }
Circle operator - (const Circle& C) const { return { c - C.c, r - C.r }; }
ld H(const ld& th) const { return sin(th) * c.x + cos(th) * c.y + r; }//coord trans | check right
ld A() const { return 1. * r * r * PI; }
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; }
} INVAL = { { 0, 0 }, -1 };
bool cmpr(const Circle& p, const Circle& q) { return p.r > q.r; }//sort descending order
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;
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
Compilation message
circle_selection.cpp: In member function 'int Pos::quad() const':
circle_selection.cpp:54:44: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
54 | int quad() const { return y > 0 || y == 0 && x >= 0; }
| ~~~~~~~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1628 KB |
Output is correct |
2 |
Correct |
1 ms |
1632 KB |
Output is correct |
3 |
Correct |
1 ms |
1416 KB |
Output is correct |
4 |
Correct |
1 ms |
1488 KB |
Output is correct |
5 |
Correct |
1 ms |
1628 KB |
Output is correct |
6 |
Correct |
1 ms |
1484 KB |
Output is correct |
7 |
Correct |
1 ms |
1624 KB |
Output is correct |
8 |
Correct |
1 ms |
1628 KB |
Output is correct |
9 |
Correct |
1 ms |
1628 KB |
Output is correct |
10 |
Correct |
1 ms |
1628 KB |
Output is correct |
11 |
Correct |
1 ms |
1628 KB |
Output is correct |
12 |
Correct |
1 ms |
1628 KB |
Output is correct |
13 |
Correct |
1 ms |
1488 KB |
Output is correct |
14 |
Correct |
1 ms |
1628 KB |
Output is correct |
15 |
Correct |
1 ms |
1628 KB |
Output is correct |
16 |
Correct |
1 ms |
1696 KB |
Output is correct |
17 |
Correct |
1 ms |
1628 KB |
Output is correct |
18 |
Correct |
1 ms |
1628 KB |
Output is correct |
19 |
Correct |
3 ms |
1880 KB |
Output is correct |
20 |
Correct |
2 ms |
1884 KB |
Output is correct |
21 |
Correct |
3 ms |
1884 KB |
Output is correct |
22 |
Correct |
6 ms |
2396 KB |
Output is correct |
23 |
Correct |
6 ms |
2244 KB |
Output is correct |
24 |
Correct |
6 ms |
2396 KB |
Output is correct |
25 |
Correct |
5 ms |
2396 KB |
Output is correct |
26 |
Correct |
6 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
105 ms |
22272 KB |
Output is correct |
2 |
Correct |
102 ms |
22220 KB |
Output is correct |
3 |
Correct |
107 ms |
23496 KB |
Output is correct |
4 |
Correct |
103 ms |
22260 KB |
Output is correct |
5 |
Correct |
115 ms |
22096 KB |
Output is correct |
6 |
Correct |
206 ms |
30476 KB |
Output is correct |
7 |
Correct |
120 ms |
23124 KB |
Output is correct |
8 |
Correct |
140 ms |
24748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1880 KB |
Output is correct |
2 |
Correct |
139 ms |
18052 KB |
Output is correct |
3 |
Correct |
449 ms |
49532 KB |
Output is correct |
4 |
Correct |
499 ms |
49608 KB |
Output is correct |
5 |
Correct |
403 ms |
45436 KB |
Output is correct |
6 |
Correct |
162 ms |
23580 KB |
Output is correct |
7 |
Correct |
77 ms |
13152 KB |
Output is correct |
8 |
Correct |
16 ms |
4076 KB |
Output is correct |
9 |
Correct |
528 ms |
48848 KB |
Output is correct |
10 |
Correct |
331 ms |
43712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
450 ms |
49296 KB |
Output is correct |
2 |
Correct |
427 ms |
48468 KB |
Output is correct |
3 |
Correct |
153 ms |
30052 KB |
Output is correct |
4 |
Correct |
480 ms |
48848 KB |
Output is correct |
5 |
Correct |
543 ms |
49020 KB |
Output is correct |
6 |
Correct |
122 ms |
26196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1628 KB |
Output is correct |
2 |
Correct |
1 ms |
1632 KB |
Output is correct |
3 |
Correct |
1 ms |
1416 KB |
Output is correct |
4 |
Correct |
1 ms |
1488 KB |
Output is correct |
5 |
Correct |
1 ms |
1628 KB |
Output is correct |
6 |
Correct |
1 ms |
1484 KB |
Output is correct |
7 |
Correct |
1 ms |
1624 KB |
Output is correct |
8 |
Correct |
1 ms |
1628 KB |
Output is correct |
9 |
Correct |
1 ms |
1628 KB |
Output is correct |
10 |
Correct |
1 ms |
1628 KB |
Output is correct |
11 |
Correct |
1 ms |
1628 KB |
Output is correct |
12 |
Correct |
1 ms |
1628 KB |
Output is correct |
13 |
Correct |
1 ms |
1488 KB |
Output is correct |
14 |
Correct |
1 ms |
1628 KB |
Output is correct |
15 |
Correct |
1 ms |
1628 KB |
Output is correct |
16 |
Correct |
1 ms |
1696 KB |
Output is correct |
17 |
Correct |
1 ms |
1628 KB |
Output is correct |
18 |
Correct |
1 ms |
1628 KB |
Output is correct |
19 |
Correct |
3 ms |
1880 KB |
Output is correct |
20 |
Correct |
2 ms |
1884 KB |
Output is correct |
21 |
Correct |
3 ms |
1884 KB |
Output is correct |
22 |
Correct |
6 ms |
2396 KB |
Output is correct |
23 |
Correct |
6 ms |
2244 KB |
Output is correct |
24 |
Correct |
6 ms |
2396 KB |
Output is correct |
25 |
Correct |
5 ms |
2396 KB |
Output is correct |
26 |
Correct |
6 ms |
2396 KB |
Output is correct |
27 |
Correct |
4 ms |
2264 KB |
Output is correct |
28 |
Correct |
4 ms |
2260 KB |
Output is correct |
29 |
Correct |
4 ms |
2396 KB |
Output is correct |
30 |
Correct |
12 ms |
3172 KB |
Output is correct |
31 |
Correct |
15 ms |
3164 KB |
Output is correct |
32 |
Correct |
11 ms |
3164 KB |
Output is correct |
33 |
Correct |
40 ms |
9684 KB |
Output is correct |
34 |
Correct |
37 ms |
9684 KB |
Output is correct |
35 |
Correct |
40 ms |
9280 KB |
Output is correct |
36 |
Correct |
124 ms |
17608 KB |
Output is correct |
37 |
Correct |
123 ms |
17860 KB |
Output is correct |
38 |
Correct |
118 ms |
17920 KB |
Output is correct |
39 |
Correct |
118 ms |
15304 KB |
Output is correct |
40 |
Correct |
118 ms |
15240 KB |
Output is correct |
41 |
Correct |
111 ms |
15192 KB |
Output is correct |
42 |
Correct |
60 ms |
13160 KB |
Output is correct |
43 |
Correct |
114 ms |
17600 KB |
Output is correct |
44 |
Correct |
109 ms |
17672 KB |
Output is correct |
45 |
Correct |
110 ms |
17608 KB |
Output is correct |
46 |
Correct |
105 ms |
17616 KB |
Output is correct |
47 |
Correct |
106 ms |
17672 KB |
Output is correct |
48 |
Correct |
110 ms |
17596 KB |
Output is correct |
49 |
Correct |
123 ms |
17548 KB |
Output is correct |
50 |
Correct |
102 ms |
17924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1628 KB |
Output is correct |
2 |
Correct |
1 ms |
1632 KB |
Output is correct |
3 |
Correct |
1 ms |
1416 KB |
Output is correct |
4 |
Correct |
1 ms |
1488 KB |
Output is correct |
5 |
Correct |
1 ms |
1628 KB |
Output is correct |
6 |
Correct |
1 ms |
1484 KB |
Output is correct |
7 |
Correct |
1 ms |
1624 KB |
Output is correct |
8 |
Correct |
1 ms |
1628 KB |
Output is correct |
9 |
Correct |
1 ms |
1628 KB |
Output is correct |
10 |
Correct |
1 ms |
1628 KB |
Output is correct |
11 |
Correct |
1 ms |
1628 KB |
Output is correct |
12 |
Correct |
1 ms |
1628 KB |
Output is correct |
13 |
Correct |
1 ms |
1488 KB |
Output is correct |
14 |
Correct |
1 ms |
1628 KB |
Output is correct |
15 |
Correct |
1 ms |
1628 KB |
Output is correct |
16 |
Correct |
1 ms |
1696 KB |
Output is correct |
17 |
Correct |
1 ms |
1628 KB |
Output is correct |
18 |
Correct |
1 ms |
1628 KB |
Output is correct |
19 |
Correct |
3 ms |
1880 KB |
Output is correct |
20 |
Correct |
2 ms |
1884 KB |
Output is correct |
21 |
Correct |
3 ms |
1884 KB |
Output is correct |
22 |
Correct |
6 ms |
2396 KB |
Output is correct |
23 |
Correct |
6 ms |
2244 KB |
Output is correct |
24 |
Correct |
6 ms |
2396 KB |
Output is correct |
25 |
Correct |
5 ms |
2396 KB |
Output is correct |
26 |
Correct |
6 ms |
2396 KB |
Output is correct |
27 |
Correct |
105 ms |
22272 KB |
Output is correct |
28 |
Correct |
102 ms |
22220 KB |
Output is correct |
29 |
Correct |
107 ms |
23496 KB |
Output is correct |
30 |
Correct |
103 ms |
22260 KB |
Output is correct |
31 |
Correct |
115 ms |
22096 KB |
Output is correct |
32 |
Correct |
206 ms |
30476 KB |
Output is correct |
33 |
Correct |
120 ms |
23124 KB |
Output is correct |
34 |
Correct |
140 ms |
24748 KB |
Output is correct |
35 |
Correct |
1 ms |
1880 KB |
Output is correct |
36 |
Correct |
139 ms |
18052 KB |
Output is correct |
37 |
Correct |
449 ms |
49532 KB |
Output is correct |
38 |
Correct |
499 ms |
49608 KB |
Output is correct |
39 |
Correct |
403 ms |
45436 KB |
Output is correct |
40 |
Correct |
162 ms |
23580 KB |
Output is correct |
41 |
Correct |
77 ms |
13152 KB |
Output is correct |
42 |
Correct |
16 ms |
4076 KB |
Output is correct |
43 |
Correct |
528 ms |
48848 KB |
Output is correct |
44 |
Correct |
331 ms |
43712 KB |
Output is correct |
45 |
Correct |
450 ms |
49296 KB |
Output is correct |
46 |
Correct |
427 ms |
48468 KB |
Output is correct |
47 |
Correct |
153 ms |
30052 KB |
Output is correct |
48 |
Correct |
480 ms |
48848 KB |
Output is correct |
49 |
Correct |
543 ms |
49020 KB |
Output is correct |
50 |
Correct |
122 ms |
26196 KB |
Output is correct |
51 |
Correct |
4 ms |
2264 KB |
Output is correct |
52 |
Correct |
4 ms |
2260 KB |
Output is correct |
53 |
Correct |
4 ms |
2396 KB |
Output is correct |
54 |
Correct |
12 ms |
3172 KB |
Output is correct |
55 |
Correct |
15 ms |
3164 KB |
Output is correct |
56 |
Correct |
11 ms |
3164 KB |
Output is correct |
57 |
Correct |
40 ms |
9684 KB |
Output is correct |
58 |
Correct |
37 ms |
9684 KB |
Output is correct |
59 |
Correct |
40 ms |
9280 KB |
Output is correct |
60 |
Correct |
124 ms |
17608 KB |
Output is correct |
61 |
Correct |
123 ms |
17860 KB |
Output is correct |
62 |
Correct |
118 ms |
17920 KB |
Output is correct |
63 |
Correct |
118 ms |
15304 KB |
Output is correct |
64 |
Correct |
118 ms |
15240 KB |
Output is correct |
65 |
Correct |
111 ms |
15192 KB |
Output is correct |
66 |
Correct |
60 ms |
13160 KB |
Output is correct |
67 |
Correct |
114 ms |
17600 KB |
Output is correct |
68 |
Correct |
109 ms |
17672 KB |
Output is correct |
69 |
Correct |
110 ms |
17608 KB |
Output is correct |
70 |
Correct |
105 ms |
17616 KB |
Output is correct |
71 |
Correct |
106 ms |
17672 KB |
Output is correct |
72 |
Correct |
110 ms |
17596 KB |
Output is correct |
73 |
Correct |
123 ms |
17548 KB |
Output is correct |
74 |
Correct |
102 ms |
17924 KB |
Output is correct |
75 |
Correct |
130 ms |
24488 KB |
Output is correct |
76 |
Correct |
132 ms |
24308 KB |
Output is correct |
77 |
Correct |
105 ms |
25652 KB |
Output is correct |
78 |
Correct |
119 ms |
25620 KB |
Output is correct |
79 |
Correct |
121 ms |
24084 KB |
Output is correct |
80 |
Correct |
105 ms |
25372 KB |
Output is correct |
81 |
Correct |
548 ms |
49488 KB |
Output is correct |
82 |
Correct |
472 ms |
49500 KB |
Output is correct |
83 |
Correct |
499 ms |
49356 KB |
Output is correct |
84 |
Correct |
410 ms |
49744 KB |
Output is correct |
85 |
Correct |
462 ms |
49356 KB |
Output is correct |
86 |
Correct |
410 ms |
49532 KB |
Output is correct |
87 |
Correct |
455 ms |
49240 KB |
Output is correct |
88 |
Correct |
411 ms |
41372 KB |
Output is correct |
89 |
Correct |
361 ms |
41252 KB |
Output is correct |
90 |
Correct |
370 ms |
41316 KB |
Output is correct |
91 |
Correct |
378 ms |
41344 KB |
Output is correct |
92 |
Correct |
353 ms |
41168 KB |
Output is correct |
93 |
Correct |
430 ms |
48376 KB |
Output is correct |
94 |
Correct |
467 ms |
48712 KB |
Output is correct |
95 |
Correct |
438 ms |
48504 KB |
Output is correct |
96 |
Correct |
437 ms |
48448 KB |
Output is correct |
97 |
Correct |
418 ms |
48256 KB |
Output is correct |
98 |
Correct |
300 ms |
35388 KB |
Output is correct |
99 |
Correct |
446 ms |
48508 KB |
Output is correct |
100 |
Correct |
418 ms |
48380 KB |
Output is correct |
101 |
Correct |
338 ms |
40576 KB |
Output is correct |
102 |
Correct |
454 ms |
47996 KB |
Output is correct |
103 |
Correct |
509 ms |
47432 KB |
Output is correct |
104 |
Correct |
491 ms |
48252 KB |
Output is correct |
105 |
Correct |
196 ms |
36992 KB |
Output is correct |
106 |
Correct |
385 ms |
47488 KB |
Output is correct |
107 |
Correct |
428 ms |
47668 KB |
Output is correct |
108 |
Correct |
427 ms |
47740 KB |
Output is correct |
109 |
Correct |
374 ms |
47744 KB |
Output is correct |
110 |
Correct |
432 ms |
47744 KB |
Output is correct |
111 |
Correct |
364 ms |
47696 KB |
Output is correct |
112 |
Correct |
440 ms |
47740 KB |
Output is correct |
113 |
Correct |
405 ms |
47660 KB |
Output is correct |
114 |
Correct |
410 ms |
47756 KB |
Output is correct |
115 |
Correct |
361 ms |
47612 KB |
Output is correct |
116 |
Correct |
406 ms |
47584 KB |
Output is correct |