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 ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
const ll N=3e5+5;
ll n;
ll x[N],y[N],r[N];
vector<ll>adj[N],ans(N,0);
vector<bool>used(N,0);
ll dist(ll i,ll j){
return abs(x[i]-x[j])*abs(x[i]-x[j])+abs(y[i]-y[j])*abs(y[i]-y[j]);
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin>>n;
vector<pair<ll,ll>>v;
bool Y=true;
for(ll i=1;i<=n;i++){
cin>>x[i]>>y[i]>>r[i];
v.pb({-r[i],i});
Y&=(y[i]==0);
}
sort(all(v));
if(n<=5000){
for(ll i=1;i<=n;i++){
for(ll j=i+1;j<=n;j++){
if(dist(i,j)<=(r[i]+r[j])*(r[i]+r[j])){
adj[i].pb(j);
adj[j].pb(i);
}
}
}
for(auto [R,i]:v){
if(ans[i]>0) continue;
ans[i]=i;
for(ll j:adj[i]){
if(ans[j]==0) ans[j]=i;
}
}
for(ll i=1;i<=n;i++){
cout<<ans[i]<<' ';
}
return 0;
}
if(Y){
set<pair<ll,ll>>ord;
for(ll i=1;i<=n;i++){
ord.insert({x[i],i});
}
vector<ll>del;
for(auto [R,i]:v){
if(ans[i]>0) continue;
del.clear();
auto it=ord.lower_bound({x[i]-r[i],0});
while(it!=ord.end()&&it->ff<=x[i]+r[i]){
del.pb(it->ss);
it++;
}
for(auto j:del){
ans[j]=i;
ord.erase({r[j],j});
}
}
for(ll i=1;i<=n;i++){
cout<<ans[i]<<' ';
}
cout<<"\n";
}
}
# | 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... |