제출 #639587

#제출 시각아이디문제언어결과실행 시간메모리
639587elkernos원 고르기 (APIO18_circle_selection)C++17
37 / 100
3057 ms33852 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll sq(int x) { return (ll)x * x; }

struct C {
    int x, y, r;
    void read() { cin >> x >> y >> r; }
    bool inter(const C &he) const { return sq(x - he.x) + sq(y - he.y) <= sq(r + he.r); }
};

struct T {
    int x, y, id;
    T(int xx, int yy, int iid) : x(xx), y(yy), id(iid) {}
    bool operator<(const T &he) const { return tie(x, y, id) < tie(he.x, he.y, he.id); }
};

const int oo = 1e9 + 7;

int32_t main()
{
    cin.tie(0)->sync_with_stdio(0);
    int n;
    cin >> n;
    vector<int> ans(n, -1), ord(n);
    vector<C> c(n);
    for(int i = 0; i < n; i++) {
        c[i].read();
        ord[i] = i;
    }
    sort(ord.begin(), ord.end(), [&](auto a, auto b) {
        return c[a].r == c[b].r ? a < b : c[a].r > c[b].r;
    });
    for(int rep = 30; rep >= 1; rep--) {
        set<T> aa;
        for(int i = 0; i < n; i++) {
            if(ans[i] == -1) {
                aa.emplace(c[i].x >> rep, c[i].y >> rep, i);
            }
        }
        auto zrob = [&](int i) {
            for(int k = -2; k <= 2; k++) {
                int x = (c[i].x >> rep) - k;
                int lo = (c[i].y >> rep) - 2;
                int hi = (c[i].y >> rep) + 2;
                auto it = aa.lower_bound(T{x, lo, -1});
                while(it != aa.end() && tie(it->x, it->y) <= tie(x, hi)) {
                    if(c[i].inter(c[it->id])) {
                        ans[it->id] = i;
                        it = aa.erase(it);
                    }
                    else {
                        it++;
                    }
                }
            }
        };
        int p = 0;
        while(p < n && c[ord[p]].r >= (1 << (rep - 1))) {
            if(ans[ord[p]] == -1) {
                zrob(ord[p]);
            }
            p++;
        }
    }
    for(int i = 0; i < n; i++) {
        cout << ans[i] + 1 << " ";
    }
    cout << '\n';
}
#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...