#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;
for (int i=0;i<sz*2;i++){
tree[i][-INF] = 0;
tree[i][INF] = 0;
}
}
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];
buf[pt] = 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]->first;
}
return ret;
}
int queryD(int i){
for (int i=0;i<pt;i++){
iter[i] = prev(iter0[i]);
buf[i] = iter[i]->first;
}
int ret = i;
for (int _=0;_<CHK;_++){
int idx = max_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]->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:111:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
111 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
circle_selection.cpp:115:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
115 | scanf("%d %d %d", &C[i].x, &C[i].y, &C[i].r);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
57948 KB |
Output is correct |
2 |
Correct |
12 ms |
58008 KB |
Output is correct |
3 |
Correct |
12 ms |
58008 KB |
Output is correct |
4 |
Correct |
12 ms |
57968 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 |
57948 KB |
Output is correct |
8 |
Correct |
12 ms |
58020 KB |
Output is correct |
9 |
Correct |
12 ms |
57948 KB |
Output is correct |
10 |
Correct |
13 ms |
57948 KB |
Output is correct |
11 |
Correct |
12 ms |
57944 KB |
Output is correct |
12 |
Correct |
12 ms |
57948 KB |
Output is correct |
13 |
Correct |
12 ms |
57944 KB |
Output is correct |
14 |
Correct |
12 ms |
57944 KB |
Output is correct |
15 |
Correct |
12 ms |
57948 KB |
Output is correct |
16 |
Correct |
13 ms |
58460 KB |
Output is correct |
17 |
Correct |
13 ms |
58460 KB |
Output is correct |
18 |
Correct |
13 ms |
58252 KB |
Output is correct |
19 |
Correct |
19 ms |
62044 KB |
Output is correct |
20 |
Correct |
19 ms |
62040 KB |
Output is correct |
21 |
Correct |
20 ms |
62040 KB |
Output is correct |
22 |
Correct |
21 ms |
62556 KB |
Output is correct |
23 |
Correct |
25 ms |
63064 KB |
Output is correct |
24 |
Correct |
20 ms |
62524 KB |
Output is correct |
25 |
Correct |
20 ms |
62300 KB |
Output is correct |
26 |
Correct |
20 ms |
62300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
742 ms |
182532 KB |
Output is correct |
2 |
Correct |
829 ms |
182200 KB |
Output is correct |
3 |
Correct |
790 ms |
182860 KB |
Output is correct |
4 |
Correct |
799 ms |
183436 KB |
Output is correct |
5 |
Correct |
743 ms |
125112 KB |
Output is correct |
6 |
Correct |
827 ms |
191156 KB |
Output is correct |
7 |
Correct |
850 ms |
171932 KB |
Output is correct |
8 |
Correct |
823 ms |
179388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
58080 KB |
Output is correct |
2 |
Correct |
486 ms |
123484 KB |
Output is correct |
3 |
Correct |
1582 ms |
249596 KB |
Output is correct |
4 |
Correct |
1596 ms |
248716 KB |
Output is correct |
5 |
Correct |
1805 ms |
243196 KB |
Output is correct |
6 |
Correct |
734 ms |
145932 KB |
Output is correct |
7 |
Correct |
288 ms |
101744 KB |
Output is correct |
8 |
Correct |
43 ms |
67704 KB |
Output is correct |
9 |
Correct |
1693 ms |
251980 KB |
Output is correct |
10 |
Correct |
2013 ms |
240708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1315 ms |
238976 KB |
Output is correct |
2 |
Correct |
740 ms |
203296 KB |
Output is correct |
3 |
Correct |
1267 ms |
190380 KB |
Output is correct |
4 |
Correct |
804 ms |
208572 KB |
Output is correct |
5 |
Correct |
762 ms |
205328 KB |
Output is correct |
6 |
Correct |
1115 ms |
183952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
57948 KB |
Output is correct |
2 |
Correct |
12 ms |
58008 KB |
Output is correct |
3 |
Correct |
12 ms |
58008 KB |
Output is correct |
4 |
Correct |
12 ms |
57968 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 |
57948 KB |
Output is correct |
8 |
Correct |
12 ms |
58020 KB |
Output is correct |
9 |
Correct |
12 ms |
57948 KB |
Output is correct |
10 |
Correct |
13 ms |
57948 KB |
Output is correct |
11 |
Correct |
12 ms |
57944 KB |
Output is correct |
12 |
Correct |
12 ms |
57948 KB |
Output is correct |
13 |
Correct |
12 ms |
57944 KB |
Output is correct |
14 |
Correct |
12 ms |
57944 KB |
Output is correct |
15 |
Correct |
12 ms |
57948 KB |
Output is correct |
16 |
Correct |
13 ms |
58460 KB |
Output is correct |
17 |
Correct |
13 ms |
58460 KB |
Output is correct |
18 |
Correct |
13 ms |
58252 KB |
Output is correct |
19 |
Correct |
19 ms |
62044 KB |
Output is correct |
20 |
Correct |
19 ms |
62040 KB |
Output is correct |
21 |
Correct |
20 ms |
62040 KB |
Output is correct |
22 |
Correct |
21 ms |
62556 KB |
Output is correct |
23 |
Correct |
25 ms |
63064 KB |
Output is correct |
24 |
Correct |
20 ms |
62524 KB |
Output is correct |
25 |
Correct |
20 ms |
62300 KB |
Output is correct |
26 |
Correct |
20 ms |
62300 KB |
Output is correct |
27 |
Correct |
27 ms |
63836 KB |
Output is correct |
28 |
Correct |
27 ms |
63836 KB |
Output is correct |
29 |
Correct |
27 ms |
63900 KB |
Output is correct |
30 |
Correct |
45 ms |
65616 KB |
Output is correct |
31 |
Correct |
37 ms |
64948 KB |
Output is correct |
32 |
Correct |
29 ms |
64860 KB |
Output is correct |
33 |
Correct |
216 ms |
101068 KB |
Output is correct |
34 |
Correct |
228 ms |
101060 KB |
Output is correct |
35 |
Correct |
244 ms |
101028 KB |
Output is correct |
36 |
Correct |
312 ms |
113716 KB |
Output is correct |
37 |
Correct |
335 ms |
114216 KB |
Output is correct |
38 |
Correct |
349 ms |
116316 KB |
Output is correct |
39 |
Correct |
173 ms |
66504 KB |
Output is correct |
40 |
Correct |
172 ms |
66608 KB |
Output is correct |
41 |
Correct |
176 ms |
66500 KB |
Output is correct |
42 |
Correct |
181 ms |
67000 KB |
Output is correct |
43 |
Correct |
230 ms |
107464 KB |
Output is correct |
44 |
Correct |
234 ms |
107104 KB |
Output is correct |
45 |
Correct |
241 ms |
107644 KB |
Output is correct |
46 |
Correct |
230 ms |
107712 KB |
Output is correct |
47 |
Correct |
242 ms |
106988 KB |
Output is correct |
48 |
Correct |
229 ms |
107756 KB |
Output is correct |
49 |
Correct |
233 ms |
106488 KB |
Output is correct |
50 |
Correct |
230 ms |
107444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
57948 KB |
Output is correct |
2 |
Correct |
12 ms |
58008 KB |
Output is correct |
3 |
Correct |
12 ms |
58008 KB |
Output is correct |
4 |
Correct |
12 ms |
57968 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 |
57948 KB |
Output is correct |
8 |
Correct |
12 ms |
58020 KB |
Output is correct |
9 |
Correct |
12 ms |
57948 KB |
Output is correct |
10 |
Correct |
13 ms |
57948 KB |
Output is correct |
11 |
Correct |
12 ms |
57944 KB |
Output is correct |
12 |
Correct |
12 ms |
57948 KB |
Output is correct |
13 |
Correct |
12 ms |
57944 KB |
Output is correct |
14 |
Correct |
12 ms |
57944 KB |
Output is correct |
15 |
Correct |
12 ms |
57948 KB |
Output is correct |
16 |
Correct |
13 ms |
58460 KB |
Output is correct |
17 |
Correct |
13 ms |
58460 KB |
Output is correct |
18 |
Correct |
13 ms |
58252 KB |
Output is correct |
19 |
Correct |
19 ms |
62044 KB |
Output is correct |
20 |
Correct |
19 ms |
62040 KB |
Output is correct |
21 |
Correct |
20 ms |
62040 KB |
Output is correct |
22 |
Correct |
21 ms |
62556 KB |
Output is correct |
23 |
Correct |
25 ms |
63064 KB |
Output is correct |
24 |
Correct |
20 ms |
62524 KB |
Output is correct |
25 |
Correct |
20 ms |
62300 KB |
Output is correct |
26 |
Correct |
20 ms |
62300 KB |
Output is correct |
27 |
Correct |
742 ms |
182532 KB |
Output is correct |
28 |
Correct |
829 ms |
182200 KB |
Output is correct |
29 |
Correct |
790 ms |
182860 KB |
Output is correct |
30 |
Correct |
799 ms |
183436 KB |
Output is correct |
31 |
Correct |
743 ms |
125112 KB |
Output is correct |
32 |
Correct |
827 ms |
191156 KB |
Output is correct |
33 |
Correct |
850 ms |
171932 KB |
Output is correct |
34 |
Correct |
823 ms |
179388 KB |
Output is correct |
35 |
Correct |
14 ms |
58080 KB |
Output is correct |
36 |
Correct |
486 ms |
123484 KB |
Output is correct |
37 |
Correct |
1582 ms |
249596 KB |
Output is correct |
38 |
Correct |
1596 ms |
248716 KB |
Output is correct |
39 |
Correct |
1805 ms |
243196 KB |
Output is correct |
40 |
Correct |
734 ms |
145932 KB |
Output is correct |
41 |
Correct |
288 ms |
101744 KB |
Output is correct |
42 |
Correct |
43 ms |
67704 KB |
Output is correct |
43 |
Correct |
1693 ms |
251980 KB |
Output is correct |
44 |
Correct |
2013 ms |
240708 KB |
Output is correct |
45 |
Correct |
1315 ms |
238976 KB |
Output is correct |
46 |
Correct |
740 ms |
203296 KB |
Output is correct |
47 |
Correct |
1267 ms |
190380 KB |
Output is correct |
48 |
Correct |
804 ms |
208572 KB |
Output is correct |
49 |
Correct |
762 ms |
205328 KB |
Output is correct |
50 |
Correct |
1115 ms |
183952 KB |
Output is correct |
51 |
Correct |
27 ms |
63836 KB |
Output is correct |
52 |
Correct |
27 ms |
63836 KB |
Output is correct |
53 |
Correct |
27 ms |
63900 KB |
Output is correct |
54 |
Correct |
45 ms |
65616 KB |
Output is correct |
55 |
Correct |
37 ms |
64948 KB |
Output is correct |
56 |
Correct |
29 ms |
64860 KB |
Output is correct |
57 |
Correct |
216 ms |
101068 KB |
Output is correct |
58 |
Correct |
228 ms |
101060 KB |
Output is correct |
59 |
Correct |
244 ms |
101028 KB |
Output is correct |
60 |
Correct |
312 ms |
113716 KB |
Output is correct |
61 |
Correct |
335 ms |
114216 KB |
Output is correct |
62 |
Correct |
349 ms |
116316 KB |
Output is correct |
63 |
Correct |
173 ms |
66504 KB |
Output is correct |
64 |
Correct |
172 ms |
66608 KB |
Output is correct |
65 |
Correct |
176 ms |
66500 KB |
Output is correct |
66 |
Correct |
181 ms |
67000 KB |
Output is correct |
67 |
Correct |
230 ms |
107464 KB |
Output is correct |
68 |
Correct |
234 ms |
107104 KB |
Output is correct |
69 |
Correct |
241 ms |
107644 KB |
Output is correct |
70 |
Correct |
230 ms |
107712 KB |
Output is correct |
71 |
Correct |
242 ms |
106988 KB |
Output is correct |
72 |
Correct |
229 ms |
107756 KB |
Output is correct |
73 |
Correct |
233 ms |
106488 KB |
Output is correct |
74 |
Correct |
230 ms |
107444 KB |
Output is correct |
75 |
Correct |
834 ms |
181944 KB |
Output is correct |
76 |
Correct |
818 ms |
183568 KB |
Output is correct |
77 |
Correct |
706 ms |
182168 KB |
Output is correct |
78 |
Correct |
743 ms |
183376 KB |
Output is correct |
79 |
Correct |
901 ms |
183492 KB |
Output is correct |
80 |
Correct |
771 ms |
182804 KB |
Output is correct |
81 |
Correct |
1516 ms |
244532 KB |
Output is correct |
82 |
Correct |
1319 ms |
233816 KB |
Output is correct |
83 |
Correct |
1355 ms |
233876 KB |
Output is correct |
84 |
Correct |
1822 ms |
259460 KB |
Output is correct |
85 |
Correct |
1443 ms |
239996 KB |
Output is correct |
86 |
Correct |
1246 ms |
232376 KB |
Output is correct |
87 |
Execution timed out |
3028 ms |
299816 KB |
Time limit exceeded |
88 |
Halted |
0 ms |
0 KB |
- |