Submission #111181

#TimeUsernameProblemLanguageResultExecution timeMemory
111181oToToTCircle selection (APIO18_circle_selection)C++17
72 / 100
3021 ms298940 KiB
#pragma GCC optimize( "O3" )
#include <bits/stdc++.h>
using namespace std;
const int N = 300000 + 5;
const int C = 1000000000;
template < typename A, typename B >
using UMP = unordered_map< A, B >;
using lld = int64_t;

int n;
vector< int > ord;
lld x[ N ], y[ N ], r[ N ];

inline bool inter( int i, int j ) {
	const lld ox = x[ i ] - x[ j ];
	const lld oy = y[ i ] - y[ j ];
	const lld R = r[ i ] + r[ j ];
	return ox * ox + oy * oy <= R * R;
}

void init() {
	cin >> n;
	for ( int i = 0 ; i < n ; ++ i )
		cin >> x[ i ] >> y[ i ] >> r[ i ];
	for ( int i = 0 ; i < n ; ++ i )
		x[ i ] += C, y[ i ] += C;

	ord.resize( n );
	iota( ord.begin(), ord.end(), 0 );
	sort( ord.begin(), ord.end(), []( int a, int b ) {
		return tie( r[ a ], b ) > tie( r[ b ], a );
	} );
}

UMP< lld, UMP< lld, vector< int > > > plane;
int ans[ N ];
int LogL = 32;
lld unit = 1;
inline void build() {
	plane.clear(); plane.rehash( n );
	for ( int i = 0 ; i < n ; ++ i ) {
		if ( ans[ i ] ) continue;
		plane[ x[ i ] >> LogL ][ y[ i ] >> LogL ].push_back( i );
	}
}

const int dx[] = { -1, 0, 1 }, dy[] = { -1, 0, 1 };

void solve() {
	build();
	for ( int i : ord ) {
		if ( ans[ i ] ) continue;
		ans[ i ] = i + 1;
		int pLogL = LogL;
		while( ( unit << ( -- LogL ) ) > r[ i ] + r[ i ] );
		if ( pLogL != ++ LogL ) build();
		lld X = x[ i ] >> LogL, Y = y[ i ] >> LogL;
		for ( int i_ = 0 ; i_ < 3 ; ++ i_ ) {
			for ( int j_ = 0 ; j_ < 3 ; ++ j_ ) {
				for ( int j : plane[ X + dx[ i_ ] ][ Y + dy[ j_ ] ] ) {
					if ( ans[ j ] ) continue;
					if ( inter( i, j ) ) ans[ j ] = i + 1;
				}
			}
		}
	}
	for ( int i = 0 ; i < n ; ++ i )
		cout << ans[ i ] << " \n"[ i == n - 1 ];
}

int main() {
	ios_base::sync_with_stdio( false );
	cin.tie( nullptr );
	init(); solve();
	return 0;
}
#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...