# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
835554 | jamielim | Circle selection (APIO18_circle_selection) | C++14 | 3085 ms | 584268 KiB |
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 fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ii,ii> i4;
typedef vector<int> vi;
const int MOD=1000000007;
const int INF=1012345678;
const ll LLINF=1012345678012345678LL;
const double PI=3.1415926536;
const double EPS=1e-14;
int n;
i4 arr[300005];
int ans[300005];
set<i4> pq;
int scale=(1<<30);
map<ll,vector<int> > m;
inline void downscale(){
m.clear();
for(i4 i:pq){
ll cur=(ll)(i.se.fi/scale)*(ll)(INF)+(ll)(i.se.se/scale);
m[cur].pb(-i.fi.se);
}
}
inline bool intersect(int a,int b){
ll dx=arr[a].se.fi-arr[b].se.fi;
ll dy=arr[a].se.se-arr[b].se.se;
ll r=arr[a].fi.fi+arr[b].fi.fi;
return (dx*dx<=r*r-dy*dy);
}
int main(){
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d%d%d",&arr[i].se.fi,&arr[i].se.se,&arr[i].fi.fi);
arr[i].se.fi+=1000000000;arr[i].se.se+=1000000000;
arr[i].fi.se=-i;
pq.insert(arr[i]);
}
memset(ans,-1,sizeof(ans));
while(!pq.empty()){
auto it=pq.end();--it;
i4 cur=(*it);pq.erase(it);
int index=-cur.fi.se;
if(ans[index]!=-1)continue;
ans[index]=index;
bool change=0;
while(scale>cur.fi.fi){
scale/=2;
change=1;
}
if(change)downscale();
int x=cur.se.fi/scale,y=cur.se.se/scale;
for(int i=x-2;i<=x+2;i++){
for(int j=y-2;j<=y+2;j++){
ll grid=(ll)(i)*(ll)(INF)+j;
vector<int> v1=m[grid];
vector<int> v2;
for(int k:v1){
if(intersect(k,index)){
i4 link=arr[k];
pq.erase(link);
ans[k]=index;
}else{
v2.pb(k);
}
}
swap(m[grid],v2);
}
}
}
for(int i=0;i<n;i++)printf("%d ",ans[i]+1);
}
Compilation message (stderr)
# | 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... |