답안 #974809

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
974809 2024-05-03T20:15:57 Z efedmrlr 원 고르기 (APIO18_circle_selection) C++17
35 / 100
846 ms 132268 KB
#include <bits/stdc++.h>

#define int long long int
#define ld long double
#define pb push_back
#define MP make_pair
#define REP(i, n) for(int i = 0; (i) < (n); (i)++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;

void fastio() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const int N = 3e5 + 5;
const int INF = 1e9 + 500;
const int SHIFT = 1e9 + 2;
vector<array<int, 3> > p;
vector<set<array<int, 2> > > st;
vector<int> xc;
int rc = 0;
set<pair<int, int> > S;
int sqr(int x) {
    return 1ll * x * x;
}

bool query(int x, int y) {
    return sqr(p[x][1] - p[y][1]) + sqr(p[x][2] - p[y][2]) <= sqr(p[x][0] + p[y][0]);
}

void printp(int ind) {
    cout << "ind: " << ind + 1 << " rad:" << p[ind][0] << " x:" << p[ind][1] << " y:" << p[ind][2] << "\n";
}

void rescale(int r) {
    rc = r;
    st.clear();
    xc.clear();
    for(auto z : S) {
        int j = z.second;
        auto &c = p[j]; 
        for(int i = -2; i <= 2; i++) {
            xc.pb(c[1] / r + i);
        }
    }
    sort(all(xc));
    xc.resize(unique(all(xc)) - xc.begin());
    st.assign(xc.size(), set<array<int, 2> >());
    for(auto z : S) {
        int i = z.second;
        auto &c = p[i];
        int xx = lower_bound(all(xc), c[1] / r) - xc.begin();
        st[xx].insert({c[2] / r, i});
    }
    
    // for(int i = 0; i < xc.size(); i++) {
    //     cout << "i:" << i << " row:" << xc[i] << "\n";
    //     for(auto c : st[i]) {
    //         cout << "c0:" << c[0] << " c1:" << c[1] << "|| "; 
    //     }
    //     cout << "\n";
    // }
}

int n;
vector<int> ans(N, 0);
void eliminate() {
    int ind = (*S.begin()).second;
    ans[ind] = ind;
    S.erase(S.begin());
    if(p[ind][0] * 2 < rc) {
        rescale(p[ind][0]);
    }
    int xx = lower_bound(all(xc), p[ind][1] / rc) - xc.begin();
    int yy = p[ind][2] / rc;
    st[xx].erase({yy, ind});
    // printp(ind);
    // cout << "xx:" << xx << " yy:" << yy << "\n";
    // cout << "eliminates: ";
    for(int i = xx - 2; i <= xx + 2; i++) {
        for(auto j = st[i].lower_bound({yy - 2, 0}); j != st[i].end() && (*j)[0] <= yy + 2; ) {
            // printp((*j)[1]);
            if(query((*j)[1], ind)) {
                // cout << "killed\n";
                ans[(*j)[1]] = ind;
                S.erase({-p[(*j)[1]][0], (*j)[1]});
                j = st[i].erase(j);
            }
            else {
                j++;
            }
        }
    } 
    // cout << "\n\n";
}

void solve() {
    cin >> n;
    p.resize(n);
    REP(i, n) {

        cin >> p[i][1] >> p[i][2] >> p[i][0];
        p[i][1] += SHIFT;
        p[i][2] += SHIFT;
        S.insert({-p[i][0], i});
    }
    // cout << "zort" << endl;
    rescale(-(*S.begin()).first);
    // cout << "zort2" << endl;
    while(S.size()) {
        eliminate();
    }
    REP(i, n) {
        cout << ans[i] + 1 << " ";
    }
    cout << "\n";

}


signed main() {
    fastio();
    solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Runtime error 3 ms 5212 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 663 ms 62180 KB Output is correct
2 Correct 681 ms 61448 KB Output is correct
3 Correct 679 ms 62128 KB Output is correct
4 Correct 673 ms 62672 KB Output is correct
5 Correct 845 ms 62056 KB Output is correct
6 Correct 846 ms 70056 KB Output is correct
7 Correct 784 ms 62184 KB Output is correct
8 Correct 778 ms 64848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 5212 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 506 ms 65204 KB Output is correct
2 Correct 537 ms 132268 KB Output is correct
3 Correct 617 ms 61612 KB Output is correct
4 Correct 512 ms 110508 KB Output is correct
5 Correct 513 ms 120824 KB Output is correct
6 Correct 615 ms 61612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Runtime error 3 ms 5212 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2652 KB Output is correct
2 Correct 1 ms 2652 KB Output is correct
3 Runtime error 3 ms 5212 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -