#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int INF = 1e9 + 100, CHK = 2;
struct Circle{
int x, y, r, i, xl, xr;
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;
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){
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++;
}
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);
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].y, i));
ret = min(ret, tree.queryD(i));
return ret;
}
int main(){
int n;
scanf("%d", &n);
vector<int> X;
for (int i=1;i<=n;i++){
scanf("%d %d %d", &C[i].x, &C[i].y, &C[i].r);
X.push_back(C[i].x - C[i].r);
X.push_back(C[i].x + C[i].r);
C[i].i = i;
}
sort(X.begin(), X.end());
X.erase(unique(X.begin(), X.end()), X.end());
for (int i=1;i<=n;i++){
C[i].xl = lower_bound(X.begin(), X.end(), C[i].x - C[i].r) - X.begin();
C[i].xr = lower_bound(X.begin(), X.end(), C[i].x + C[i].r) - X.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].y, i);
ans[C[i].i] = C[ans[C[i].i]].i;
}
for (int i=1;i<=n;i++) printf("%d ", ans[i]);
printf("\n");
}
Compilation message
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:108:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
108 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
circle_selection.cpp:112:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
112 | scanf("%d %d %d", &C[i].x, &C[i].y, &C[i].r);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
57944 KB |
Output is correct |
2 |
Correct |
12 ms |
57944 KB |
Output is correct |
3 |
Correct |
12 ms |
58064 KB |
Output is correct |
4 |
Correct |
13 ms |
57948 KB |
Output is correct |
5 |
Correct |
12 ms |
57948 KB |
Output is correct |
6 |
Correct |
12 ms |
58012 KB |
Output is correct |
7 |
Correct |
12 ms |
57944 KB |
Output is correct |
8 |
Correct |
14 ms |
57944 KB |
Output is correct |
9 |
Correct |
12 ms |
57944 KB |
Output is correct |
10 |
Correct |
11 ms |
57948 KB |
Output is correct |
11 |
Correct |
12 ms |
57960 KB |
Output is correct |
12 |
Correct |
12 ms |
57948 KB |
Output is correct |
13 |
Correct |
12 ms |
57948 KB |
Output is correct |
14 |
Correct |
12 ms |
57948 KB |
Output is correct |
15 |
Correct |
12 ms |
58044 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 |
58016 KB |
Output is correct |
19 |
Correct |
17 ms |
60252 KB |
Output is correct |
20 |
Correct |
17 ms |
60228 KB |
Output is correct |
21 |
Correct |
17 ms |
59992 KB |
Output is correct |
22 |
Correct |
20 ms |
60508 KB |
Output is correct |
23 |
Correct |
22 ms |
61372 KB |
Output is correct |
24 |
Correct |
17 ms |
60504 KB |
Output is correct |
25 |
Correct |
18 ms |
60252 KB |
Output is correct |
26 |
Correct |
20 ms |
60504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
443 ms |
70680 KB |
Output is correct |
2 |
Correct |
448 ms |
69588 KB |
Output is correct |
3 |
Correct |
454 ms |
70844 KB |
Output is correct |
4 |
Correct |
441 ms |
70268 KB |
Output is correct |
5 |
Correct |
393 ms |
71664 KB |
Output is correct |
6 |
Correct |
471 ms |
80480 KB |
Output is correct |
7 |
Correct |
479 ms |
73732 KB |
Output is correct |
8 |
Correct |
468 ms |
74204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
58072 KB |
Output is correct |
2 |
Correct |
315 ms |
85652 KB |
Output is correct |
3 |
Correct |
1129 ms |
136416 KB |
Output is correct |
4 |
Correct |
1118 ms |
135604 KB |
Output is correct |
5 |
Correct |
1335 ms |
132724 KB |
Output is correct |
6 |
Correct |
522 ms |
87380 KB |
Output is correct |
7 |
Correct |
179 ms |
70664 KB |
Output is correct |
8 |
Correct |
32 ms |
61400 KB |
Output is correct |
9 |
Correct |
1243 ms |
139016 KB |
Output is correct |
10 |
Correct |
1579 ms |
127624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
913 ms |
127412 KB |
Output is correct |
2 |
Correct |
410 ms |
91496 KB |
Output is correct |
3 |
Correct |
877 ms |
77264 KB |
Output is correct |
4 |
Correct |
468 ms |
95084 KB |
Output is correct |
5 |
Correct |
428 ms |
93140 KB |
Output is correct |
6 |
Correct |
752 ms |
71216 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
57944 KB |
Output is correct |
2 |
Correct |
12 ms |
57944 KB |
Output is correct |
3 |
Correct |
12 ms |
58064 KB |
Output is correct |
4 |
Correct |
13 ms |
57948 KB |
Output is correct |
5 |
Correct |
12 ms |
57948 KB |
Output is correct |
6 |
Correct |
12 ms |
58012 KB |
Output is correct |
7 |
Correct |
12 ms |
57944 KB |
Output is correct |
8 |
Correct |
14 ms |
57944 KB |
Output is correct |
9 |
Correct |
12 ms |
57944 KB |
Output is correct |
10 |
Correct |
11 ms |
57948 KB |
Output is correct |
11 |
Correct |
12 ms |
57960 KB |
Output is correct |
12 |
Correct |
12 ms |
57948 KB |
Output is correct |
13 |
Correct |
12 ms |
57948 KB |
Output is correct |
14 |
Correct |
12 ms |
57948 KB |
Output is correct |
15 |
Correct |
12 ms |
58044 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 |
58016 KB |
Output is correct |
19 |
Correct |
17 ms |
60252 KB |
Output is correct |
20 |
Correct |
17 ms |
60228 KB |
Output is correct |
21 |
Correct |
17 ms |
59992 KB |
Output is correct |
22 |
Correct |
20 ms |
60508 KB |
Output is correct |
23 |
Correct |
22 ms |
61372 KB |
Output is correct |
24 |
Correct |
17 ms |
60504 KB |
Output is correct |
25 |
Correct |
18 ms |
60252 KB |
Output is correct |
26 |
Correct |
20 ms |
60504 KB |
Output is correct |
27 |
Correct |
22 ms |
60248 KB |
Output is correct |
28 |
Correct |
23 ms |
60252 KB |
Output is correct |
29 |
Correct |
23 ms |
60252 KB |
Output is correct |
30 |
Correct |
29 ms |
62012 KB |
Output is correct |
31 |
Correct |
26 ms |
61276 KB |
Output is correct |
32 |
Correct |
24 ms |
61192 KB |
Output is correct |
33 |
Correct |
126 ms |
63540 KB |
Output is correct |
34 |
Correct |
134 ms |
63428 KB |
Output is correct |
35 |
Correct |
145 ms |
63588 KB |
Output is correct |
36 |
Correct |
199 ms |
76240 KB |
Output is correct |
37 |
Correct |
190 ms |
76492 KB |
Output is correct |
38 |
Correct |
240 ms |
78792 KB |
Output is correct |
39 |
Correct |
175 ms |
66308 KB |
Output is correct |
40 |
Correct |
173 ms |
66400 KB |
Output is correct |
41 |
Correct |
178 ms |
66500 KB |
Output is correct |
42 |
Correct |
178 ms |
66592 KB |
Output is correct |
43 |
Correct |
132 ms |
69984 KB |
Output is correct |
44 |
Correct |
132 ms |
69732 KB |
Output is correct |
45 |
Correct |
130 ms |
70080 KB |
Output is correct |
46 |
Correct |
134 ms |
69984 KB |
Output is correct |
47 |
Correct |
132 ms |
69432 KB |
Output is correct |
48 |
Correct |
138 ms |
70216 KB |
Output is correct |
49 |
Correct |
133 ms |
69064 KB |
Output is correct |
50 |
Correct |
134 ms |
69728 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
57944 KB |
Output is correct |
2 |
Correct |
12 ms |
57944 KB |
Output is correct |
3 |
Correct |
12 ms |
58064 KB |
Output is correct |
4 |
Correct |
13 ms |
57948 KB |
Output is correct |
5 |
Correct |
12 ms |
57948 KB |
Output is correct |
6 |
Correct |
12 ms |
58012 KB |
Output is correct |
7 |
Correct |
12 ms |
57944 KB |
Output is correct |
8 |
Correct |
14 ms |
57944 KB |
Output is correct |
9 |
Correct |
12 ms |
57944 KB |
Output is correct |
10 |
Correct |
11 ms |
57948 KB |
Output is correct |
11 |
Correct |
12 ms |
57960 KB |
Output is correct |
12 |
Correct |
12 ms |
57948 KB |
Output is correct |
13 |
Correct |
12 ms |
57948 KB |
Output is correct |
14 |
Correct |
12 ms |
57948 KB |
Output is correct |
15 |
Correct |
12 ms |
58044 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 |
58016 KB |
Output is correct |
19 |
Correct |
17 ms |
60252 KB |
Output is correct |
20 |
Correct |
17 ms |
60228 KB |
Output is correct |
21 |
Correct |
17 ms |
59992 KB |
Output is correct |
22 |
Correct |
20 ms |
60508 KB |
Output is correct |
23 |
Correct |
22 ms |
61372 KB |
Output is correct |
24 |
Correct |
17 ms |
60504 KB |
Output is correct |
25 |
Correct |
18 ms |
60252 KB |
Output is correct |
26 |
Correct |
20 ms |
60504 KB |
Output is correct |
27 |
Correct |
443 ms |
70680 KB |
Output is correct |
28 |
Correct |
448 ms |
69588 KB |
Output is correct |
29 |
Correct |
454 ms |
70844 KB |
Output is correct |
30 |
Correct |
441 ms |
70268 KB |
Output is correct |
31 |
Correct |
393 ms |
71664 KB |
Output is correct |
32 |
Correct |
471 ms |
80480 KB |
Output is correct |
33 |
Correct |
479 ms |
73732 KB |
Output is correct |
34 |
Correct |
468 ms |
74204 KB |
Output is correct |
35 |
Correct |
13 ms |
58072 KB |
Output is correct |
36 |
Correct |
315 ms |
85652 KB |
Output is correct |
37 |
Correct |
1129 ms |
136416 KB |
Output is correct |
38 |
Correct |
1118 ms |
135604 KB |
Output is correct |
39 |
Correct |
1335 ms |
132724 KB |
Output is correct |
40 |
Correct |
522 ms |
87380 KB |
Output is correct |
41 |
Correct |
179 ms |
70664 KB |
Output is correct |
42 |
Correct |
32 ms |
61400 KB |
Output is correct |
43 |
Correct |
1243 ms |
139016 KB |
Output is correct |
44 |
Correct |
1579 ms |
127624 KB |
Output is correct |
45 |
Correct |
913 ms |
127412 KB |
Output is correct |
46 |
Correct |
410 ms |
91496 KB |
Output is correct |
47 |
Correct |
877 ms |
77264 KB |
Output is correct |
48 |
Correct |
468 ms |
95084 KB |
Output is correct |
49 |
Correct |
428 ms |
93140 KB |
Output is correct |
50 |
Correct |
752 ms |
71216 KB |
Output is correct |
51 |
Correct |
22 ms |
60248 KB |
Output is correct |
52 |
Correct |
23 ms |
60252 KB |
Output is correct |
53 |
Correct |
23 ms |
60252 KB |
Output is correct |
54 |
Correct |
29 ms |
62012 KB |
Output is correct |
55 |
Correct |
26 ms |
61276 KB |
Output is correct |
56 |
Correct |
24 ms |
61192 KB |
Output is correct |
57 |
Correct |
126 ms |
63540 KB |
Output is correct |
58 |
Correct |
134 ms |
63428 KB |
Output is correct |
59 |
Correct |
145 ms |
63588 KB |
Output is correct |
60 |
Correct |
199 ms |
76240 KB |
Output is correct |
61 |
Correct |
190 ms |
76492 KB |
Output is correct |
62 |
Correct |
240 ms |
78792 KB |
Output is correct |
63 |
Correct |
175 ms |
66308 KB |
Output is correct |
64 |
Correct |
173 ms |
66400 KB |
Output is correct |
65 |
Correct |
178 ms |
66500 KB |
Output is correct |
66 |
Correct |
178 ms |
66592 KB |
Output is correct |
67 |
Correct |
132 ms |
69984 KB |
Output is correct |
68 |
Correct |
132 ms |
69732 KB |
Output is correct |
69 |
Correct |
130 ms |
70080 KB |
Output is correct |
70 |
Correct |
134 ms |
69984 KB |
Output is correct |
71 |
Correct |
132 ms |
69432 KB |
Output is correct |
72 |
Correct |
138 ms |
70216 KB |
Output is correct |
73 |
Correct |
133 ms |
69064 KB |
Output is correct |
74 |
Correct |
134 ms |
69728 KB |
Output is correct |
75 |
Correct |
455 ms |
69720 KB |
Output is correct |
76 |
Correct |
458 ms |
70068 KB |
Output is correct |
77 |
Correct |
423 ms |
69400 KB |
Output is correct |
78 |
Correct |
468 ms |
70600 KB |
Output is correct |
79 |
Correct |
611 ms |
71312 KB |
Output is correct |
80 |
Correct |
438 ms |
70956 KB |
Output is correct |
81 |
Correct |
1029 ms |
130600 KB |
Output is correct |
82 |
Correct |
929 ms |
121016 KB |
Output is correct |
83 |
Correct |
897 ms |
122672 KB |
Output is correct |
84 |
Correct |
1314 ms |
146972 KB |
Output is correct |
85 |
Correct |
988 ms |
127332 KB |
Output is correct |
86 |
Correct |
830 ms |
119712 KB |
Output is correct |
87 |
Correct |
2537 ms |
189384 KB |
Output is correct |
88 |
Correct |
568 ms |
79268 KB |
Output is correct |
89 |
Correct |
587 ms |
79360 KB |
Output is correct |
90 |
Correct |
615 ms |
79588 KB |
Output is correct |
91 |
Correct |
659 ms |
78692 KB |
Output is correct |
92 |
Correct |
585 ms |
79740 KB |
Output is correct |
93 |
Correct |
460 ms |
92132 KB |
Output is correct |
94 |
Correct |
2924 ms |
146884 KB |
Output is correct |
95 |
Correct |
431 ms |
90528 KB |
Output is correct |
96 |
Correct |
444 ms |
92276 KB |
Output is correct |
97 |
Correct |
1895 ms |
121980 KB |
Output is correct |
98 |
Correct |
495 ms |
83012 KB |
Output is correct |
99 |
Correct |
430 ms |
91320 KB |
Output is correct |
100 |
Correct |
452 ms |
91304 KB |
Output is correct |
101 |
Correct |
675 ms |
94640 KB |
Output is correct |
102 |
Correct |
456 ms |
90928 KB |
Output is correct |
103 |
Execution timed out |
3051 ms |
144100 KB |
Time limit exceeded |
104 |
Halted |
0 ms |
0 KB |
- |