이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=3e5+100;
const int SQ=222;//  333 444
vector<int> adj[N];
ll who[N];
void solve()
{
	ll n;
	cin>>n;
	vector<ll> x(n),y(n),r(n);
	set<ll> tpy;
	for(int i=0;i<n;i++)
	{
		cin>>x[i]>>y[i]>>r[i];
		tpy.insert(y[i]);
	}
	if(tpy.size()==1)
	{
		set<pair<int,int>> only_l,only_r;
		set<pair<int,int>> rem;
		for(int i=0;i<n;i++)
		{
			only_l.insert({x[i]-r[i],i});
			only_r.insert({x[i]+r[i],i});
			rem.insert({-r[i],i});
		}
		while(rem.size())
		{
			auto p=*begin(rem);
			rem.erase(begin(rem));
			if(who[p.second]!=0)
				continue;
			int mi=x[p.second]-r[p.second];
			int mx=x[p.second]+r[p.second];
			// cout<<"Hello "<<p.second<<' '<<p.first<<endl;
			// We find all element which have there l between mi and mx inclusive
			while(only_l.size())
			{
				auto it=only_l.lower_bound({mi,-1});
				if(end(only_l)!=it)
				{
					auto tpl=*it;
					if(tpl.first<=mx)
					{
						if(who[tpl.second]==0)
						{
							// cout<<"Removed_L "<<tpl.first<<' '<<tpl.second<<endl;
							who[tpl.second]=p.second+1;
						}
						only_l.erase(it);
					}
					else
					{
						break;
					}
				}
				else
				{
					break;
				}
			}
			while(only_r.size())
			{
				auto it=only_r.lower_bound({mx+1,-1});
				if(begin(only_r)!=it)
				{
					it--;
					auto tpl=*it;
					if(mi<=tpl.first)
					{
						if(who[tpl.second]==0)
						{
							// cout<<"Removed_R "<<tpl.first<<' '<<tpl.second<<endl;
							who[tpl.second]=p.second+1;
						}
						only_r.erase(it);
					}
					else
					{
						break;
					}
				}
				else
				{
					break;
				}
			}
			// cout<<"Khatam\n";
		}
		for(int i=0;i<n;i++)
		{
			cout<<who[i]<<' ';
		}
		cout<<'\n';
	}
	else if((n<=5000))
	{
		for(int i=0;i<n;i++)
			{
				for(int j=0;j<=i;j++)
				{
					// ( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) ) <= (r1+r2)²
					ll dist=(r[i]+r[j])*(r[i]+r[j]);
					ll dp=( (x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]) );
					if(dp<=dist)
					{
						adj[i].push_back(j);
						adj[j].push_back(i);
					}
				}
			}
			set<pair<int,int>> rem;
			for(int i=0;i<n;i++)
				rem.insert({-r[i],i});
			while(rem.size())
			{
				auto p=*begin(rem);
				rem.erase(begin(rem));
				if(who[p.second]!=0)
					continue;
				for(auto op:adj[p.second])
					if(who[op]==0)
						who[op]=p.second+1;
			}
			for(int i=0;i<n;i++)
			{
				cout<<who[i]<<' ';
			}
			cout<<'\n';
	}
	else
	{
		vector<pair<ll,ll>> tp(n);
		for(int i=0;i<n;i++)
		{
			tp[i].first=x[i];
			tp[i].second=i;
		}
		sort(begin(tp),end(tp));
		for(int jp=0;jp<n;jp++)
		{
			for(int l=-SQ;l<=SQ;l++)
			{
				if((jp+l)>=0 and (jp+l)<n)
				{
					int i=tp[jp].second;
					int j=tp[jp+l].second;
					ll dist=(r[i]+r[j])*(r[i]+r[j]);
					ll dp=( (x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]) );
					if(dp<=dist)
					{
						adj[i].push_back(j);
						adj[j].push_back(i);
					}
				}
			}
		}
		for(int i=0;i<n;i++)
		{
			tp[i].first=y[i];
			tp[i].second=i;
		}
		sort(begin(tp),end(tp));
		for(int jp=0;jp<n;jp++)
		{
			for(int l=-SQ;l<=SQ;l++)
			{
				if((jp+l)>=0 and (jp+l)<n)
				{
					int i=tp[jp].second;
					int j=tp[jp+l].second;
					ll dist=(r[i]+r[j])*(r[i]+r[j]);
					ll dp=( (x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]) );
					if(dp<=dist)
					{
						adj[i].push_back(j);
						adj[j].push_back(i);
					}
				}
			}
		}
		set<pair<int,int>> rem;
		for(int i=0;i<n;i++)
			rem.insert({-r[i],i});
		while(rem.size())
		{
			auto p=*begin(rem);
			rem.erase(begin(rem));
			if(who[p.second]!=0)
				continue;
			for(auto op:adj[p.second])
				if(who[op]==0)
					who[op]=p.second+1;
		}
		for(int i=0;i<n;i++)
		{
			cout<<who[i]<<' ';
		}
		cout<<'\n';
	}
}
int main()
{
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(0);
	solve();
}
| # | 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... |