답안 #499271

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
499271 2021-12-27T18:00:56 Z _martynas 원 고르기 (APIO18_circle_selection) C++14
87 / 100
3000 ms 656396 KB
#include <bits/stdc++.h>

using namespace std;
using namespace std::chrono;

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 LLNode
{
    int idx;
    LLNode* next = nullptr;

    LLNode()
    {
    }

    LLNode(int val)
        : idx(val)
    {
    }
} LLNodes[MAX_N];
int llcounter = 0;

inline LLNode* getLLNode()
{
    return &LLNodes[llcounter++];
}

int dup;

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

    Quad()
    {
    }

    Quad(ll _l, ll _r, ll _bot, ll _top)
        : l(_l), r(_r), bot(_bot), top(_top)
    {
        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) {
            if(llnode == nullptr) {
                llnode = getLLNode();
                llnode->idx = idx;
            }
            else {
                dup++;
                LLNode* temp = getLLNode();
                temp->idx = idx;
                temp->next = llnode;
                llnode = temp;
            }
        }
        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) {
            while(llnode != nullptr &&
                (R[idx]+R[llnode->idx])*(R[idx]+R[llnode->idx])
                >= llabs(X[idx]-X[llnode->idx])*llabs(X[idx]-X[llnode->idx])
                +llabs(Y[idx]-Y[llnode->idx])*llabs(Y[idx]-Y[llnode->idx])) {
                P[llnode->idx] = idx;
                visited[llnode->idx] = true;
                sz--;
                llnode = llnode->next;
            }
            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()
{
    auto stop = steady_clock::now();

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

//    cerr << "Exec: " << duration_cast<milliseconds>(steady_clock::now()-stop).count() << " ms\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 = n-1; i >= 0; i--) {
        int idx = I[i];
        //cerr << i << " started\n";
        Q.add(X[idx], Y[idx], idx);
        //cerr << i << " finished\n";
    }

    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++) {
        cout << 1+P[i] << " ";
    }
    cout << "\n";

//    cerr << "Dupe: " << dup << "\n";
//    cerr << "Exec: " << duration_cast<milliseconds>(steady_clock::now()-stop).count() << " ms\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
*/

Compilation message

circle_selection.cpp: In function 'int main()':
circle_selection.cpp:159:10: warning: variable 'stop' set but not used [-Wunused-but-set-variable]
  159 |     auto stop = steady_clock::now();
      |          ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4940 KB Output is correct
2 Correct 2 ms 4940 KB Output is correct
3 Correct 2 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 5196 KB Output is correct
7 Correct 2 ms 5196 KB Output is correct
8 Correct 3 ms 5196 KB Output is correct
9 Correct 3 ms 5196 KB Output is correct
10 Correct 3 ms 5196 KB Output is correct
11 Correct 3 ms 5196 KB Output is correct
12 Correct 3 ms 5196 KB Output is correct
13 Correct 3 ms 5196 KB Output is correct
14 Correct 2 ms 5196 KB Output is correct
15 Correct 2 ms 5196 KB Output is correct
16 Correct 6 ms 7372 KB Output is correct
17 Correct 6 ms 7164 KB Output is correct
18 Correct 6 ms 7216 KB Output is correct
19 Correct 22 ms 15612 KB Output is correct
20 Correct 21 ms 13236 KB Output is correct
21 Correct 26 ms 16324 KB Output is correct
22 Correct 27 ms 15600 KB Output is correct
23 Correct 22 ms 14668 KB Output is correct
24 Correct 27 ms 15944 KB Output is correct
25 Correct 24 ms 16588 KB Output is correct
26 Correct 24 ms 16204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1161 ms 358804 KB Output is correct
2 Correct 1199 ms 370640 KB Output is correct
3 Correct 1190 ms 349860 KB Output is correct
4 Correct 1210 ms 387084 KB Output is correct
5 Correct 711 ms 65344 KB Output is correct
6 Correct 1038 ms 211248 KB Output is correct
7 Correct 852 ms 135108 KB Output is correct
8 Correct 945 ms 157472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5068 KB Output is correct
2 Correct 622 ms 229528 KB Output is correct
3 Correct 1821 ms 656328 KB Output is correct
4 Correct 1811 ms 656396 KB Output is correct
5 Correct 1798 ms 587528 KB Output is correct
6 Correct 808 ms 319440 KB Output is correct
7 Correct 403 ms 169880 KB Output is correct
8 Correct 78 ms 38532 KB Output is correct
9 Correct 1827 ms 595168 KB Output is correct
10 Correct 1655 ms 615656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1649 ms 600976 KB Output is correct
2 Correct 1563 ms 573804 KB Output is correct
3 Correct 1463 ms 601416 KB Output is correct
4 Correct 1595 ms 620128 KB Output is correct
5 Correct 1577 ms 598464 KB Output is correct
6 Correct 1417 ms 590640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4940 KB Output is correct
2 Correct 2 ms 4940 KB Output is correct
3 Correct 2 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 5196 KB Output is correct
7 Correct 2 ms 5196 KB Output is correct
8 Correct 3 ms 5196 KB Output is correct
9 Correct 3 ms 5196 KB Output is correct
10 Correct 3 ms 5196 KB Output is correct
11 Correct 3 ms 5196 KB Output is correct
12 Correct 3 ms 5196 KB Output is correct
13 Correct 3 ms 5196 KB Output is correct
14 Correct 2 ms 5196 KB Output is correct
15 Correct 2 ms 5196 KB Output is correct
16 Correct 6 ms 7372 KB Output is correct
17 Correct 6 ms 7164 KB Output is correct
18 Correct 6 ms 7216 KB Output is correct
19 Correct 22 ms 15612 KB Output is correct
20 Correct 21 ms 13236 KB Output is correct
21 Correct 26 ms 16324 KB Output is correct
22 Correct 27 ms 15600 KB Output is correct
23 Correct 22 ms 14668 KB Output is correct
24 Correct 27 ms 15944 KB Output is correct
25 Correct 24 ms 16588 KB Output is correct
26 Correct 24 ms 16204 KB Output is correct
27 Correct 46 ms 26572 KB Output is correct
28 Correct 43 ms 25308 KB Output is correct
29 Correct 43 ms 26308 KB Output is correct
30 Correct 46 ms 25544 KB Output is correct
31 Correct 44 ms 25412 KB Output is correct
32 Correct 45 ms 26340 KB Output is correct
33 Correct 441 ms 200536 KB Output is correct
34 Correct 450 ms 209808 KB Output is correct
35 Correct 457 ms 205124 KB Output is correct
36 Correct 500 ms 203460 KB Output is correct
37 Correct 523 ms 212244 KB Output is correct
38 Correct 524 ms 206676 KB Output is correct
39 Correct 1203 ms 25348 KB Output is correct
40 Correct 1103 ms 25296 KB Output is correct
41 Correct 1111 ms 25320 KB Output is correct
42 Correct 351 ms 92664 KB Output is correct
43 Correct 462 ms 156608 KB Output is correct
44 Correct 460 ms 156428 KB Output is correct
45 Correct 471 ms 156476 KB Output is correct
46 Correct 463 ms 156472 KB Output is correct
47 Correct 471 ms 156456 KB Output is correct
48 Correct 465 ms 156484 KB Output is correct
49 Correct 477 ms 156560 KB Output is correct
50 Correct 464 ms 156468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4940 KB Output is correct
2 Correct 2 ms 4940 KB Output is correct
3 Correct 2 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 5196 KB Output is correct
7 Correct 2 ms 5196 KB Output is correct
8 Correct 3 ms 5196 KB Output is correct
9 Correct 3 ms 5196 KB Output is correct
10 Correct 3 ms 5196 KB Output is correct
11 Correct 3 ms 5196 KB Output is correct
12 Correct 3 ms 5196 KB Output is correct
13 Correct 3 ms 5196 KB Output is correct
14 Correct 2 ms 5196 KB Output is correct
15 Correct 2 ms 5196 KB Output is correct
16 Correct 6 ms 7372 KB Output is correct
17 Correct 6 ms 7164 KB Output is correct
18 Correct 6 ms 7216 KB Output is correct
19 Correct 22 ms 15612 KB Output is correct
20 Correct 21 ms 13236 KB Output is correct
21 Correct 26 ms 16324 KB Output is correct
22 Correct 27 ms 15600 KB Output is correct
23 Correct 22 ms 14668 KB Output is correct
24 Correct 27 ms 15944 KB Output is correct
25 Correct 24 ms 16588 KB Output is correct
26 Correct 24 ms 16204 KB Output is correct
27 Correct 1161 ms 358804 KB Output is correct
28 Correct 1199 ms 370640 KB Output is correct
29 Correct 1190 ms 349860 KB Output is correct
30 Correct 1210 ms 387084 KB Output is correct
31 Correct 711 ms 65344 KB Output is correct
32 Correct 1038 ms 211248 KB Output is correct
33 Correct 852 ms 135108 KB Output is correct
34 Correct 945 ms 157472 KB Output is correct
35 Correct 2 ms 5068 KB Output is correct
36 Correct 622 ms 229528 KB Output is correct
37 Correct 1821 ms 656328 KB Output is correct
38 Correct 1811 ms 656396 KB Output is correct
39 Correct 1798 ms 587528 KB Output is correct
40 Correct 808 ms 319440 KB Output is correct
41 Correct 403 ms 169880 KB Output is correct
42 Correct 78 ms 38532 KB Output is correct
43 Correct 1827 ms 595168 KB Output is correct
44 Correct 1655 ms 615656 KB Output is correct
45 Correct 1649 ms 600976 KB Output is correct
46 Correct 1563 ms 573804 KB Output is correct
47 Correct 1463 ms 601416 KB Output is correct
48 Correct 1595 ms 620128 KB Output is correct
49 Correct 1577 ms 598464 KB Output is correct
50 Correct 1417 ms 590640 KB Output is correct
51 Correct 46 ms 26572 KB Output is correct
52 Correct 43 ms 25308 KB Output is correct
53 Correct 43 ms 26308 KB Output is correct
54 Correct 46 ms 25544 KB Output is correct
55 Correct 44 ms 25412 KB Output is correct
56 Correct 45 ms 26340 KB Output is correct
57 Correct 441 ms 200536 KB Output is correct
58 Correct 450 ms 209808 KB Output is correct
59 Correct 457 ms 205124 KB Output is correct
60 Correct 500 ms 203460 KB Output is correct
61 Correct 523 ms 212244 KB Output is correct
62 Correct 524 ms 206676 KB Output is correct
63 Correct 1203 ms 25348 KB Output is correct
64 Correct 1103 ms 25296 KB Output is correct
65 Correct 1111 ms 25320 KB Output is correct
66 Correct 351 ms 92664 KB Output is correct
67 Correct 462 ms 156608 KB Output is correct
68 Correct 460 ms 156428 KB Output is correct
69 Correct 471 ms 156476 KB Output is correct
70 Correct 463 ms 156472 KB Output is correct
71 Correct 471 ms 156456 KB Output is correct
72 Correct 465 ms 156484 KB Output is correct
73 Correct 477 ms 156560 KB Output is correct
74 Correct 464 ms 156468 KB Output is correct
75 Correct 1505 ms 613524 KB Output is correct
76 Correct 1353 ms 472404 KB Output is correct
77 Correct 1344 ms 523808 KB Output is correct
78 Correct 1410 ms 603832 KB Output is correct
79 Correct 1778 ms 619292 KB Output is correct
80 Correct 1435 ms 592172 KB Output is correct
81 Correct 1724 ms 603408 KB Output is correct
82 Correct 1716 ms 608288 KB Output is correct
83 Correct 1706 ms 615960 KB Output is correct
84 Correct 1708 ms 571608 KB Output is correct
85 Correct 1730 ms 623972 KB Output is correct
86 Correct 1743 ms 618252 KB Output is correct
87 Correct 1740 ms 543172 KB Output is correct
88 Execution timed out 3080 ms 63712 KB Time limit exceeded
89 Halted 0 ms 0 KB -