답안 #909329

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
909329 2024-01-17T07:11:51 Z green_gold_dog 게임 (APIO22_game) C++17
100 / 100
1430 ms 48872 KB
//#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include "game.h"
typedef int ll;

template<typename T>
bool assign_max(T& a, T b) {
        if (b > a) {
                a = b;
                return true;
        }
        return false;
}

template<typename T>
bool assign_min(T& a, T b) {
        if (b < a) {
                a = b;
                return true;
        }
        return false;
}

using namespace std;

struct NIGGA {
        vector<vector<ll>> g, rg;
        vector<ll> l, r;
        vector<ll> nl, nr;
        ll n, k;
        bool c = false;
        NIGGA(ll nn, ll nk) {
                n = nn;
                k = nk;
                n -= k;
                ll x = 1;
                while (x < k + 2) {
                        x *= 2;
                }
                l.resize(n, -1);
                r.resize(n, k);
                nl.resize(n, -1);
                nr.resize(n, x - 1);
                g.resize(n);
                rg.resize(n);
        }
        void upd(ll v) {
                if (r[v] <= l[v] || c) {
                        c = true;
                        return;
                }
                ll col = -1;
                while (true) {
                        col++;
                        ll mid = (nl[v] + nr[v]) / 2;
                        if (r[v] < mid) {
                                nr[v] = mid;
                                continue;
                        }
                        if (l[v] >= mid) {
                                nl[v] = mid;
                                continue;
                        }
                        break;
                }
                if (!col) {
                        return;
                }
                for (auto i : g[v]) {
                        if (assign_max(l[i], l[v])) {
                                upd(i);
                        }
                }
                for (auto i : rg[v]) {
                        if (assign_min(r[i], r[v])) {
                                upd(i);
                        }
                }
        }
        bool check() {
                return c;
        }
        bool get(ll& a) {
                if (a < k) {
                        return false;
                } else {
                        a -= k;
                        return true;
                }
        }
        void add(ll a, ll b) {
                bool c1 = get(a);
                bool c2 = get(b);
                if (c1 && c2) {
                        assign_max(l[b], l[a]);
                        g[a].push_back(b);
                        assign_min(r[a], r[b]);
                        rg[b].push_back(a);
                        upd(a);
                        upd(b);
                        return;
                }
                if (!c1 && !c2) {
                        if (a >= b) {
                                c = true;
                        }
                        return;
                }
                if (c2) {
                        assign_max(l[b], a);
                        upd(b);
                        return;
                }
                if (c1) {
                        assign_min(r[a], b);
                        upd(a);
                        return;
                }
        }
};

NIGGA nigger(2, 1);

void init(ll n, ll k) {
        nigger = NIGGA(n, k);
}

int add_teleporter(ll u, ll v) {
        nigger.add(u, v);
        if (nigger.check()) {
                return 1;
        }
        return 0;
}

#ifdef LOCAL
int main() {
        ll n, m, k;
        cin >> n >> m >> k;
        init(n, k);
        for (ll i = 0; i < m; i++) {
                ll a, b;
                cin >> a >> b;
                cout << add_teleporter(a, b) << '\n';
        }
}
#endif
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 356 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 356 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 596 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 2 ms 344 KB Output is correct
26 Correct 3 ms 856 KB Output is correct
27 Correct 2 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 356 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 596 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 2 ms 344 KB Output is correct
26 Correct 3 ms 856 KB Output is correct
27 Correct 2 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 16 ms 3640 KB Output is correct
31 Correct 4 ms 2628 KB Output is correct
32 Correct 15 ms 5144 KB Output is correct
33 Correct 18 ms 4952 KB Output is correct
34 Correct 27 ms 6728 KB Output is correct
35 Correct 27 ms 5080 KB Output is correct
36 Correct 33 ms 5032 KB Output is correct
37 Correct 21 ms 4188 KB Output is correct
38 Correct 20 ms 3988 KB Output is correct
39 Correct 33 ms 4184 KB Output is correct
40 Correct 28 ms 6484 KB Output is correct
41 Correct 29 ms 4748 KB Output is correct
42 Correct 25 ms 4712 KB Output is correct
43 Correct 34 ms 4944 KB Output is correct
44 Correct 32 ms 4884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 356 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 596 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 2 ms 344 KB Output is correct
26 Correct 3 ms 856 KB Output is correct
27 Correct 2 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 16 ms 3640 KB Output is correct
31 Correct 4 ms 2628 KB Output is correct
32 Correct 15 ms 5144 KB Output is correct
33 Correct 18 ms 4952 KB Output is correct
34 Correct 27 ms 6728 KB Output is correct
35 Correct 27 ms 5080 KB Output is correct
36 Correct 33 ms 5032 KB Output is correct
37 Correct 21 ms 4188 KB Output is correct
38 Correct 20 ms 3988 KB Output is correct
39 Correct 33 ms 4184 KB Output is correct
40 Correct 28 ms 6484 KB Output is correct
41 Correct 29 ms 4748 KB Output is correct
42 Correct 25 ms 4712 KB Output is correct
43 Correct 34 ms 4944 KB Output is correct
44 Correct 32 ms 4884 KB Output is correct
45 Correct 310 ms 31236 KB Output is correct
46 Correct 18 ms 19660 KB Output is correct
47 Correct 17 ms 19544 KB Output is correct
48 Correct 368 ms 44532 KB Output is correct
49 Correct 379 ms 38716 KB Output is correct
50 Correct 686 ms 31740 KB Output is correct
51 Correct 1041 ms 34920 KB Output is correct
52 Correct 699 ms 38576 KB Output is correct
53 Correct 976 ms 38272 KB Output is correct
54 Correct 906 ms 37272 KB Output is correct
55 Correct 1271 ms 38012 KB Output is correct
56 Correct 1430 ms 37036 KB Output is correct
57 Correct 334 ms 17900 KB Output is correct
58 Correct 289 ms 17796 KB Output is correct
59 Correct 329 ms 18440 KB Output is correct
60 Correct 341 ms 17744 KB Output is correct
61 Correct 401 ms 17988 KB Output is correct
62 Correct 544 ms 31552 KB Output is correct
63 Correct 580 ms 27928 KB Output is correct
64 Correct 1316 ms 48872 KB Output is correct
65 Correct 603 ms 32600 KB Output is correct
66 Correct 415 ms 28824 KB Output is correct
67 Correct 827 ms 36264 KB Output is correct
68 Correct 216 ms 25708 KB Output is correct
69 Correct 73 ms 19900 KB Output is correct
70 Correct 742 ms 30424 KB Output is correct
71 Correct 288 ms 25980 KB Output is correct
72 Correct 189 ms 21564 KB Output is correct
73 Correct 543 ms 29472 KB Output is correct
74 Correct 1424 ms 36124 KB Output is correct
75 Correct 1251 ms 41636 KB Output is correct
76 Correct 1225 ms 41596 KB Output is correct