#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=1000;
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.end()) it--;
i=0;
co++;
do {
int jnd=(*it).second;
if(rev[jnd]<rev[el[ind]] && intersect(ind,jnd)) {
el[ind]=jnd;
}
i++;
it--;
} 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:79:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
79 | scanf("%d",&n);
| ~~~~~^~~~~~~~~
circle_selection.cpp:81:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
81 | scanf("%d %d %d",&x[i],&y[i],&radius[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
222 ms |
17276 KB |
Output is correct |
2 |
Correct |
221 ms |
17160 KB |
Output is correct |
3 |
Correct |
228 ms |
17240 KB |
Output is correct |
4 |
Correct |
218 ms |
17088 KB |
Output is correct |
5 |
Correct |
219 ms |
17188 KB |
Output is correct |
6 |
Correct |
419 ms |
17916 KB |
Output is correct |
7 |
Correct |
237 ms |
17304 KB |
Output is correct |
8 |
Correct |
270 ms |
17160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
953 ms |
23244 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |