#include <iostream>
#include <fstream>
#include <algorithm>
#include <set>
using namespace std;
const int nmax=100005;
pair<int,int> v[nmax];
set< pair<int,int> > s;
set< pair<int,int> >::iterator it1,it2;
long long x[nmax],y[nmax],r[nmax];
int tt[nmax];
int n,i,j,ind;
bool ok(int A,int B)
{
return (1LL*(x[A]-x[B])*(x[A]-x[B])+1LL*(y[A]-y[B])*(y[A]-y[B])<=1LL*(r[A]+r[B])*(r[A]+r[B]));
}
bool comp(pair<int,int> unu,pair<int,int> doi)
{
if(unu.first==doi.first) return unu.second<doi.second;
return unu.first>doi.first;
}
int main()
{
freopen("data.in","r",stdin);
cin>>n;
bool zr=1;
for(i=1;i<=n;i++)
{
cin>>x[i]>>y[i]>>r[i];
v[i].first=r[i];
v[i].second=i;
if(y[i]!=0)
{
zr=0;
}
}
if(n<=5000)
{
sort(v+1,v+n+1,comp);
for(i=1;i<=n;i++)
if(!tt[v[i].second])
{
tt[v[i].second]=v[i].second;
for(j=i+1;j<=n;j++)
{
if(ok(v[i].second,v[j].second)&&(!tt[v[j].second]))
tt[v[j].second]=v[i].second;
}
}
for(i=1;i<=n;i++)
cout<<tt[i]<<' ';
return 0;
}
if(zr)
{
int cap1,cap2;
sort(v+1,v+n+1,comp);
for(i=1;i<=n;i++)
{
cap1=x[i]-r[i];cap2=x[i]+r[i];
s.insert({cap1,i});
s.insert({cap2,i});
}
bool ok;
for(i=1;i<=n;i++)
if(!tt[v[i].second])
{
ind=v[i].second;tt[ind]=ind;
cap1=x[ind]-r[ind];
it1=s.lower_bound({cap1,0});ok=1;
while((!s.empty())&&ok&&it1!=s.end())
{
it2=it1;it2++;
if((*it1).first<=x[ind]+r[ind]&&(!tt[(*it1).second]))
{
tt[(*it1).second]=ind;
}
s.erase(it1);
if(it2==s.end()||((*it2).first>x[ind]+r[ind]))
ok=0;
it1=it2;
}
}
for(i=1;i<=n;i++)
cout<<tt[i]<<' ';
return 0;
}
return 0;
}
Compilation message
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:24:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen("data.in","r",stdin);
~~~~~~~^~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |