제출 #1341673

#제출 시각아이디문제언어결과실행 시간메모리
1341673nguyenkhangninh99원 고르기 (APIO18_circle_selection)C++20
100 / 100
2519 ms464436 KiB

#include<bits/stdc++.h>
using namespace std;

const int limit = 2000000010;
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

	int n; cin >> n;
    vector<array<int, 3>> a(n + 1);
    for(int i = 1; i <= n; i++){
        cin >> a[i][1] >> a[i][2] >> a[i][0];
        a[i][1] += 1e9;
        a[i][2] += 1e9;
    }
    vector<int> order(n + 1);
    for(int i = 1; i <= n; i++) order[i] = i;

    sort(order.begin() + 1, order.end(), [&](int i, int j){
        return a[i][0] == a[j][0] ? i < j : a[i][0] > a[j][0];
    });
    auto check = [&](int i, int j){
        return 1ll * (a[i][1] - a[j][1]) * (a[i][1] - a[j][1]) + 1ll * (a[i][2] - a[j][2]) * (a[i][2] - a[j][2]) <= 1ll * (a[i][0] + a[j][0]) * (a[i][0] + a[j][0]);
    };

    int sz = 2000000000;

    unordered_map<int, vector<int>> mp;
    vector<int> ans(n + 1);
    
    for(int i = 1; i <= n; i++){
        if(ans[order[i]]) continue;
        bool ok = false;
        while(sz / 2 >= a[order[i]][0]){
            sz /= 2;
            ok = 1;
        }

        ans[order[i]] = order[i];
        
        if(ok){
            mp.clear();
            for(int j = 1; j <= n; j++){
                if(!ans[j]) mp[1ll * (a[j][1] / sz) * limit + a[j][2] / sz].push_back(j);
            }
        }

        int x = a[order[i]][1] / sz, y = a[order[i]][2] / sz;
        for(int j = x - 2; j <= x + 2; j++){
            for(int k = y - 2; k <= y + 2; k++){
                long long id = 1ll * j * limit + k;
                for(int c: mp[id]){
                    if(check(c, order[i]) && !ans[c]) ans[c] = order[i];
                }
            }
        }
    }
    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...