Submission #502034

#TimeUsernameProblemLanguageResultExecution timeMemory
502034CodeTiger927Circle selection (APIO18_circle_selection)C++14
100 / 100
1473 ms54964 KiB
using namespace std;

#include <iostream>
#include <vector>
#include <algorithm>

#define MAXN 300005

typedef long long ll;
typedef pair<ll,ll> pll;

int N,vis[MAXN],ans[MAXN];
// current unit circle length
long long gl = 1e18;
vector<pair<pair<ll,int>,pll>> pts;
vector<ll> xs;
vector<vector<pair<ll,int>>> g;

int get(long long x) {
	x /= gl;
	return lower_bound(xs.begin(),xs.end(),x) - xs.begin();
}

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

bool check(int a,int b) {
	return sq(pts[a].second.first - pts[b].second.first) + sq(pts[a].second.second - pts[b].second.second) <= sq(pts[a].first.first + pts[b].first.first);
}

void reconstruct(long long nl) {
	// cout << "BEGIN RECONSTRUCTION!" << endl;
	gl = nl;
	g.clear();
	xs.clear();
	for(auto [a,b] : pts) {
		xs.push_back(b.first / gl);
	}
	sort(xs.begin(),xs.end());
	xs.resize(unique(xs.begin(),xs.end()) - xs.begin());
	g = vector<vector<pair<ll,int>>>(xs.size(),vector<pair<ll,int>>());
	for(int i = 0;i < N;++i) {
		if(!vis[i]) g[get(pts[i].second.first)].push_back({pts[i].second.second,i});
	}
	for(int i = 0;i < xs.size();++i) {
		sort(g[i].begin(),g[i].end());
	}
	return;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> N;
	for(int i = 0;i < N;++i) {
		long long x,y,r;
		cin >> x >> y >> r;
		pts.push_back({{r,i},{x + 1e9,y + 1e9}});
	}
	sort(pts.begin(),pts.end(),[&](auto a,auto b) {return make_pair(-a.first.first,a.first.second) < make_pair(-b.first.first,b.first.second);});
	// reconstruct(1e18);
	for(int i = 0;i < N;++i) {
		if(vis[i]) continue;
		// cout << "TERMINATOR " << i << " " << (pts[i].first.second + 1) << endl;
		if(pts[i].first.first * 2 <= gl) {
			reconstruct(pts[i].first.first);
		}
		int x = get(pts[i].second.first);
		long long y = pts[i].second.second;
		long long r = pts[i].first.first;
		int index = pts[i].first.second;
		long long ly = (y / gl) * gl - 2 * gl;
		long long hy = (y / gl) * gl + 3 * gl;

		for(int j = max(0,x - 2);j <= min(x + 2,(int)xs.size() - 1);++j) {
			auto itr = lower_bound(g[j].begin(),g[j].end(),make_pair(ly,-1));
			for(;itr != g[j].end() && itr -> first <= hy;++itr) {
				if(check(i,itr -> second)) {
					// cout << (itr -> second) << endl;
					if(!vis[itr -> second]) vis[itr -> second] = index + 1;
				}
			}
		}
	}
	for(int i = 0;i < N;++i) {
		ans[pts[i].first.second] = vis[i];
	}
	for(int i = 0;i < N;++i) {
		cout << ans[i] << " \n"[i == N - 1];
	}
	return 0;
}

Compilation message (stderr)

circle_selection.cpp: In function 'void reconstruct(long long int)':
circle_selection.cpp:37:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   37 |  for(auto [a,b] : pts) {
      |           ^
circle_selection.cpp:46:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |  for(int i = 0;i < xs.size();++i) {
      |                ~~^~~~~~~~~~~
circle_selection.cpp: In function 'int main()':
circle_selection.cpp:71:13: warning: unused variable 'r' [-Wunused-variable]
   71 |   long long r = pts[i].first.first;
      |             ^
#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...