#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
using namespace std;
typedef long long ll;
constexpr int INF = 1e9 + 100, CHK = 2;
struct Circle{
int x, y, r, i, xl, xr, yy;
Circle(){}
bool operator < (const Circle &C) const{
if (r==C.r) return i < C.i;
return r > C.r;
}
}C[300300];
int ans[300300];
int ok(int i, int j){
ll d = (ll)(C[i].x-C[j].x) * (C[i].x-C[j].x) + (ll)(C[i].y-C[j].y) * (C[i].y-C[j].y);
ll r = (ll)(C[i].r + C[j].r) * (C[i].r + C[j].r);
return d <= r;
}
struct Seg{
int sz;
map<int, int> tree[1201200];
map<int, int>::iterator iter0[30], iter[30];
int T[30], buf[30], pt, py = INF;
void init(int n){
sz = n;
}
void update(int l, int r, int y, int i){
r++;
for (l+=sz, r+=sz;l<r;l>>=1, r>>=1){
if (l&1){
tree[l][y] = i;
l++;
}
if (r&1){
--r;
tree[r][y] = i;
}
}
}
int queryU(int x, int y, int i){
pt = 0;
for (int node=x+sz;node>0;node>>=1){
if (y!=py || T[pt] != node) iter0[pt] = tree[node].lower_bound(y);
iter[pt] = iter0[pt];
T[pt] = node;
buf[pt] = (iter[pt]==tree[T[pt]].end())?INF:iter[pt]->first;
pt++;
}
py = y;
int ret = i;
for (int _=0;_<CHK;_++){
int idx = min_element(buf, buf+pt) - buf;
if (buf[idx]==INF) break;
if (ok(i, iter[idx]->second)) ret = min(ret, iter[idx]->second);
if (_+1 == CHK) break;
iter[idx]++;
buf[idx] = (iter[idx]==tree[T[idx]].end())?INF:iter[idx]->first;
}
return ret;
}
int queryD(int i){
for (int i=0;i<pt;i++){
iter[i] = iter0[i];
buf[i] = (iter[i]==tree[T[i]].begin())?(-INF):prev(iter[i])->first;
}
int ret = i;
for (int _=0;_<CHK;_++){
int idx = max_element(buf, buf+pt) - buf;
if (buf[idx]==-INF) break;
iter[idx]--;
if (ok(i, iter[idx]->second)) ret = min(ret, iter[idx]->second);
buf[idx] = (iter[idx]==tree[T[idx]].begin())?(-INF):prev(iter[idx])->first;
}
return ret;
}
}tree;
int calc(int x, int i){
int ret = i;
ret = min(ret, tree.queryU(x, C[i].yy, i));
ret = min(ret, tree.queryD(i));
return ret;
}
int main(){
ll a = 32154, b = 38591;
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<long double> X;
vector<ll> Y;
long double t = sqrtl(a*a + b*b);
for (int i=1;i<=n;i++){
cin >> C[i].x >> C[i].y >> C[i].r;
X.push_back((a*C[i].x+b*C[i].y) - t*C[i].r);
X.push_back((a*C[i].x+b*C[i].y) + t*C[i].r);
Y.push_back(-b*C[i].x+a*C[i].y);
C[i].i = i;
}
sort(X.begin(), X.end());
X.erase(unique(X.begin(), X.end()), X.end());
sort(Y.begin(), Y.end());
Y.erase(unique(Y.begin(), Y.end()), Y.end());
for (int i=1;i<=n;i++){
C[i].xl = lower_bound(X.begin(), X.end(), (a*C[i].x+b*C[i].y) - t*C[i].r) - X.begin();
C[i].xr = lower_bound(X.begin(), X.end(), (a*C[i].x+b*C[i].y) + t*C[i].r) - X.begin();
C[i].yy = lower_bound(Y.begin(), Y.end(), -b*C[i].x+a*C[i].y) - Y.begin();
}
sort(C+1, C+n+1);
tree.init(X.size());
for (int i=1;i<=n;i++){
ans[C[i].i] = min(calc(C[i].xl, i), calc(C[i].xr, i));
if (ans[C[i].i]==i) tree.update(C[i].xl, C[i].xr, C[i].yy, i);
ans[C[i].i] = C[ans[C[i].i]].i;
}
for (int i=1;i<=n;i++) printf("%d ", ans[i]);
printf("\n");
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
57944 KB |
Output is correct |
2 |
Correct |
12 ms |
57948 KB |
Output is correct |
3 |
Correct |
12 ms |
57948 KB |
Output is correct |
4 |
Correct |
11 ms |
58024 KB |
Output is correct |
5 |
Correct |
12 ms |
57944 KB |
Output is correct |
6 |
Correct |
12 ms |
57948 KB |
Output is correct |
7 |
Correct |
12 ms |
57948 KB |
Output is correct |
8 |
Correct |
13 ms |
57948 KB |
Output is correct |
9 |
Correct |
13 ms |
57948 KB |
Output is correct |
10 |
Correct |
11 ms |
57948 KB |
Output is correct |
11 |
Correct |
12 ms |
57948 KB |
Output is correct |
12 |
Correct |
12 ms |
57948 KB |
Output is correct |
13 |
Correct |
12 ms |
57948 KB |
Output is correct |
14 |
Correct |
13 ms |
57948 KB |
Output is correct |
15 |
Correct |
12 ms |
57948 KB |
Output is correct |
16 |
Correct |
13 ms |
57948 KB |
Output is correct |
17 |
Correct |
13 ms |
57948 KB |
Output is correct |
18 |
Correct |
13 ms |
58160 KB |
Output is correct |
19 |
Correct |
18 ms |
60528 KB |
Output is correct |
20 |
Correct |
18 ms |
60508 KB |
Output is correct |
21 |
Correct |
21 ms |
60508 KB |
Output is correct |
22 |
Correct |
22 ms |
60508 KB |
Output is correct |
23 |
Correct |
19 ms |
60508 KB |
Output is correct |
24 |
Correct |
19 ms |
60588 KB |
Output is correct |
25 |
Correct |
19 ms |
60504 KB |
Output is correct |
26 |
Correct |
18 ms |
60508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
599 ms |
86512 KB |
Output is correct |
2 |
Correct |
621 ms |
87480 KB |
Output is correct |
3 |
Correct |
623 ms |
86500 KB |
Output is correct |
4 |
Correct |
622 ms |
85664 KB |
Output is correct |
5 |
Correct |
609 ms |
86512 KB |
Output is correct |
6 |
Correct |
681 ms |
95448 KB |
Output is correct |
7 |
Correct |
615 ms |
86772 KB |
Output is correct |
8 |
Correct |
702 ms |
89068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
57948 KB |
Output is correct |
2 |
Correct |
404 ms |
88136 KB |
Output is correct |
3 |
Correct |
1257 ms |
145048 KB |
Output is correct |
4 |
Correct |
1262 ms |
144464 KB |
Output is correct |
5 |
Correct |
1214 ms |
135072 KB |
Output is correct |
6 |
Correct |
503 ms |
90616 KB |
Output is correct |
7 |
Correct |
186 ms |
73724 KB |
Output is correct |
8 |
Correct |
42 ms |
61704 KB |
Output is correct |
9 |
Correct |
1104 ms |
139004 KB |
Output is correct |
10 |
Correct |
1422 ms |
130148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
990 ms |
131760 KB |
Output is correct |
2 |
Correct |
543 ms |
95464 KB |
Output is correct |
3 |
Correct |
1020 ms |
90148 KB |
Output is correct |
4 |
Correct |
586 ms |
101588 KB |
Output is correct |
5 |
Correct |
587 ms |
100292 KB |
Output is correct |
6 |
Correct |
847 ms |
86772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
57944 KB |
Output is correct |
2 |
Correct |
12 ms |
57948 KB |
Output is correct |
3 |
Correct |
12 ms |
57948 KB |
Output is correct |
4 |
Correct |
11 ms |
58024 KB |
Output is correct |
5 |
Correct |
12 ms |
57944 KB |
Output is correct |
6 |
Correct |
12 ms |
57948 KB |
Output is correct |
7 |
Correct |
12 ms |
57948 KB |
Output is correct |
8 |
Correct |
13 ms |
57948 KB |
Output is correct |
9 |
Correct |
13 ms |
57948 KB |
Output is correct |
10 |
Correct |
11 ms |
57948 KB |
Output is correct |
11 |
Correct |
12 ms |
57948 KB |
Output is correct |
12 |
Correct |
12 ms |
57948 KB |
Output is correct |
13 |
Correct |
12 ms |
57948 KB |
Output is correct |
14 |
Correct |
13 ms |
57948 KB |
Output is correct |
15 |
Correct |
12 ms |
57948 KB |
Output is correct |
16 |
Correct |
13 ms |
57948 KB |
Output is correct |
17 |
Correct |
13 ms |
57948 KB |
Output is correct |
18 |
Correct |
13 ms |
58160 KB |
Output is correct |
19 |
Correct |
18 ms |
60528 KB |
Output is correct |
20 |
Correct |
18 ms |
60508 KB |
Output is correct |
21 |
Correct |
21 ms |
60508 KB |
Output is correct |
22 |
Correct |
22 ms |
60508 KB |
Output is correct |
23 |
Correct |
19 ms |
60508 KB |
Output is correct |
24 |
Correct |
19 ms |
60588 KB |
Output is correct |
25 |
Correct |
19 ms |
60504 KB |
Output is correct |
26 |
Correct |
18 ms |
60508 KB |
Output is correct |
27 |
Correct |
25 ms |
60696 KB |
Output is correct |
28 |
Correct |
25 ms |
60700 KB |
Output is correct |
29 |
Correct |
25 ms |
60700 KB |
Output is correct |
30 |
Correct |
25 ms |
61188 KB |
Output is correct |
31 |
Correct |
26 ms |
61464 KB |
Output is correct |
32 |
Correct |
25 ms |
61208 KB |
Output is correct |
33 |
Correct |
174 ms |
67872 KB |
Output is correct |
34 |
Correct |
180 ms |
68300 KB |
Output is correct |
35 |
Correct |
196 ms |
68600 KB |
Output is correct |
36 |
Correct |
259 ms |
80636 KB |
Output is correct |
37 |
Correct |
223 ms |
78076 KB |
Output is correct |
38 |
Correct |
280 ms |
82364 KB |
Output is correct |
39 |
Correct |
381 ms |
80124 KB |
Output is correct |
40 |
Correct |
374 ms |
80120 KB |
Output is correct |
41 |
Correct |
392 ms |
80120 KB |
Output is correct |
42 |
Correct |
340 ms |
75888 KB |
Output is correct |
43 |
Correct |
172 ms |
71968 KB |
Output is correct |
44 |
Correct |
178 ms |
71460 KB |
Output is correct |
45 |
Correct |
170 ms |
71224 KB |
Output is correct |
46 |
Correct |
190 ms |
71768 KB |
Output is correct |
47 |
Correct |
172 ms |
71904 KB |
Output is correct |
48 |
Correct |
204 ms |
71172 KB |
Output is correct |
49 |
Correct |
168 ms |
71220 KB |
Output is correct |
50 |
Correct |
177 ms |
71544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
57944 KB |
Output is correct |
2 |
Correct |
12 ms |
57948 KB |
Output is correct |
3 |
Correct |
12 ms |
57948 KB |
Output is correct |
4 |
Correct |
11 ms |
58024 KB |
Output is correct |
5 |
Correct |
12 ms |
57944 KB |
Output is correct |
6 |
Correct |
12 ms |
57948 KB |
Output is correct |
7 |
Correct |
12 ms |
57948 KB |
Output is correct |
8 |
Correct |
13 ms |
57948 KB |
Output is correct |
9 |
Correct |
13 ms |
57948 KB |
Output is correct |
10 |
Correct |
11 ms |
57948 KB |
Output is correct |
11 |
Correct |
12 ms |
57948 KB |
Output is correct |
12 |
Correct |
12 ms |
57948 KB |
Output is correct |
13 |
Correct |
12 ms |
57948 KB |
Output is correct |
14 |
Correct |
13 ms |
57948 KB |
Output is correct |
15 |
Correct |
12 ms |
57948 KB |
Output is correct |
16 |
Correct |
13 ms |
57948 KB |
Output is correct |
17 |
Correct |
13 ms |
57948 KB |
Output is correct |
18 |
Correct |
13 ms |
58160 KB |
Output is correct |
19 |
Correct |
18 ms |
60528 KB |
Output is correct |
20 |
Correct |
18 ms |
60508 KB |
Output is correct |
21 |
Correct |
21 ms |
60508 KB |
Output is correct |
22 |
Correct |
22 ms |
60508 KB |
Output is correct |
23 |
Correct |
19 ms |
60508 KB |
Output is correct |
24 |
Correct |
19 ms |
60588 KB |
Output is correct |
25 |
Correct |
19 ms |
60504 KB |
Output is correct |
26 |
Correct |
18 ms |
60508 KB |
Output is correct |
27 |
Correct |
599 ms |
86512 KB |
Output is correct |
28 |
Correct |
621 ms |
87480 KB |
Output is correct |
29 |
Correct |
623 ms |
86500 KB |
Output is correct |
30 |
Correct |
622 ms |
85664 KB |
Output is correct |
31 |
Correct |
609 ms |
86512 KB |
Output is correct |
32 |
Correct |
681 ms |
95448 KB |
Output is correct |
33 |
Correct |
615 ms |
86772 KB |
Output is correct |
34 |
Correct |
702 ms |
89068 KB |
Output is correct |
35 |
Correct |
12 ms |
57948 KB |
Output is correct |
36 |
Correct |
404 ms |
88136 KB |
Output is correct |
37 |
Correct |
1257 ms |
145048 KB |
Output is correct |
38 |
Correct |
1262 ms |
144464 KB |
Output is correct |
39 |
Correct |
1214 ms |
135072 KB |
Output is correct |
40 |
Correct |
503 ms |
90616 KB |
Output is correct |
41 |
Correct |
186 ms |
73724 KB |
Output is correct |
42 |
Correct |
42 ms |
61704 KB |
Output is correct |
43 |
Correct |
1104 ms |
139004 KB |
Output is correct |
44 |
Correct |
1422 ms |
130148 KB |
Output is correct |
45 |
Correct |
990 ms |
131760 KB |
Output is correct |
46 |
Correct |
543 ms |
95464 KB |
Output is correct |
47 |
Correct |
1020 ms |
90148 KB |
Output is correct |
48 |
Correct |
586 ms |
101588 KB |
Output is correct |
49 |
Correct |
587 ms |
100292 KB |
Output is correct |
50 |
Correct |
847 ms |
86772 KB |
Output is correct |
51 |
Correct |
25 ms |
60696 KB |
Output is correct |
52 |
Correct |
25 ms |
60700 KB |
Output is correct |
53 |
Correct |
25 ms |
60700 KB |
Output is correct |
54 |
Correct |
25 ms |
61188 KB |
Output is correct |
55 |
Correct |
26 ms |
61464 KB |
Output is correct |
56 |
Correct |
25 ms |
61208 KB |
Output is correct |
57 |
Correct |
174 ms |
67872 KB |
Output is correct |
58 |
Correct |
180 ms |
68300 KB |
Output is correct |
59 |
Correct |
196 ms |
68600 KB |
Output is correct |
60 |
Correct |
259 ms |
80636 KB |
Output is correct |
61 |
Correct |
223 ms |
78076 KB |
Output is correct |
62 |
Correct |
280 ms |
82364 KB |
Output is correct |
63 |
Correct |
381 ms |
80124 KB |
Output is correct |
64 |
Correct |
374 ms |
80120 KB |
Output is correct |
65 |
Correct |
392 ms |
80120 KB |
Output is correct |
66 |
Correct |
340 ms |
75888 KB |
Output is correct |
67 |
Correct |
172 ms |
71968 KB |
Output is correct |
68 |
Correct |
178 ms |
71460 KB |
Output is correct |
69 |
Correct |
170 ms |
71224 KB |
Output is correct |
70 |
Correct |
190 ms |
71768 KB |
Output is correct |
71 |
Correct |
172 ms |
71904 KB |
Output is correct |
72 |
Correct |
204 ms |
71172 KB |
Output is correct |
73 |
Correct |
168 ms |
71220 KB |
Output is correct |
74 |
Correct |
177 ms |
71544 KB |
Output is correct |
75 |
Correct |
627 ms |
87544 KB |
Output is correct |
76 |
Correct |
610 ms |
86000 KB |
Output is correct |
77 |
Correct |
598 ms |
87312 KB |
Output is correct |
78 |
Correct |
601 ms |
87540 KB |
Output is correct |
79 |
Correct |
721 ms |
87280 KB |
Output is correct |
80 |
Correct |
627 ms |
86376 KB |
Output is correct |
81 |
Correct |
1104 ms |
136040 KB |
Output is correct |
82 |
Correct |
1115 ms |
139928 KB |
Output is correct |
83 |
Correct |
1083 ms |
137156 KB |
Output is correct |
84 |
Correct |
1486 ms |
156856 KB |
Output is correct |
85 |
Correct |
1130 ms |
136544 KB |
Output is correct |
86 |
Correct |
1093 ms |
134704 KB |
Output is correct |
87 |
Correct |
1316 ms |
148968 KB |
Output is correct |
88 |
Correct |
1788 ms |
125168 KB |
Output is correct |
89 |
Correct |
1780 ms |
126544 KB |
Output is correct |
90 |
Correct |
1837 ms |
126420 KB |
Output is correct |
91 |
Correct |
1783 ms |
127084 KB |
Output is correct |
92 |
Correct |
1901 ms |
126708 KB |
Output is correct |
93 |
Correct |
572 ms |
95936 KB |
Output is correct |
94 |
Correct |
632 ms |
95212 KB |
Output is correct |
95 |
Correct |
618 ms |
96348 KB |
Output is correct |
96 |
Correct |
605 ms |
100140 KB |
Output is correct |
97 |
Correct |
576 ms |
96232 KB |
Output is correct |
98 |
Correct |
696 ms |
96744 KB |
Output is correct |
99 |
Correct |
583 ms |
96744 KB |
Output is correct |
100 |
Correct |
567 ms |
96576 KB |
Output is correct |
101 |
Correct |
875 ms |
109484 KB |
Output is correct |
102 |
Correct |
594 ms |
96524 KB |
Output is correct |
103 |
Correct |
609 ms |
97912 KB |
Output is correct |
104 |
Correct |
636 ms |
102116 KB |
Output is correct |
105 |
Correct |
1662 ms |
115396 KB |
Output is correct |
106 |
Correct |
577 ms |
102244 KB |
Output is correct |
107 |
Correct |
600 ms |
104360 KB |
Output is correct |
108 |
Correct |
601 ms |
104304 KB |
Output is correct |
109 |
Correct |
585 ms |
103912 KB |
Output is correct |
110 |
Correct |
591 ms |
104332 KB |
Output is correct |
111 |
Correct |
587 ms |
104424 KB |
Output is correct |
112 |
Correct |
595 ms |
104004 KB |
Output is correct |
113 |
Correct |
579 ms |
104424 KB |
Output is correct |
114 |
Correct |
591 ms |
103644 KB |
Output is correct |
115 |
Correct |
609 ms |
102904 KB |
Output is correct |
116 |
Correct |
595 ms |
103256 KB |
Output is correct |