제출 #1209019

#제출 시각아이디문제언어결과실행 시간메모리
1209019k1r1t0Circle selection (APIO18_circle_selection)C++20
37 / 100
3094 ms594828 KiB
#pragma GCC optimize("O3")

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

struct pt {int x, y;};
pt operator -(pt a, pt b) {return {a.x - b.x, a.y - b.y};}
pt operator +(pt a, pt b) {return {a.x + b.x, a.y + b.y};}
ll lensqr(pt a) {return 1ll * a.x * a.x + 1ll * a.y * a.y;}

const int K = 31;
const int N = 310000;
const int INF = (int)(1e9);

int n, r[N], ans[N];
pt p[N];
map<array<int, 2>, vector<int>> mp[K];

bool good(int i, int j) {
	return lensqr(p[i] - p[j]) <= 1ll * (r[i] + r[j]) * (r[i] + r[j]);
}

int32_t main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> p[i].x >> p[i].y >> r[i];
		p[i] = p[i] + pt(INF, INF);
		for (int j = 0; j < K; j++)
			mp[j][{p[i].x >> j, p[i].y >> j}].push_back(i);
	}
	vector<int> ord(n);
	iota(begin(ord), end(ord), 1);
	sort(begin(ord), end(ord), [&](int i, int j) {
		return r[i] > r[j] || (r[i] == r[j] && i < j);
	});
	for (int k : ord) {
		if (ans[k]) continue;
		int t = 0;
		while ((1ll << t) < r[k])
			t++;
		int bx = p[k].x >> t;
		int by = p[k].y >> t;
		for (int dx = -2; dx <= 2; dx++)
		for (int dy = -2; dy <= 2; dy++) {
			int cx = bx + dx;
			int cy = by + dy;
			vector<int> vec;
			for (auto i : mp[t][{cx, cy}]) {
				if (ans[i]) continue;
				if (good(i, k)) ans[i] = k;
				else vec.push_back(i);
			}
			mp[t][{cx, cy}] = vec;
		}
	}
	for (int i = 1; i <= n; i++)
		cout << ans[i] << ' ';
}
#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...