#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
const int K = 3;
int N;
int X[303030];
int Y[303030];
int R[303030];
int XL[303030];
int XR[303030];
pii UL[303030][22];
pii UR[303030][22];
int V[303030][44];
int ulp[303030];
int urp[303030];
int vp[303030];
int ans[303030];
char rr;
struct DSU {
int n;
vector<int> l, r, c;
vector<bool> chk;
int cid;
void init(int _n) {
n = _n;
l.resize(n + 1); r.resize(n + 1);
c.resize(n); chk.resize(n);
cid = 0;
l[0] = -1; r[0] = n;
}
inline int left(int x) {
x = min(x, n - 1);
return x < 0 ? -1 : (chk[x] ? x : l[c[x]]);
}
inline int right(int x) {
x = max(x, 0);
return x >= n ? n : (chk[x] ? x : r[c[x]]);
}
void upd(int x) {
int lb = left(x), rb = right(x);
chk[x] = true;
cid++;
if (x - lb <= rb - x) {
for (int i = lb + 1; i < x; i++) c[i] = cid;
l[cid] = lb; r[cid] = x;
if (x < n - 1 && !chk[x + 1]) l[c[x + 1]] = x;
} else {
for (int i = x + 1; i < rb; i++) c[i] = cid;
l[cid] = x; r[cid] = rb;
if (x && !chk[x - 1]) r[c[x - 1]] = x;
}
}
};
void rf(int &x) {
x = 0;
int sgn = 0;
while (rr < 48 && rr != '-') rr = getchar();
if (rr == '-') { sgn = 1; rr = getchar(); }
while (47 < rr) { x = (x << 3) + (x << 1) + (rr & 15); rr = getchar(); }
if (sgn) x = -x;
}
inline bool intersect(int i, int j) {
int dx = X[i] - X[j], dy = Y[i] - Y[j], r = R[i] + R[j];
return (long long)dx * dx + (long long)dy * dy <= (long long)r * r;
}
inline void upd_ans(int cur, int cand) {
int &t = ans[cur];
if (R[t] > R[cand] || (R[t] == R[cand] && t < cand)) return;
if (intersect(cur, cand)) t = cand;
}
struct SegTree {
struct Node {
vector<pii> v;
DSU uf;
};
int n, base;
vector<Node> T;
SegTree(int _n) : n(_n) {
for (base = 1; base < n; base <<= 1);
T.resize(base + base);
}
void add_line(int p, int q, int y, int i) {
p += base; q += base;
p--; q--;
while (p <= q) {
if (p & 1) {
V[i][vp[i]++] = T[p].v.size();
T[p].v.emplace_back(y, i);
p++;
}
if (~q & 1) {
V[i][vp[i]++] = T[q].v.size();
T[q].v.emplace_back(y, i);
q--;
}
p >>= 1; q >>= 1;
}
}
void add_point(int p, int i, bool is_left) {
p += base; p--;
while (p) {
if (is_left) UL[i][ulp[i]++] = {p, (int)T[p].v.size()};
else UR[i][urp[i]++] = {p, (int)T[p].v.size()};
p >>= 1;
}
}
void init() {
for (int i = 1; i < base + base; i++) T[i].uf.init(T[i].v.size());
}
void upd(int p, int q, int i) {
p += base; q += base;
p--; q--;
int ptr = 0;
while (p <= q) {
if (p & 1) {
T[p].uf.upd(V[i][ptr++]);
p++;
}
if (~q & 1) {
T[q].uf.upd(V[i][ptr++]);
q--;
}
p >>= 1; q >>= 1;
}
}
void chk(int cur, bool is_left) {
if (is_left) {
for (int i = 0; i < ulp[cur]; i++) {
int p, s; tie(p, s) = UL[cur][i];
int t = s;
for (int j = 0; j < K; j++) {
t = T[p].uf.right(t);
if (t >= T[p].v.size()) break;
upd_ans(cur, T[p].v[t].second);
t++;
}
t = s;
for (int j = 0; j < K; j++) {
t = T[p].uf.left(t);
if (t < 0) break;
upd_ans(cur, T[p].v[t].second);
t--;
}
}
} else {
for (int i = 0; i < urp[cur]; i++) {
int p, s; tie(p, s) = UR[cur][i];
int t = s;
for (int j = 0; j < K; j++) {
t = T[p].uf.right(t);
if (t >= T[p].v.size()) break;
upd_ans(cur, T[p].v[t].second);
t++;
}
t = s;
for (int j = 0; j < K; j++) {
t = T[p].uf.left(t);
if (t < 0) break;
upd_ans(cur, T[p].v[t].second);
t--;
}
}
}
}
};
int main() {
rf(N);
vector<int> v;
for (int i = 1; i <= N; i++) {
rf(X[i]); rf(Y[i]); rf(R[i]);
XL[i] = X[i] - R[i];
XR[i] = X[i] + R[i];
v.push_back(XL[i]); v.push_back(XR[i]);
}
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
for (int i = 1; i <= N; i++) {
XL[i] = lower_bound(v.begin(), v.end(), XL[i]) - v.begin() + 1;
XR[i] = lower_bound(v.begin(), v.end(), XR[i]) - v.begin() + 1;
}
int M = v.size();
SegTree seg(M);
vector<int> ord(N);
iota(ord.begin(), ord.end(), 1);
sort(ord.begin(), ord.end(), [&](int a, int b) { return Y[a] < Y[b]; });
for (int i : ord) {
seg.add_line(XL[i], XR[i], Y[i], i);
seg.add_point(XL[i], i, true);
seg.add_point(XR[i], i, false);
}
seg.init();
sort(ord.begin(), ord.end(), [&](int a, int b) {
if (R[a] == R[b]) return a < b;
return R[a] > R[b];
});
for (int i : ord) {
ans[i] = i;
seg.chk(i, true);
seg.chk(i, false);
if (ans[i] == i) seg.upd(XL[i], XR[i], i);
}
for (int i = 1; i <= N; i++) printf("%d ", ans[i]); puts("");
return 0;
}
Compilation message
circle_selection.cpp: In member function 'void SegTree::chk(int, bool)':
circle_selection.cpp:152:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
152 | if (t >= T[p].v.size()) break;
| ~~^~~~~~~~~~~~~~~~
circle_selection.cpp:170:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
170 | if (t >= T[p].v.size()) break;
| ~~^~~~~~~~~~~~~~~~
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:227:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
227 | for (int i = 1; i <= N; i++) printf("%d ", ans[i]); puts("");
| ^~~
circle_selection.cpp:227:54: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
227 | for (int i = 1; i <= N; i++) printf("%d ", ans[i]); puts("");
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
12632 KB |
Output is correct |
2 |
Correct |
1 ms |
12632 KB |
Output is correct |
3 |
Correct |
2 ms |
12636 KB |
Output is correct |
4 |
Correct |
1 ms |
12636 KB |
Output is correct |
5 |
Correct |
2 ms |
12632 KB |
Output is correct |
6 |
Correct |
2 ms |
12892 KB |
Output is correct |
7 |
Correct |
2 ms |
12892 KB |
Output is correct |
8 |
Correct |
2 ms |
12892 KB |
Output is correct |
9 |
Correct |
2 ms |
12892 KB |
Output is correct |
10 |
Correct |
2 ms |
12892 KB |
Output is correct |
11 |
Correct |
2 ms |
12888 KB |
Output is correct |
12 |
Correct |
2 ms |
12892 KB |
Output is correct |
13 |
Correct |
2 ms |
12892 KB |
Output is correct |
14 |
Correct |
2 ms |
12892 KB |
Output is correct |
15 |
Correct |
2 ms |
12892 KB |
Output is correct |
16 |
Correct |
5 ms |
13916 KB |
Output is correct |
17 |
Correct |
4 ms |
13916 KB |
Output is correct |
18 |
Correct |
4 ms |
13916 KB |
Output is correct |
19 |
Correct |
16 ms |
23636 KB |
Output is correct |
20 |
Correct |
15 ms |
23644 KB |
Output is correct |
21 |
Correct |
17 ms |
23644 KB |
Output is correct |
22 |
Correct |
13 ms |
22616 KB |
Output is correct |
23 |
Correct |
18 ms |
23132 KB |
Output is correct |
24 |
Correct |
13 ms |
22620 KB |
Output is correct |
25 |
Correct |
12 ms |
22364 KB |
Output is correct |
26 |
Correct |
14 ms |
22680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1996 ms |
769404 KB |
Output is correct |
2 |
Correct |
2059 ms |
771876 KB |
Output is correct |
3 |
Correct |
2066 ms |
771072 KB |
Output is correct |
4 |
Correct |
2044 ms |
769536 KB |
Output is correct |
5 |
Correct |
1274 ms |
453996 KB |
Output is correct |
6 |
Correct |
1207 ms |
674284 KB |
Output is correct |
7 |
Correct |
1492 ms |
691024 KB |
Output is correct |
8 |
Correct |
1393 ms |
686256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
12636 KB |
Output is correct |
2 |
Correct |
563 ms |
204660 KB |
Output is correct |
3 |
Correct |
1978 ms |
695788 KB |
Output is correct |
4 |
Correct |
1971 ms |
696236 KB |
Output is correct |
5 |
Correct |
2303 ms |
703864 KB |
Output is correct |
6 |
Correct |
1025 ms |
364956 KB |
Output is correct |
7 |
Correct |
400 ms |
190652 KB |
Output is correct |
8 |
Correct |
60 ms |
52188 KB |
Output is correct |
9 |
Correct |
2060 ms |
698592 KB |
Output is correct |
10 |
Correct |
2708 ms |
715340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1593 ms |
690288 KB |
Output is correct |
2 |
Correct |
973 ms |
660408 KB |
Output is correct |
3 |
Correct |
2705 ms |
744524 KB |
Output is correct |
4 |
Correct |
1084 ms |
663736 KB |
Output is correct |
5 |
Correct |
1002 ms |
660664 KB |
Output is correct |
6 |
Correct |
2605 ms |
759036 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
12632 KB |
Output is correct |
2 |
Correct |
1 ms |
12632 KB |
Output is correct |
3 |
Correct |
2 ms |
12636 KB |
Output is correct |
4 |
Correct |
1 ms |
12636 KB |
Output is correct |
5 |
Correct |
2 ms |
12632 KB |
Output is correct |
6 |
Correct |
2 ms |
12892 KB |
Output is correct |
7 |
Correct |
2 ms |
12892 KB |
Output is correct |
8 |
Correct |
2 ms |
12892 KB |
Output is correct |
9 |
Correct |
2 ms |
12892 KB |
Output is correct |
10 |
Correct |
2 ms |
12892 KB |
Output is correct |
11 |
Correct |
2 ms |
12888 KB |
Output is correct |
12 |
Correct |
2 ms |
12892 KB |
Output is correct |
13 |
Correct |
2 ms |
12892 KB |
Output is correct |
14 |
Correct |
2 ms |
12892 KB |
Output is correct |
15 |
Correct |
2 ms |
12892 KB |
Output is correct |
16 |
Correct |
5 ms |
13916 KB |
Output is correct |
17 |
Correct |
4 ms |
13916 KB |
Output is correct |
18 |
Correct |
4 ms |
13916 KB |
Output is correct |
19 |
Correct |
16 ms |
23636 KB |
Output is correct |
20 |
Correct |
15 ms |
23644 KB |
Output is correct |
21 |
Correct |
17 ms |
23644 KB |
Output is correct |
22 |
Correct |
13 ms |
22616 KB |
Output is correct |
23 |
Correct |
18 ms |
23132 KB |
Output is correct |
24 |
Correct |
13 ms |
22620 KB |
Output is correct |
25 |
Correct |
12 ms |
22364 KB |
Output is correct |
26 |
Correct |
14 ms |
22680 KB |
Output is correct |
27 |
Correct |
35 ms |
34848 KB |
Output is correct |
28 |
Correct |
39 ms |
34908 KB |
Output is correct |
29 |
Correct |
36 ms |
34952 KB |
Output is correct |
30 |
Correct |
33 ms |
33372 KB |
Output is correct |
31 |
Correct |
31 ms |
32928 KB |
Output is correct |
32 |
Correct |
27 ms |
32600 KB |
Output is correct |
33 |
Correct |
464 ms |
223528 KB |
Output is correct |
34 |
Correct |
559 ms |
224932 KB |
Output is correct |
35 |
Correct |
579 ms |
226484 KB |
Output is correct |
36 |
Correct |
402 ms |
198696 KB |
Output is correct |
37 |
Correct |
425 ms |
199472 KB |
Output is correct |
38 |
Correct |
440 ms |
201144 KB |
Output is correct |
39 |
Correct |
155 ms |
72352 KB |
Output is correct |
40 |
Correct |
156 ms |
72200 KB |
Output is correct |
41 |
Correct |
153 ms |
72388 KB |
Output is correct |
42 |
Correct |
176 ms |
76232 KB |
Output is correct |
43 |
Correct |
259 ms |
193404 KB |
Output is correct |
44 |
Correct |
250 ms |
192164 KB |
Output is correct |
45 |
Correct |
255 ms |
192960 KB |
Output is correct |
46 |
Correct |
252 ms |
192896 KB |
Output is correct |
47 |
Correct |
252 ms |
191432 KB |
Output is correct |
48 |
Correct |
254 ms |
192912 KB |
Output is correct |
49 |
Correct |
255 ms |
190728 KB |
Output is correct |
50 |
Correct |
248 ms |
192156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
12632 KB |
Output is correct |
2 |
Correct |
1 ms |
12632 KB |
Output is correct |
3 |
Correct |
2 ms |
12636 KB |
Output is correct |
4 |
Correct |
1 ms |
12636 KB |
Output is correct |
5 |
Correct |
2 ms |
12632 KB |
Output is correct |
6 |
Correct |
2 ms |
12892 KB |
Output is correct |
7 |
Correct |
2 ms |
12892 KB |
Output is correct |
8 |
Correct |
2 ms |
12892 KB |
Output is correct |
9 |
Correct |
2 ms |
12892 KB |
Output is correct |
10 |
Correct |
2 ms |
12892 KB |
Output is correct |
11 |
Correct |
2 ms |
12888 KB |
Output is correct |
12 |
Correct |
2 ms |
12892 KB |
Output is correct |
13 |
Correct |
2 ms |
12892 KB |
Output is correct |
14 |
Correct |
2 ms |
12892 KB |
Output is correct |
15 |
Correct |
2 ms |
12892 KB |
Output is correct |
16 |
Correct |
5 ms |
13916 KB |
Output is correct |
17 |
Correct |
4 ms |
13916 KB |
Output is correct |
18 |
Correct |
4 ms |
13916 KB |
Output is correct |
19 |
Correct |
16 ms |
23636 KB |
Output is correct |
20 |
Correct |
15 ms |
23644 KB |
Output is correct |
21 |
Correct |
17 ms |
23644 KB |
Output is correct |
22 |
Correct |
13 ms |
22616 KB |
Output is correct |
23 |
Correct |
18 ms |
23132 KB |
Output is correct |
24 |
Correct |
13 ms |
22620 KB |
Output is correct |
25 |
Correct |
12 ms |
22364 KB |
Output is correct |
26 |
Correct |
14 ms |
22680 KB |
Output is correct |
27 |
Correct |
1996 ms |
769404 KB |
Output is correct |
28 |
Correct |
2059 ms |
771876 KB |
Output is correct |
29 |
Correct |
2066 ms |
771072 KB |
Output is correct |
30 |
Correct |
2044 ms |
769536 KB |
Output is correct |
31 |
Correct |
1274 ms |
453996 KB |
Output is correct |
32 |
Correct |
1207 ms |
674284 KB |
Output is correct |
33 |
Correct |
1492 ms |
691024 KB |
Output is correct |
34 |
Correct |
1393 ms |
686256 KB |
Output is correct |
35 |
Correct |
2 ms |
12636 KB |
Output is correct |
36 |
Correct |
563 ms |
204660 KB |
Output is correct |
37 |
Correct |
1978 ms |
695788 KB |
Output is correct |
38 |
Correct |
1971 ms |
696236 KB |
Output is correct |
39 |
Correct |
2303 ms |
703864 KB |
Output is correct |
40 |
Correct |
1025 ms |
364956 KB |
Output is correct |
41 |
Correct |
400 ms |
190652 KB |
Output is correct |
42 |
Correct |
60 ms |
52188 KB |
Output is correct |
43 |
Correct |
2060 ms |
698592 KB |
Output is correct |
44 |
Correct |
2708 ms |
715340 KB |
Output is correct |
45 |
Correct |
1593 ms |
690288 KB |
Output is correct |
46 |
Correct |
973 ms |
660408 KB |
Output is correct |
47 |
Correct |
2705 ms |
744524 KB |
Output is correct |
48 |
Correct |
1084 ms |
663736 KB |
Output is correct |
49 |
Correct |
1002 ms |
660664 KB |
Output is correct |
50 |
Correct |
2605 ms |
759036 KB |
Output is correct |
51 |
Correct |
35 ms |
34848 KB |
Output is correct |
52 |
Correct |
39 ms |
34908 KB |
Output is correct |
53 |
Correct |
36 ms |
34952 KB |
Output is correct |
54 |
Correct |
33 ms |
33372 KB |
Output is correct |
55 |
Correct |
31 ms |
32928 KB |
Output is correct |
56 |
Correct |
27 ms |
32600 KB |
Output is correct |
57 |
Correct |
464 ms |
223528 KB |
Output is correct |
58 |
Correct |
559 ms |
224932 KB |
Output is correct |
59 |
Correct |
579 ms |
226484 KB |
Output is correct |
60 |
Correct |
402 ms |
198696 KB |
Output is correct |
61 |
Correct |
425 ms |
199472 KB |
Output is correct |
62 |
Correct |
440 ms |
201144 KB |
Output is correct |
63 |
Correct |
155 ms |
72352 KB |
Output is correct |
64 |
Correct |
156 ms |
72200 KB |
Output is correct |
65 |
Correct |
153 ms |
72388 KB |
Output is correct |
66 |
Correct |
176 ms |
76232 KB |
Output is correct |
67 |
Correct |
259 ms |
193404 KB |
Output is correct |
68 |
Correct |
250 ms |
192164 KB |
Output is correct |
69 |
Correct |
255 ms |
192960 KB |
Output is correct |
70 |
Correct |
252 ms |
192896 KB |
Output is correct |
71 |
Correct |
252 ms |
191432 KB |
Output is correct |
72 |
Correct |
254 ms |
192912 KB |
Output is correct |
73 |
Correct |
255 ms |
190728 KB |
Output is correct |
74 |
Correct |
248 ms |
192156 KB |
Output is correct |
75 |
Correct |
2182 ms |
771464 KB |
Output is correct |
76 |
Correct |
2164 ms |
770292 KB |
Output is correct |
77 |
Correct |
1783 ms |
767900 KB |
Output is correct |
78 |
Correct |
1898 ms |
766104 KB |
Output is correct |
79 |
Correct |
2249 ms |
764852 KB |
Output is correct |
80 |
Correct |
1924 ms |
765940 KB |
Output is correct |
81 |
Correct |
1863 ms |
693176 KB |
Output is correct |
82 |
Correct |
1700 ms |
688484 KB |
Output is correct |
83 |
Correct |
1684 ms |
689520 KB |
Output is correct |
84 |
Correct |
2155 ms |
701964 KB |
Output is correct |
85 |
Correct |
1808 ms |
692824 KB |
Output is correct |
86 |
Correct |
1664 ms |
688312 KB |
Output is correct |
87 |
Execution timed out |
3086 ms |
723324 KB |
Time limit exceeded |
88 |
Halted |
0 ms |
0 KB |
- |