답안 #499266

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
499266 2021-12-27T16:37:34 Z _martynas 원 고르기 (APIO18_circle_selection) C++11
75 / 100
2011 ms 565044 KB
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

const ll MOD = 1e9+7;

const int MAX_N = 3e5+5;

int n;
ll X[MAX_N], Y[MAX_N], R[MAX_N];
int P[MAX_N];
bool visited[MAX_N];
int Inh[MAX_N];

struct Quad
{
    ll l, r, bot, top;
    array<Quad*, 4> childs = {};
    int idx;
    int sz;

    Quad()
    {
    }

    Quad(ll _l, ll _r, ll _bot, ll _top)
        : l(_l), r(_r), bot(_bot), top(_top)
    {
        idx = -1;
        sz = 0;
    }

    void add(ll x, ll y, int idx)
    {
        if(x < l || x > r || y < bot || y > top) {
            return;
        }

        sz++;
//        cerr << "l = " << l << ", r = " << r << ", "
//             << "bot = " << bot << ", top = " << top << "\n";
        if(l == r && bot == top) {
            this->idx = idx;
        }
        else {
            ll midH, midV;
            midH = l+(r-l)/2;
            midV = bot+(top-bot)/2;

            if(l != r && top != bot) {
                if(childs[0] == nullptr && !(x < l || x > midH || y < bot || y > midV)) {
                    childs[0] = new Quad(l, midH, bot, midV);
                }
                else if(childs[1] == nullptr && !(x < midH+1 || x > r || y < bot || y > midV)) {
                    childs[1] = new Quad(midH+1, r, bot, midV);
                }
                else if(childs[2] == nullptr && !(x < l || x > midH || y < midV+1 || y > top)) {
                    childs[2] = new Quad(l, midH, midV+1, top);
                }
                else if(childs[3] == nullptr && !(x < midH+1 || x > r || y < midV+1 || y > top)) {
                    childs[3] = new Quad(midH+1, r, midV+1, top);
                }
            }
            else if(l != r) {
                if(childs[0] == nullptr && !(x < l || x > midH || y < bot || y > top)) {
                    childs[0] = new Quad(l, midH, bot, midV);
                }
                else if(childs[1] == nullptr && !(x < midH+1 || x > r || y < bot || y > top)) {
                    childs[1] = new Quad(midH+1, r, bot, top);
                }
            }
            else if(top != bot) {
                if(childs[0] == nullptr && !(x < l || x > r || y < bot || y > midV)) {
                    childs[0] = new Quad(l, r, bot, midV);
                }
                else if(childs[1] == nullptr && !(x < l || x > r || y < midV+1 || y > top)) {
                    childs[1] = new Quad(l, r, midV+1, top);
                }
            }

            for(int k = 0; k < 4; k++) {
                if(childs[k] != nullptr) {
                    childs[k]->add(x, y, idx);
                }
            }
        }
    }

    void setInRange(ll x, ll y, ll radius, int idx)
    {
        if(x+2*radius < l || x-2*radius > r || y+2*radius < bot || y-2*radius > top || sz == 0) {
            return;
        }
//        cerr << "l = " << l << ", r = " << r << ", "
//             << "bot = " << bot << ", top = " << top << "\n";
        if(l == r && bot == top) {
            if((R[idx]+R[this->idx])*(R[idx]+R[this->idx])
                >= llabs(X[idx]-X[this->idx])*llabs(X[idx]-X[this->idx])
                +llabs(Y[idx]-Y[this->idx])*llabs(Y[idx]-Y[this->idx])) {
                P[this->idx] = idx;
                visited[this->idx] = true;
                sz--;
            }
            return;
        }

        int cnt = 0;
        for(int k = 0; k < 4; k++) {
            if(childs[k] != nullptr) {
                childs[k]->setInRange(x, y, radius, idx);
                cnt += childs[k]->sz;
            }
        }
        sz = cnt;
    }
};

Quad Q(-1000000000, 1000000000, -1000000000, 1000000000);

int main()
{
//    cerr << "0:\n";
//    Q.add(0, 0, 0);
//    cerr << "1:\n";
//    Q.add(2, 2, 1);
//    cerr << "2:\n";
//    Q.add(-3, -3, 2);
//
//    cerr << "P:\n";
//    Q.setInRange(0, 1, 1, 3);
//    for(int i = 0; i < 3; i++) {
//        cerr << i << ": " << P[i] << "\n";
//    }

    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> X[i] >> Y[i] >> R[i];
    }
    iota(P, P+n, 0);

    // Handle circles at the same position *correctly*
    fill(Inh, Inh+n, -1);
    map<pair<int, int>, int> M;
    for(int i = 0; i < n; i++) {
        auto it = M.find({X[i], Y[i]});
        if(it != M.end()) {
            //cerr << i << " same as " << it->second << "\n";
            if(R[it->second] < R[i]) {
                visited[it->second] = true;
                Inh[it->second] = i;
                M[{X[i], Y[i]}] = i;
            }
            else {
                visited[i] = true;
                Inh[i] = it->second;
            }
        }
        else {
            M[{X[i], Y[i]}] = i;
        }
    }

    for(int i = 0; i < n; i++) {
        //cerr << i << " started\n";
        if(!visited[i])
            Q.add(X[i], Y[i], i);
        //cerr << i << " finished\n";
    }

    vector<int> I(n);
    iota(I.begin(), I.end(), 0);
    sort(I.begin(), I.end(),
    [&](int a, int b)
    {
        return R[a] > R[b] || (R[a] == R[b] && a < b);
    });

    for(int i = 0; i < n; i++) {
        int idx = I[i];
        if(visited[idx]) continue;
        Q.setInRange(X[idx], Y[idx], R[idx], idx);
    }

    for(int i = 0; i < n; i++) {
        if(Inh[i] != -1) {
            int p = Inh[i];
            while(Inh[p] != -1) {
                p = Inh[p];
            }
            Inh[i] = p;
            P[i] = P[p];
        }
    }

    for(int i = 0; i < n; i++) {
        cout << 1+P[i] << " ";
    }
    cout << "\n";

    return 0;
}
/*
11
9 9 2
13 2 1
11 8 2
3 3 2
3 12 1
12 14 1
9 8 5
2 8 2
5 2 1
14 4 2
14 14 1
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 4 ms 2380 KB Output is correct
17 Correct 4 ms 2124 KB Output is correct
18 Correct 4 ms 2252 KB Output is correct
19 Correct 20 ms 9516 KB Output is correct
20 Correct 22 ms 7612 KB Output is correct
21 Correct 23 ms 10164 KB Output is correct
22 Correct 28 ms 9488 KB Output is correct
23 Correct 22 ms 8780 KB Output is correct
24 Correct 24 ms 9804 KB Output is correct
25 Correct 25 ms 10384 KB Output is correct
26 Correct 23 ms 10072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1306 ms 317068 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 593 ms 194692 KB Output is correct
3 Correct 1954 ms 565024 KB Output is correct
4 Correct 2011 ms 565044 KB Output is correct
5 Correct 1927 ms 507000 KB Output is correct
6 Correct 869 ms 273652 KB Output is correct
7 Correct 414 ms 143624 KB Output is correct
8 Correct 84 ms 29480 KB Output is correct
9 Correct 1944 ms 513980 KB Output is correct
10 Correct 1766 ms 531056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1743 ms 518872 KB Output is correct
2 Correct 1760 ms 496276 KB Output is correct
3 Correct 1689 ms 519320 KB Output is correct
4 Correct 1791 ms 534724 KB Output is correct
5 Correct 1820 ms 516964 KB Output is correct
6 Correct 1563 ms 510240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 4 ms 2380 KB Output is correct
17 Correct 4 ms 2124 KB Output is correct
18 Correct 4 ms 2252 KB Output is correct
19 Correct 20 ms 9516 KB Output is correct
20 Correct 22 ms 7612 KB Output is correct
21 Correct 23 ms 10164 KB Output is correct
22 Correct 28 ms 9488 KB Output is correct
23 Correct 22 ms 8780 KB Output is correct
24 Correct 24 ms 9804 KB Output is correct
25 Correct 25 ms 10384 KB Output is correct
26 Correct 23 ms 10072 KB Output is correct
27 Correct 44 ms 19012 KB Output is correct
28 Correct 43 ms 17936 KB Output is correct
29 Correct 46 ms 18836 KB Output is correct
30 Correct 57 ms 18132 KB Output is correct
31 Correct 46 ms 18088 KB Output is correct
32 Correct 45 ms 18756 KB Output is correct
33 Correct 474 ms 170600 KB Output is correct
34 Correct 461 ms 178172 KB Output is correct
35 Correct 482 ms 174332 KB Output is correct
36 Correct 594 ms 172976 KB Output is correct
37 Correct 541 ms 180216 KB Output is correct
38 Correct 546 ms 175644 KB Output is correct
39 Correct 932 ms 23620 KB Output is correct
40 Correct 940 ms 24644 KB Output is correct
41 Correct 920 ms 24684 KB Output is correct
42 Correct 365 ms 82208 KB Output is correct
43 Correct 509 ms 136440 KB Output is correct
44 Correct 483 ms 136384 KB Output is correct
45 Correct 487 ms 136376 KB Output is correct
46 Correct 490 ms 136416 KB Output is correct
47 Correct 484 ms 136484 KB Output is correct
48 Correct 501 ms 136432 KB Output is correct
49 Correct 504 ms 136576 KB Output is correct
50 Correct 535 ms 136416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 4 ms 2380 KB Output is correct
17 Correct 4 ms 2124 KB Output is correct
18 Correct 4 ms 2252 KB Output is correct
19 Correct 20 ms 9516 KB Output is correct
20 Correct 22 ms 7612 KB Output is correct
21 Correct 23 ms 10164 KB Output is correct
22 Correct 28 ms 9488 KB Output is correct
23 Correct 22 ms 8780 KB Output is correct
24 Correct 24 ms 9804 KB Output is correct
25 Correct 25 ms 10384 KB Output is correct
26 Correct 23 ms 10072 KB Output is correct
27 Incorrect 1306 ms 317068 KB Output isn't correct
28 Halted 0 ms 0 KB -