제출 #700149

#제출 시각아이디문제언어결과실행 시간메모리
700149ymm원 고르기 (APIO18_circle_selection)C++17
100 / 100
2891 ms55820 KiB
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;

const int N = 300'010;
ll r[N], x[N], y[N];
 
inline ll sqr(ll x){return x*x;}
inline bool g(int i, int j){return sqr(x[i]-x[j]) + sqr(y[i]-y[j]) <= sqr(r[i]+r[j]);}

template<>
struct std::hash<pii>
{
	size_t operator()(const pii &x) const {
		return hash<ll>()(*(ll *)&x);
	}
};
 
unordered_map<pii, vector<pii>> mp[32];
int ans[N];
pll circ[N];
int n;
 
int main()
{
    cin.tie(0) -> sync_with_stdio(false);
    cin >> n;
    Loop(i,0,n)
    {
        cin >> x[i] >> y[i] >> r[i];
        x[i] += 1e9; y[i] += 1e9;
        circ[i] = {~r[i], i};
    }
    sort(circ, circ+n);
    Loop(_,0,n)
    {
        int i = circ[_].second;
        int lg = r[i]==1?0:32-__builtin_clz(r[i]-1);
        int mn = 1e9;
        for(int k = lg; k < 32; ++k)
        {
            ll r = k? 1<<(k-1): 0;
            ll d = r? 2*r: 1;
            // (r, d]
            Loop(xx,-1,2) Loop(yy,-1,2){
                auto tmp = mp[k].find(pii{x[i]/(2*d)+xx, y[i]/(2*d)+yy});
                if(tmp == mp[k].end()) continue;
                for(auto [j1, j2] : tmp->second){
                    if(g(i,j2)){
                        mn = min(j1, mn);
                        break;
                    }
                }
            }
        }
        if(mn == 1e9){
            ll r = lg? 1<<(lg-1): 0;
            ll d = r? 2*r: 1;
            mp[lg][pll{x[i]/(2*d), y[i]/(2*d)}].emplace_back(_, i);
            ans[i] = i;
        } else ans[i] = circ[mn].second;
    }
    Loop(i,0,n) cout << ans[i]+1 << ' ';
}
#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...