This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fr first
#define sc second
struct Circle{
int x,y,r,id;
void read(int i){
cin>>x>>y>>r;
id=i;
}
}a[300005];
bool operator<(Circle a,Circle b){
return a.r>b.r||(a.r==b.r&&a.id<b.id);
}
typedef long long ll;
ll sq(ll x){return x*x;}
ll dist(int x,int y,int x2,int y2){return sq(x-x2)+sq(y-y2);}
bool intersect(Circle a,Circle b){
return dist(a.x,a.y,b.x,b.y)<=sq(a.r+b.r);
}
int n;
int ans[300005];
void subtask1(){
sort(a+1,a+1+n);
for(int i=1;i<=n;i++)
if(!ans[a[i].id])for(int j=1;j<=n;j++)if(!ans[a[j].id]&&intersect(a[i],a[j]))ans[a[j].id]=a[i].id;
for(int i=1;i<=n;i++)printf("%d ",ans[i]);
exit(0);
}
void subtask2(){
set<pair<int,int>>st;
for(int i=1;i<=n;i++){
st.emplace(a[i].x-a[i].r,i);
st.emplace(a[i].x+a[i].r,i);
}
sort(a+1,a+1+n);
for(int i=1;i<=n;i++){
if(ans[a[i].id])continue;
while(true){
auto it=st.lower_bound(make_pair(a[i].x-a[i].r,-2e9));
if(it==st.end())break;
if(it->first>a[i].x+a[i].r)break;
st.erase(*it);
if(ans[it->second])continue;
ans[it->second]=a[i].id;
}
}
for(int i=1;i<=n;i++)printf("%d ",ans[i]);
exit(0);
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n;
bool _subtask2=true;
for(int i=1;i<=n;i++){
a[i].read(i);
_subtask2&=(a[i].y==0);
}
if(n<=5000)subtask1();
else if(_subtask2)subtask2();
}
/*
11
9 9 2
13 2 1
11 8 2
3 3 2
3 12 1
12 14 1
9 8 5
2 8 2
5 2 1
14 4 2
14 14 1
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |