제출 #1356884

#제출 시각아이디문제언어결과실행 시간메모리
1356884seungchan1e원 고르기 (APIO18_circle_selection)C++20
12 / 100
432 ms77452 KiB
#include <algorithm>
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int MAXN = 303030;

struct Circle {
    int x, y, r, id;
    bool doesIntersect(const Circle& rhs) const {
        ll dx = x - rhs.x;
        ll dy = y - rhs.y;
        ll pr = r + rhs.r;
        return dx * dx + dy * dy <= pr * pr;
    }
};

int n, a[MAXN];
Circle cx[MAXN];

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);

    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> cx[i].x >> cx[i].y >> cx[i].r; cx[i].id = i;
    }

    auto rescale = [](int R, vector<int>& pos, vector<vector<Circle>>& grid) {
        vector<int> newPos;
        vector<vector<Circle>> newGrid;
        for(int i = 0; i < pos.size(); i++) {
            vector<Circle> left, right;
            for(auto c : grid[i]) {
                if(c.x < pos[i]+R) left.push_back(c);
                else right.push_back(c);
            }
            if(left.size()) {
                newPos.push_back(pos[i]);
                newGrid.push_back(left);
            }
            if(right.size()) {
                newPos.push_back(pos[i]+R);
                newGrid.push_back(right);
            }
        }
        pos = newPos;
        grid = newGrid;
    };

    int R = 1<<30;

    vector<Circle> vc(cx+1, cx+n+1);
    sort(vc.begin(), vc.end(), [](const Circle& a, const Circle& b) { return tuple(-a.r, a.id) < tuple(-b.r, b.id); });

    vector<int> pos = {-(1<<30)};
    vector<vector<Circle>> grid = {vector<Circle>(cx+1, cx+n+1)};
    sort(grid[0].begin(), grid[0].end(), [](const Circle& a, const Circle& b) { return a.y < b.y; });
    rescale(R, pos, grid);

    for(auto ci : vc) {
        if(a[ci.id]) continue;
        a[ci.id] = ci.id;

        while(R/2 >= cx[ci.id].r) {
            R /= 2;
            rescale(R, pos, grid);
        }

        int sx = lower_bound(pos.begin(), pos.end(), R*(ci.x/R) - 2*R) - pos.begin();
        for(int j = sx; j < pos.size() && j < sx+6; j++) {
            int sy = lower_bound(grid[j].begin(), grid[j].end(), ci.y - 2*ci.r - 1, [](const Circle& a, int y) {
                return a.y < y;
            } ) - grid[j].begin();
            for(int k = sy; k < grid[j].size(); k++) {
                auto cj = grid[j][k];
                if(cj.y > ci.y + 2*ci.r) break;
                if(!a[cj.id] && ci.doesIntersect(cj)) a[cj.id] = ci.id;
            }
        }
    }

    for(int i = 1; i <= n; i++) cout << a[i] << " ";
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…