제출 #111183

#제출 시각아이디문제언어결과실행 시간메모리
111183oToToT원 고르기 (APIO18_circle_selection)C++14
72 / 100
3057 ms307256 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; static inline int gc() { static char buf[1 << 20], *p = buf, *end = buf; if (p == end) { if ((end = buf + fread(buf, 1, 1 << 20, stdin)) == buf) return EOF; p = buf; } return *p++; } template<typename T> static inline bool gn(T &_){ register int c = gc(); register T __ = 1; _ = 0; while(!isdigit(c) and c!=EOF and c!='-') c = gc(); if(c == '-') { __ = -1; c = gc(); } if(c == EOF) return false; while(isdigit(c)) _ = _ * 10 + c - '0', c = gc(); _ *= __; return true; } template <typename T, typename ...Args> static inline bool gn(T &x, Args& ...args){return gn(x) and gn(args...);} 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() { gn( n ); for ( int i = 0 ; i < n ; ++ i ) gn( 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 * 10 ); 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 ) printf( "%d%c", ans[ i ], " \n"[ i == n - 1 ] ); } int main() { 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...