#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, 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);
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:110:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
110 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
circle_selection.cpp:114:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
114 | scanf("%d %d %d", &C[i].x, &C[i].y, &C[i].r);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
57944 KB |
Output is correct |
2 |
Correct |
12 ms |
57948 KB |
Output is correct |
3 |
Correct |
13 ms |
58000 KB |
Output is correct |
4 |
Correct |
12 ms |
58068 KB |
Output is correct |
5 |
Correct |
13 ms |
58204 KB |
Output is correct |
6 |
Correct |
13 ms |
57944 KB |
Output is correct |
7 |
Correct |
12 ms |
58328 KB |
Output is correct |
8 |
Correct |
12 ms |
57948 KB |
Output is correct |
9 |
Correct |
12 ms |
58084 KB |
Output is correct |
10 |
Correct |
12 ms |
57944 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 |
12 ms |
57948 KB |
Output is correct |
15 |
Correct |
12 ms |
58012 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 |
57948 KB |
Output is correct |
19 |
Correct |
17 ms |
60252 KB |
Output is correct |
20 |
Correct |
17 ms |
60252 KB |
Output is correct |
21 |
Correct |
17 ms |
60252 KB |
Output is correct |
22 |
Correct |
20 ms |
60764 KB |
Output is correct |
23 |
Correct |
23 ms |
61532 KB |
Output is correct |
24 |
Correct |
18 ms |
60764 KB |
Output is correct |
25 |
Correct |
17 ms |
60508 KB |
Output is correct |
26 |
Correct |
18 ms |
60508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
449 ms |
76304 KB |
Output is correct |
2 |
Correct |
472 ms |
77372 KB |
Output is correct |
3 |
Correct |
452 ms |
75952 KB |
Output is correct |
4 |
Correct |
450 ms |
76472 KB |
Output is correct |
5 |
Correct |
430 ms |
76596 KB |
Output is correct |
6 |
Correct |
502 ms |
84916 KB |
Output is correct |
7 |
Correct |
487 ms |
77872 KB |
Output is correct |
8 |
Correct |
485 ms |
80044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
57944 KB |
Output is correct |
2 |
Correct |
348 ms |
88404 KB |
Output is correct |
3 |
Correct |
1212 ms |
142660 KB |
Output is correct |
4 |
Correct |
1129 ms |
143068 KB |
Output is correct |
5 |
Correct |
1397 ms |
141548 KB |
Output is correct |
6 |
Correct |
555 ms |
91328 KB |
Output is correct |
7 |
Correct |
188 ms |
72972 KB |
Output is correct |
8 |
Correct |
32 ms |
61656 KB |
Output is correct |
9 |
Correct |
1255 ms |
146104 KB |
Output is correct |
10 |
Correct |
1630 ms |
136132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
968 ms |
134276 KB |
Output is correct |
2 |
Correct |
420 ms |
97720 KB |
Output is correct |
3 |
Correct |
877 ms |
85292 KB |
Output is correct |
4 |
Correct |
484 ms |
102984 KB |
Output is correct |
5 |
Correct |
451 ms |
99888 KB |
Output is correct |
6 |
Correct |
783 ms |
79216 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 |
13 ms |
58000 KB |
Output is correct |
4 |
Correct |
12 ms |
58068 KB |
Output is correct |
5 |
Correct |
13 ms |
58204 KB |
Output is correct |
6 |
Correct |
13 ms |
57944 KB |
Output is correct |
7 |
Correct |
12 ms |
58328 KB |
Output is correct |
8 |
Correct |
12 ms |
57948 KB |
Output is correct |
9 |
Correct |
12 ms |
58084 KB |
Output is correct |
10 |
Correct |
12 ms |
57944 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 |
12 ms |
57948 KB |
Output is correct |
15 |
Correct |
12 ms |
58012 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 |
57948 KB |
Output is correct |
19 |
Correct |
17 ms |
60252 KB |
Output is correct |
20 |
Correct |
17 ms |
60252 KB |
Output is correct |
21 |
Correct |
17 ms |
60252 KB |
Output is correct |
22 |
Correct |
20 ms |
60764 KB |
Output is correct |
23 |
Correct |
23 ms |
61532 KB |
Output is correct |
24 |
Correct |
18 ms |
60764 KB |
Output is correct |
25 |
Correct |
17 ms |
60508 KB |
Output is correct |
26 |
Correct |
18 ms |
60508 KB |
Output is correct |
27 |
Correct |
24 ms |
60508 KB |
Output is correct |
28 |
Correct |
25 ms |
60584 KB |
Output is correct |
29 |
Correct |
24 ms |
60540 KB |
Output is correct |
30 |
Correct |
29 ms |
62288 KB |
Output is correct |
31 |
Correct |
24 ms |
61432 KB |
Output is correct |
32 |
Correct |
24 ms |
61444 KB |
Output is correct |
33 |
Correct |
128 ms |
66684 KB |
Output is correct |
34 |
Correct |
152 ms |
66672 KB |
Output is correct |
35 |
Correct |
140 ms |
66500 KB |
Output is correct |
36 |
Correct |
220 ms |
78588 KB |
Output is correct |
37 |
Correct |
240 ms |
79276 KB |
Output is correct |
38 |
Correct |
238 ms |
81368 KB |
Output is correct |
39 |
Correct |
180 ms |
67516 KB |
Output is correct |
40 |
Correct |
176 ms |
67488 KB |
Output is correct |
41 |
Correct |
187 ms |
67404 KB |
Output is correct |
42 |
Correct |
183 ms |
68284 KB |
Output is correct |
43 |
Correct |
135 ms |
72900 KB |
Output is correct |
44 |
Correct |
142 ms |
72352 KB |
Output is correct |
45 |
Correct |
136 ms |
72848 KB |
Output is correct |
46 |
Correct |
140 ms |
72596 KB |
Output is correct |
47 |
Correct |
142 ms |
71832 KB |
Output is correct |
48 |
Correct |
133 ms |
72900 KB |
Output is correct |
49 |
Correct |
142 ms |
71584 KB |
Output is correct |
50 |
Correct |
148 ms |
72460 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 |
13 ms |
58000 KB |
Output is correct |
4 |
Correct |
12 ms |
58068 KB |
Output is correct |
5 |
Correct |
13 ms |
58204 KB |
Output is correct |
6 |
Correct |
13 ms |
57944 KB |
Output is correct |
7 |
Correct |
12 ms |
58328 KB |
Output is correct |
8 |
Correct |
12 ms |
57948 KB |
Output is correct |
9 |
Correct |
12 ms |
58084 KB |
Output is correct |
10 |
Correct |
12 ms |
57944 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 |
12 ms |
57948 KB |
Output is correct |
15 |
Correct |
12 ms |
58012 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 |
57948 KB |
Output is correct |
19 |
Correct |
17 ms |
60252 KB |
Output is correct |
20 |
Correct |
17 ms |
60252 KB |
Output is correct |
21 |
Correct |
17 ms |
60252 KB |
Output is correct |
22 |
Correct |
20 ms |
60764 KB |
Output is correct |
23 |
Correct |
23 ms |
61532 KB |
Output is correct |
24 |
Correct |
18 ms |
60764 KB |
Output is correct |
25 |
Correct |
17 ms |
60508 KB |
Output is correct |
26 |
Correct |
18 ms |
60508 KB |
Output is correct |
27 |
Correct |
449 ms |
76304 KB |
Output is correct |
28 |
Correct |
472 ms |
77372 KB |
Output is correct |
29 |
Correct |
452 ms |
75952 KB |
Output is correct |
30 |
Correct |
450 ms |
76472 KB |
Output is correct |
31 |
Correct |
430 ms |
76596 KB |
Output is correct |
32 |
Correct |
502 ms |
84916 KB |
Output is correct |
33 |
Correct |
487 ms |
77872 KB |
Output is correct |
34 |
Correct |
485 ms |
80044 KB |
Output is correct |
35 |
Correct |
12 ms |
57944 KB |
Output is correct |
36 |
Correct |
348 ms |
88404 KB |
Output is correct |
37 |
Correct |
1212 ms |
142660 KB |
Output is correct |
38 |
Correct |
1129 ms |
143068 KB |
Output is correct |
39 |
Correct |
1397 ms |
141548 KB |
Output is correct |
40 |
Correct |
555 ms |
91328 KB |
Output is correct |
41 |
Correct |
188 ms |
72972 KB |
Output is correct |
42 |
Correct |
32 ms |
61656 KB |
Output is correct |
43 |
Correct |
1255 ms |
146104 KB |
Output is correct |
44 |
Correct |
1630 ms |
136132 KB |
Output is correct |
45 |
Correct |
968 ms |
134276 KB |
Output is correct |
46 |
Correct |
420 ms |
97720 KB |
Output is correct |
47 |
Correct |
877 ms |
85292 KB |
Output is correct |
48 |
Correct |
484 ms |
102984 KB |
Output is correct |
49 |
Correct |
451 ms |
99888 KB |
Output is correct |
50 |
Correct |
783 ms |
79216 KB |
Output is correct |
51 |
Correct |
24 ms |
60508 KB |
Output is correct |
52 |
Correct |
25 ms |
60584 KB |
Output is correct |
53 |
Correct |
24 ms |
60540 KB |
Output is correct |
54 |
Correct |
29 ms |
62288 KB |
Output is correct |
55 |
Correct |
24 ms |
61432 KB |
Output is correct |
56 |
Correct |
24 ms |
61444 KB |
Output is correct |
57 |
Correct |
128 ms |
66684 KB |
Output is correct |
58 |
Correct |
152 ms |
66672 KB |
Output is correct |
59 |
Correct |
140 ms |
66500 KB |
Output is correct |
60 |
Correct |
220 ms |
78588 KB |
Output is correct |
61 |
Correct |
240 ms |
79276 KB |
Output is correct |
62 |
Correct |
238 ms |
81368 KB |
Output is correct |
63 |
Correct |
180 ms |
67516 KB |
Output is correct |
64 |
Correct |
176 ms |
67488 KB |
Output is correct |
65 |
Correct |
187 ms |
67404 KB |
Output is correct |
66 |
Correct |
183 ms |
68284 KB |
Output is correct |
67 |
Correct |
135 ms |
72900 KB |
Output is correct |
68 |
Correct |
142 ms |
72352 KB |
Output is correct |
69 |
Correct |
136 ms |
72848 KB |
Output is correct |
70 |
Correct |
140 ms |
72596 KB |
Output is correct |
71 |
Correct |
142 ms |
71832 KB |
Output is correct |
72 |
Correct |
133 ms |
72900 KB |
Output is correct |
73 |
Correct |
142 ms |
71584 KB |
Output is correct |
74 |
Correct |
148 ms |
72460 KB |
Output is correct |
75 |
Correct |
465 ms |
78056 KB |
Output is correct |
76 |
Correct |
454 ms |
78268 KB |
Output is correct |
77 |
Correct |
405 ms |
79640 KB |
Output is correct |
78 |
Correct |
431 ms |
77996 KB |
Output is correct |
79 |
Correct |
608 ms |
77788 KB |
Output is correct |
80 |
Correct |
495 ms |
79040 KB |
Output is correct |
81 |
Correct |
1048 ms |
139144 KB |
Output is correct |
82 |
Correct |
899 ms |
129244 KB |
Output is correct |
83 |
Correct |
917 ms |
128952 KB |
Output is correct |
84 |
Correct |
1319 ms |
154536 KB |
Output is correct |
85 |
Correct |
997 ms |
135192 KB |
Output is correct |
86 |
Correct |
894 ms |
126800 KB |
Output is correct |
87 |
Correct |
2678 ms |
196960 KB |
Output is correct |
88 |
Correct |
647 ms |
81772 KB |
Output is correct |
89 |
Correct |
672 ms |
82192 KB |
Output is correct |
90 |
Correct |
597 ms |
82884 KB |
Output is correct |
91 |
Correct |
597 ms |
82148 KB |
Output is correct |
92 |
Correct |
620 ms |
81704 KB |
Output is correct |
93 |
Correct |
444 ms |
97208 KB |
Output is correct |
94 |
Execution timed out |
3034 ms |
154452 KB |
Time limit exceeded |
95 |
Halted |
0 ms |
0 KB |
- |