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 int long long
bool inte(vector<int> c,vector<int> c1)
{
int dis=(c[2]-c1[2])*(c[2]-c1[2])+(c[3]-c1[3])*(c[3]-c1[3]);
return dis <= (c[0]+c1[0])*(c[0]+c1[0]);
}
signed main()
{
int n;
cin>>n;
int r[n],x[n],y[n],ans[n]={};
for (int i=0;i<n;i++)
cin>>x[i]>>y[i]>>r[i];
if (n<=5000)
{
set<vector<int>> se;
set<int> rem;
for (int i=0;i<n;i++)
{
se.insert({-r[i],i,x[i],y[i]});
rem.insert(i);
}
while (!se.empty())
{
auto it=se.begin();
vector<int> c=*it;c[0]*=-1;
for (int i:rem)
if (!ans[i] && inte(c,{r[i],i,x[i],y[i]}))
{
se.erase({-r[i],i,x[i],y[i]});
ans[i]=c[1]+1;
}
}
}
else
{
int mx=-1e9,mn=-mx;
for (int i=0;i<n;i++)
mn=min(mn,y[i]),mx=max(mx,y[i]);
if (!mn && !mx)
{
set<pair<int,int>> st,en,rem;
for (int i=0;i<n;i++)
st.insert({x[i]-r[i],i}),en.insert({x[i]+r[i],i}),rem.insert({-r[i],i});
while (!rem.empty())
{
set<int> toer;
auto p=*rem.begin();
auto it=st.lower_bound({x[p.second]-r[p.second],0});
auto it1=st.lower_bound({1+x[p.second]+r[p.second],0});
while (it!=it1)
{
toer.insert((*it).second);
it++;
}
it=en.lower_bound({x[p.second]-r[p.second],0});
it1=en.lower_bound({x[p.second]+r[p.second]+1,0});
while (it!=it1)
{
toer.insert((*it).second);
it++;
}
for (int i:toer)
{
ans[i]=p.second+1;
st.erase({x[i]-r[i],i}),en.erase({x[i]+r[i],i}),rem.erase({-r[i],i});
}
}
}
else
{
vector<vector<int>> vec;
for (int i=0;i<n;i++)
vec.push_back({y[i]+r[i],i,1}),vec.push_back({y[i]-r[i],i,0});
sort(vec.begin(),vec.end());
set<pair<int,int>> ms;
while (!vec.empty())
{
vector<int> v=vec.back();
vec.pop_back();
if (v[2])
{
auto it=ms.insert({x[v[1]],v[1]}).first;
if (it!=ms.begin())
{
it--;
int id=(*it).second;
if (inte({r[v[1]],0,x[v[1]],y[v[1]]},{r[id],0,x[id],y[id]}))
{
if (r[v[1]]>r[id] || (r[v[1]]==r[id] && v[1]<id))
ans[v[1]]=ans[id]=v[1]+1;
else
ans[v[1]]=ans[id]=id+1;
}
it++;
}
it++;
if (it!=ms.end())
{
int id=(*it).second;
if (inte({r[v[1]],0,x[v[1]],y[v[1]]},{r[id],0,x[id],y[id]}))
{
if (r[v[1]]>r[id] || (r[v[1]]==r[id] && v[1]<id))
ans[v[1]]=ans[id]=v[1]+1;
else
ans[v[1]]=ans[id]=id+1;
}
}
}
else
{
auto it=ms.find({x[v[1]],v[1]});
if (it!=ms.begin())
{
it--;
int id=(*it).second;
it++,it++;
if (it!=ms.end())
{
int id1=(*it).second;
if (inte({r[id],0,x[id],y[id]},{r[id1],0,x[id1],y[id1]}))
{
if (r[id]>r[id1] || (r[id]==r[id1] && id<id1))
ans[id]=ans[id1]=id+1;
else
ans[id]=ans[id1]=id1+1;
}
}
}
ms.erase({x[v[1]],v[1]});
}
}
}
}
for (int i=0;i<n;i++)
cout<<ans[i]<<' ';
cout<<endl;
return 0;
}
# | 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... |