답안 #982265

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
982265 2024-05-14T05:06:11 Z Faisal_Saqib 원 고르기 (APIO18_circle_selection) C++17
34 / 100
1795 ms 145380 KB
#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();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 7516 KB Output is correct
2 Correct 2 ms 7516 KB Output is correct
3 Correct 2 ms 7516 KB Output is correct
4 Correct 2 ms 7516 KB Output is correct
5 Correct 2 ms 7516 KB Output is correct
6 Correct 2 ms 7516 KB Output is correct
7 Correct 2 ms 7516 KB Output is correct
8 Correct 2 ms 7516 KB Output is correct
9 Correct 2 ms 7516 KB Output is correct
10 Correct 2 ms 7516 KB Output is correct
11 Correct 2 ms 7516 KB Output is correct
12 Correct 2 ms 7516 KB Output is correct
13 Correct 3 ms 7772 KB Output is correct
14 Correct 2 ms 7516 KB Output is correct
15 Correct 2 ms 7516 KB Output is correct
16 Correct 8 ms 11436 KB Output is correct
17 Correct 8 ms 11356 KB Output is correct
18 Correct 7 ms 11868 KB Output is correct
19 Correct 204 ms 145380 KB Output is correct
20 Correct 217 ms 143924 KB Output is correct
21 Correct 166 ms 84832 KB Output is correct
22 Correct 28 ms 8284 KB Output is correct
23 Correct 27 ms 8284 KB Output is correct
24 Correct 28 ms 8388 KB Output is correct
25 Correct 36 ms 8384 KB Output is correct
26 Correct 30 ms 8284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 664 ms 61028 KB Output is correct
2 Correct 649 ms 61028 KB Output is correct
3 Correct 718 ms 60796 KB Output is correct
4 Correct 733 ms 61472 KB Output is correct
5 Correct 612 ms 60972 KB Output is correct
6 Correct 762 ms 65732 KB Output is correct
7 Correct 668 ms 65852 KB Output is correct
8 Correct 636 ms 65616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 7512 KB Output is correct
2 Correct 379 ms 25288 KB Output is correct
3 Correct 1369 ms 61052 KB Output is correct
4 Correct 1409 ms 61112 KB Output is correct
5 Correct 1484 ms 63496 KB Output is correct
6 Correct 803 ms 39096 KB Output is correct
7 Correct 400 ms 23976 KB Output is correct
8 Correct 63 ms 10836 KB Output is correct
9 Correct 1593 ms 61792 KB Output is correct
10 Correct 1511 ms 67936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1266 ms 61248 KB Output is correct
2 Correct 1365 ms 61060 KB Output is correct
3 Incorrect 1795 ms 103496 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 7516 KB Output is correct
2 Correct 2 ms 7516 KB Output is correct
3 Correct 2 ms 7516 KB Output is correct
4 Correct 2 ms 7516 KB Output is correct
5 Correct 2 ms 7516 KB Output is correct
6 Correct 2 ms 7516 KB Output is correct
7 Correct 2 ms 7516 KB Output is correct
8 Correct 2 ms 7516 KB Output is correct
9 Correct 2 ms 7516 KB Output is correct
10 Correct 2 ms 7516 KB Output is correct
11 Correct 2 ms 7516 KB Output is correct
12 Correct 2 ms 7516 KB Output is correct
13 Correct 3 ms 7772 KB Output is correct
14 Correct 2 ms 7516 KB Output is correct
15 Correct 2 ms 7516 KB Output is correct
16 Correct 8 ms 11436 KB Output is correct
17 Correct 8 ms 11356 KB Output is correct
18 Correct 7 ms 11868 KB Output is correct
19 Correct 204 ms 145380 KB Output is correct
20 Correct 217 ms 143924 KB Output is correct
21 Correct 166 ms 84832 KB Output is correct
22 Correct 28 ms 8284 KB Output is correct
23 Correct 27 ms 8284 KB Output is correct
24 Correct 28 ms 8388 KB Output is correct
25 Correct 36 ms 8384 KB Output is correct
26 Correct 30 ms 8284 KB Output is correct
27 Incorrect 138 ms 93744 KB Output isn't correct
28 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 7516 KB Output is correct
2 Correct 2 ms 7516 KB Output is correct
3 Correct 2 ms 7516 KB Output is correct
4 Correct 2 ms 7516 KB Output is correct
5 Correct 2 ms 7516 KB Output is correct
6 Correct 2 ms 7516 KB Output is correct
7 Correct 2 ms 7516 KB Output is correct
8 Correct 2 ms 7516 KB Output is correct
9 Correct 2 ms 7516 KB Output is correct
10 Correct 2 ms 7516 KB Output is correct
11 Correct 2 ms 7516 KB Output is correct
12 Correct 2 ms 7516 KB Output is correct
13 Correct 3 ms 7772 KB Output is correct
14 Correct 2 ms 7516 KB Output is correct
15 Correct 2 ms 7516 KB Output is correct
16 Correct 8 ms 11436 KB Output is correct
17 Correct 8 ms 11356 KB Output is correct
18 Correct 7 ms 11868 KB Output is correct
19 Correct 204 ms 145380 KB Output is correct
20 Correct 217 ms 143924 KB Output is correct
21 Correct 166 ms 84832 KB Output is correct
22 Correct 28 ms 8284 KB Output is correct
23 Correct 27 ms 8284 KB Output is correct
24 Correct 28 ms 8388 KB Output is correct
25 Correct 36 ms 8384 KB Output is correct
26 Correct 30 ms 8284 KB Output is correct
27 Correct 664 ms 61028 KB Output is correct
28 Correct 649 ms 61028 KB Output is correct
29 Correct 718 ms 60796 KB Output is correct
30 Correct 733 ms 61472 KB Output is correct
31 Correct 612 ms 60972 KB Output is correct
32 Correct 762 ms 65732 KB Output is correct
33 Correct 668 ms 65852 KB Output is correct
34 Correct 636 ms 65616 KB Output is correct
35 Correct 2 ms 7512 KB Output is correct
36 Correct 379 ms 25288 KB Output is correct
37 Correct 1369 ms 61052 KB Output is correct
38 Correct 1409 ms 61112 KB Output is correct
39 Correct 1484 ms 63496 KB Output is correct
40 Correct 803 ms 39096 KB Output is correct
41 Correct 400 ms 23976 KB Output is correct
42 Correct 63 ms 10836 KB Output is correct
43 Correct 1593 ms 61792 KB Output is correct
44 Correct 1511 ms 67936 KB Output is correct
45 Correct 1266 ms 61248 KB Output is correct
46 Correct 1365 ms 61060 KB Output is correct
47 Incorrect 1795 ms 103496 KB Output isn't correct
48 Halted 0 ms 0 KB -