Submission #368177

#TimeUsernameProblemLanguageResultExecution timeMemory
368177YJUCircle selection (APIO18_circle_selection)C++14
12 / 100
493 ms36544 KiB
#include<bits/stdc++.h> #pragma GCC optimize("unroll-loops,no-stack-protector,Ofast") using namespace std; typedef long long ll; typedef long double ld; typedef pair<ll,ll> pll; const ll MOD=1e9+7; const ll MOD2=998244353; const ll N=3e5+5; const ld pi=acos(-1); const ll INF=(1LL<<60); #define SQ(i) ((i)*(i)) #define REP(i,n) for(ll i=0;i<n;i++) #define REP1(i,n) for(ll i=1;i<=n;i++) #define pb push_back #define mp make_pair #define X first #define Y second #define setp setprecision #define lwb lower_bound #define SZ(_a) (ll)_a.size() struct circle{ ll r,x,y,id; bool operator <(circle B){ return (r!=B.r?r>B.r:id<B.id); } }; bool inter(circle A,circle B){ return (SQ(A.r+B.r)>=SQ(A.x-B.x)+SQ(A.y-B.y)); } ll n,ans[N]; vector<circle> cir; int main(){ ios_base::sync_with_stdio(0);cin.tie(0); cin>>n; cir.resize(n); REP(i,n)cin>>cir[i].x>>cir[i].y>>cir[i].r,cir[i].id=i; sort(cir.begin(),cir.end()); ll R=cir[0].r+1; while(SZ(cir)){ vector<pair<pll,ll> > loc; REP(i,SZ(cir))loc.pb(mp(mp(cir[i].x/R,cir[i].y/R),i)); sort(loc.begin(),loc.end()); for(auto i:cir){ if(ans[i.id])continue; if(i.r<R/2)break; ans[i.id]=i.id; ll cx=i.x/R,cy=i.y/R; for(int x=cx-2;x<=cx+2;x++){ pair<pll,ll> pos=mp(mp(x,cy-2),-1); for(int j=lwb(loc.begin(),loc.end(),pos)-loc.begin();j<SZ(loc);j++){ if(loc[j].X.X!=x||loc[j].X.Y>cy+2)break; if(!ans[cir[loc[j].Y].id]&&inter(i,cir[loc[j].Y])){ ans[cir[loc[j].Y].id]=i.id; } } } } vector<circle> tmp=cir; cir.clear(); for(auto i:tmp){ if(!ans[i.id])cir.pb(i); } R>>=1; } REP(i,n)cout<<ans[i]+1<<(i==n-1?"\n":" "); return 0; } /* 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 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...