#include<bits/stdc++.h>
#define maxn 400000
using namespace std;
int n;
int el[maxn];
int x[maxn];
int y[maxn];
int rev[maxn];
int radius[maxn];
pair<pair<int,int>,pair<int,int> > circ[maxn];
vector<pair<pair<int,int>,int> > v;
set<pair<int,int> > s;
inline bool intersect(int i,int j) {
return 1ll*(x[i]-x[j])*(x[i]-x[j])+1ll*(y[i]-y[j])*(y[i]-y[j])<=1ll*(radius[i]+radius[j])*(radius[i]+radius[j]);
}
void dc(int l,int r) {
if(l==r) return;
int m=(l+r)/2;
dc(l,m);
//cout<<l<<" "<<m<<" "<<r<<endl;
for(int i=l;i<=r;i++) {
int ind=circ[i].first.second;
if(el[ind]==ind) {
//cout<<ind<<endl;
if(i<=m) {
v.push_back({{x[ind]-radius[ind],0},ind});
v.push_back({{x[ind]+radius[ind],2},ind});
}
else {
v.push_back({{x[ind]-radius[ind],1},ind});
v.push_back({{x[ind]+radius[ind],1},ind});
}
}
}
sort(v.begin(),v.end());
for(auto p:v) {
int xc=p.first.first;
int ind=p.second;
int pos=rev[ind];
if(pos<=m) {
//cout<<ind<<" "<<pos<<endl;
if(xc == x[ind]-radius[ind]) s.insert({y[ind],ind});
else s.erase({y[ind],ind});
}
else {
if(s.empty()) continue;
set<pair<int,int> >::iterator it=s.lower_bound({y[ind],-1});
set<pair<int,int> >::iterator st=it;
int co=0;
int i=0;
//cout<<ind<<" "<<pos<<endl;
while(it!=s.end() && i<=co) {
int jnd=(*it).second;
if(rev[jnd]<rev[el[ind]] && intersect(ind,jnd)) {
el[ind]=jnd;
}
it++;
i++;
}
it=st;
if(it==s.begin()) continue;
i=0;
do {
it--;
int jnd=(*it).second;
if(rev[jnd]<rev[el[ind]] && intersect(ind,jnd)) {
el[ind]=jnd;
}
i++;
} while(it!=s.begin() && i<=co);
}
}
s.clear();
v.clear();
dc(m+1,r);
}
int main() {
scanf("%d",&n);
for(int i=1;i<=n;i++) {
scanf("%d %d %d",&x[i],&y[i],&radius[i]);
circ[i]={{-radius[i],i},{x[i],y[i]}};
el[i]=i;
}
sort(circ+1,circ+n+1);
for(int i=1;i<=n;i++) {
rev[circ[i].first.second]=i;
//cout<<circ[i].first.second<<" ";
}
//cout<<endl;
dc(1,n);
for(int i=1;i<=n;i++) {
printf("%d ",el[i]);
}
printf("\n");
return 0;
}
Compilation message
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:78:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
78 | scanf("%d",&n);
| ~~~~~^~~~~~~~~
circle_selection.cpp:80:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
80 | scanf("%d %d %d",&x[i],&y[i],&radius[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
304 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
320 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
4 ms |
724 KB |
Output is correct |
20 |
Correct |
4 ms |
832 KB |
Output is correct |
21 |
Correct |
4 ms |
784 KB |
Output is correct |
22 |
Correct |
10 ms |
916 KB |
Output is correct |
23 |
Correct |
13 ms |
920 KB |
Output is correct |
24 |
Correct |
11 ms |
896 KB |
Output is correct |
25 |
Correct |
11 ms |
916 KB |
Output is correct |
26 |
Correct |
10 ms |
916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
246 ms |
17400 KB |
Output is correct |
2 |
Correct |
219 ms |
17340 KB |
Output is correct |
3 |
Correct |
218 ms |
17440 KB |
Output is correct |
4 |
Correct |
218 ms |
17320 KB |
Output is correct |
5 |
Correct |
213 ms |
17324 KB |
Output is correct |
6 |
Correct |
439 ms |
18464 KB |
Output is correct |
7 |
Correct |
297 ms |
17592 KB |
Output is correct |
8 |
Correct |
322 ms |
17604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
335 ms |
7544 KB |
Output is correct |
3 |
Correct |
1151 ms |
23756 KB |
Output is correct |
4 |
Correct |
1064 ms |
23900 KB |
Output is correct |
5 |
Correct |
845 ms |
19340 KB |
Output is correct |
6 |
Correct |
330 ms |
12324 KB |
Output is correct |
7 |
Correct |
154 ms |
6604 KB |
Output is correct |
8 |
Correct |
27 ms |
1736 KB |
Output is correct |
9 |
Correct |
1008 ms |
23796 KB |
Output is correct |
10 |
Correct |
744 ms |
19616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
945 ms |
23764 KB |
Output is correct |
2 |
Correct |
868 ms |
23840 KB |
Output is correct |
3 |
Incorrect |
360 ms |
17652 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
304 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
320 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
4 ms |
724 KB |
Output is correct |
20 |
Correct |
4 ms |
832 KB |
Output is correct |
21 |
Correct |
4 ms |
784 KB |
Output is correct |
22 |
Correct |
10 ms |
916 KB |
Output is correct |
23 |
Correct |
13 ms |
920 KB |
Output is correct |
24 |
Correct |
11 ms |
896 KB |
Output is correct |
25 |
Correct |
11 ms |
916 KB |
Output is correct |
26 |
Correct |
10 ms |
916 KB |
Output is correct |
27 |
Correct |
8 ms |
1236 KB |
Output is correct |
28 |
Correct |
8 ms |
1236 KB |
Output is correct |
29 |
Correct |
8 ms |
1236 KB |
Output is correct |
30 |
Correct |
24 ms |
1460 KB |
Output is correct |
31 |
Correct |
21 ms |
1448 KB |
Output is correct |
32 |
Correct |
22 ms |
1420 KB |
Output is correct |
33 |
Correct |
71 ms |
6464 KB |
Output is correct |
34 |
Correct |
73 ms |
6184 KB |
Output is correct |
35 |
Correct |
72 ms |
6200 KB |
Output is correct |
36 |
Correct |
280 ms |
7484 KB |
Output is correct |
37 |
Correct |
276 ms |
7204 KB |
Output is correct |
38 |
Correct |
290 ms |
7232 KB |
Output is correct |
39 |
Incorrect |
188 ms |
7204 KB |
Output isn't correct |
40 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
304 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
320 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
4 ms |
724 KB |
Output is correct |
20 |
Correct |
4 ms |
832 KB |
Output is correct |
21 |
Correct |
4 ms |
784 KB |
Output is correct |
22 |
Correct |
10 ms |
916 KB |
Output is correct |
23 |
Correct |
13 ms |
920 KB |
Output is correct |
24 |
Correct |
11 ms |
896 KB |
Output is correct |
25 |
Correct |
11 ms |
916 KB |
Output is correct |
26 |
Correct |
10 ms |
916 KB |
Output is correct |
27 |
Correct |
246 ms |
17400 KB |
Output is correct |
28 |
Correct |
219 ms |
17340 KB |
Output is correct |
29 |
Correct |
218 ms |
17440 KB |
Output is correct |
30 |
Correct |
218 ms |
17320 KB |
Output is correct |
31 |
Correct |
213 ms |
17324 KB |
Output is correct |
32 |
Correct |
439 ms |
18464 KB |
Output is correct |
33 |
Correct |
297 ms |
17592 KB |
Output is correct |
34 |
Correct |
322 ms |
17604 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
335 ms |
7544 KB |
Output is correct |
37 |
Correct |
1151 ms |
23756 KB |
Output is correct |
38 |
Correct |
1064 ms |
23900 KB |
Output is correct |
39 |
Correct |
845 ms |
19340 KB |
Output is correct |
40 |
Correct |
330 ms |
12324 KB |
Output is correct |
41 |
Correct |
154 ms |
6604 KB |
Output is correct |
42 |
Correct |
27 ms |
1736 KB |
Output is correct |
43 |
Correct |
1008 ms |
23796 KB |
Output is correct |
44 |
Correct |
744 ms |
19616 KB |
Output is correct |
45 |
Correct |
945 ms |
23764 KB |
Output is correct |
46 |
Correct |
868 ms |
23840 KB |
Output is correct |
47 |
Incorrect |
360 ms |
17652 KB |
Output isn't correct |
48 |
Halted |
0 ms |
0 KB |
- |