Submission #971559

#TimeUsernameProblemLanguageResultExecution timeMemory
971559irmuunCircle selection (APIO18_circle_selection)C++17
19 / 100
790 ms269900 KiB
#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>>L,R; for(ll i=1;i<=n;i++){ L.insert({x[i]-r[i],i}); R.insert({x[i]+r[i],i}); } vector<ll>del; for(auto [ra,i]:v){ if(ans[i]>0) continue; del.clear(); auto it=L.lower_bound({x[i]-r[i],0}); while(it!=L.end()&&it->ff<=x[i]+r[i]){ del.pb(it->ss); it++; } auto it1=R.lower_bound({x[i]-r[i],0}); while(it1!=R.end()&&it1->ff<=x[i]+r[i]){ del.pb(it1->ss); it1++; } for(auto j:del){ if(ans[j]==0){ ans[j]=i; L.erase({x[j]-r[j],j}); R.erase({x[j]+r[j],j}); } } } for(ll i=1;i<=n;i++){ cout<<ans[i]<<' '; } cout<<"\n"; return 0; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...