Submission #1070463

#TimeUsernameProblemLanguageResultExecution timeMemory
1070463thangdz2k7Circle selection (APIO18_circle_selection)C++17
19 / 100
645 ms47864 KiB
#include <bits/stdc++.h>

using namespace std;

const int N = 3e5 + 5;

long long sqr(long long x){ return x * x; }

struct circle{
    long long x, y, r;

    bool intersect(circle A){
        return sqr(x - A.x) + sqr(y - A.y) <= sqr(r + A.r);
    }
};

int n;
circle a[N];

namespace subtask1{
    int ans[N];

    void solve(){
        while (true){
            long long maxr = 0;
            int idx = 0;
            for (int i = 1; i <= n; ++ i) if (!ans[i] && a[i].r > maxr){
                idx = i;
                maxr = a[i].r;
            }
            if (!idx) break;
            for (int i = 1; i <= n; ++ i) if (!ans[i] && a[idx].intersect(a[i])) ans[i] = idx;
        }
        for (int i = 1; i <= n; ++ i) cout << ans[i] << ' ';
    }
}

namespace subtask2{
    vector <int> sr;
    int ans[N];
    set <pair <int, int>> l, r;

    void solve(){
        for (int i = 1; i <= n; ++ i) {
            sr.push_back(i);
            l.insert({a[i].x - a[i].r, i});
            r.insert({a[i].x + a[i].r, i});
        }
        sort(sr.begin(), sr.end(), [&](int u, int v){
            if (a[u].r == a[v].r) return u < v;
            return a[u].r > a[v].r;
        });

        for (int id : sr){
            if (ans[id]) continue;
            int le = a[id].x - a[id].r;
            int ri = a[id].x + a[id].r;
            auto it = l.lower_bound({le, 0});
            while (it != l.end() && it -> first <= ri){
                int del = it -> second;
                ans[del] = id;
                ++ it;
                l.erase({a[del].x - a[del].r, del});
                r.erase({a[del].x + a[del].r, del});
            }
            it = r.lower_bound({le, 0});
            while (it != r.end() && it -> first <= ri){
                int del = it -> second;
                ans[del] = id;
                ++ it;
                l.erase({a[del].x - a[del].r, del});
                r.erase({a[del].x + a[del].r, del});
            }
        }

        for (int i = 1; i <= n; ++ i) cout << ans[i] << ' ';
    }
}

namespace subtask4{
    void solve(){

    }
}

namespace Acepted{
    void solve(){

    }
}

void solve(){
    cin >> n;
    bool ck2 = true;
    bool ck4 = true;
    for (int i = 1; i <= n; ++ i) {
        cin >> a[i].x >> a[i].y >> a[i].r;
        if (a[i].y != 0) ck2 = false;
        if (i > 1 && a[i].r != a[i - 1].r) ck4 = false;
    }

    if (n <= 5000) subtask1::solve();
    else if (ck2) subtask2::solve();
    else if (ck4) subtask4::solve();
    else Acepted::solve();
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    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...