Submission #1261752

#TimeUsernameProblemLanguageResultExecution timeMemory
12617524QT0R원 고르기 (APIO18_circle_selection)C++20
100 / 100
919 ms30684 KiB
#include <bits/stdc++.h>
using namespace std;
#define ll long long

ll n;
vector<array<ll, 3>> info;
vector<array<ll, 3>> points;
vector<ll> ans;
vector<bool> del;

ll grid_length;

ll sq(ll x)
{
	return x * x;
}

bool query(ll i, ll j)
{
	return (sq(info[i][0] - info[j][0]) + sq(info[i][1] - info[j][1])) <= sq(info[i][2] + info[j][2]);
}

void remake()
{
	points.clear();
	for (ll i = 0; i < n; i++)
	{
		if (!del[i])
			continue;
		points.push_back({info[i][0] / grid_length, info[i][1] / grid_length, i});
	}
	sort(points.begin(), points.end());
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	cin >> n;
	ans.resize(n);
	del.resize(n, 1);
	for (ll i = 1, x, y, r; i <= n; i++)
	{
		cin >> x >> y >> r;
		info.push_back({x, y, r});
	}
	vector<ll> kol(n);
	iota(kol.begin(), kol.end(), 0);
	sort(kol.begin(), kol.end(), [&](ll a, ll b)
		 { return info[a][2] == info[b][2] ? a < b : info[a][2] > info[b][2]; });
	grid_length = info[kol[0]][2];
	remake();
	for (auto now : kol)
	{
		if (!del[now])
			continue;
		if (2 * info[now][2] <= grid_length)
		{
			grid_length = info[now][2];
			remake();
		}
		ll cur_x = info[now][0] / grid_length;
		ll cur_y = info[now][1] / grid_length;
		vector<ll> deleted_now;
		auto lst = points.begin();
		auto fin = lower_bound(points.begin(), points.end(), (array<ll, 3>){cur_x+2, cur_y+3, -1});
		for (ll x = cur_x - 2; x <= cur_x + 2; x++)
		{
			for (ll y = cur_y - 2; y <= cur_y + 2; y++)
			{
				auto it1 = lower_bound(lst, fin, (array<ll, 3>){x, y, -1});
				auto it2 = lower_bound(it1, fin, (array<ll, 3>){x, y + 1, -1});
				for (; it1 != it2; it1++)
				{
					ll ind = (*it1)[2];
					if (del[ind] && query(now, ind))
					{
						del[ind] = false;
						ans[ind] = now;
					}
				}
				swap(lst, it1);
			}
		}
	}
	for (auto x : ans)
		cout << x + 1 << ' ';
	cout << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...