Submission #909327

# Submission time Handle Problem Language Result Execution time Memory
909327 2024-01-17T07:11:07 Z green_gold_dog Game (APIO22_game) C++17
60 / 100
4000 ms 43184 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;
                }
                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
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 596 KB Output is correct
8 Correct 0 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 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 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 1 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 596 KB Output is correct
8 Correct 0 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 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 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 1 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 1 ms 600 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 632 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 4 ms 344 KB Output is correct
25 Correct 2 ms 344 KB Output is correct
26 Correct 2 ms 344 KB Output is correct
27 Correct 2 ms 600 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 2 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 596 KB Output is correct
8 Correct 0 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 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 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 1 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 1 ms 600 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 632 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 4 ms 344 KB Output is correct
25 Correct 2 ms 344 KB Output is correct
26 Correct 2 ms 344 KB Output is correct
27 Correct 2 ms 600 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 2 ms 600 KB Output is correct
30 Correct 22 ms 4060 KB Output is correct
31 Correct 9 ms 2704 KB Output is correct
32 Correct 28 ms 4920 KB Output is correct
33 Correct 17 ms 4352 KB Output is correct
34 Correct 1060 ms 5464 KB Output is correct
35 Correct 379 ms 4880 KB Output is correct
36 Correct 56 ms 4544 KB Output is correct
37 Correct 40 ms 4684 KB Output is correct
38 Correct 33 ms 3904 KB Output is correct
39 Correct 28 ms 4116 KB Output is correct
40 Correct 1034 ms 5364 KB Output is correct
41 Correct 186 ms 4196 KB Output is correct
42 Correct 121 ms 4424 KB Output is correct
43 Correct 45 ms 4656 KB Output is correct
44 Correct 1018 ms 5284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 596 KB Output is correct
8 Correct 0 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 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 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 1 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 1 ms 600 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 632 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 4 ms 344 KB Output is correct
25 Correct 2 ms 344 KB Output is correct
26 Correct 2 ms 344 KB Output is correct
27 Correct 2 ms 600 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 2 ms 600 KB Output is correct
30 Correct 22 ms 4060 KB Output is correct
31 Correct 9 ms 2704 KB Output is correct
32 Correct 28 ms 4920 KB Output is correct
33 Correct 17 ms 4352 KB Output is correct
34 Correct 1060 ms 5464 KB Output is correct
35 Correct 379 ms 4880 KB Output is correct
36 Correct 56 ms 4544 KB Output is correct
37 Correct 40 ms 4684 KB Output is correct
38 Correct 33 ms 3904 KB Output is correct
39 Correct 28 ms 4116 KB Output is correct
40 Correct 1034 ms 5364 KB Output is correct
41 Correct 186 ms 4196 KB Output is correct
42 Correct 121 ms 4424 KB Output is correct
43 Correct 45 ms 4656 KB Output is correct
44 Correct 1018 ms 5284 KB Output is correct
45 Correct 381 ms 31048 KB Output is correct
46 Correct 20 ms 19800 KB Output is correct
47 Correct 17 ms 19704 KB Output is correct
48 Correct 570 ms 43184 KB Output is correct
49 Correct 458 ms 38448 KB Output is correct
50 Execution timed out 4091 ms 25320 KB Time limit exceeded
51 Halted 0 ms 0 KB -