Submission #909310

# Submission time Handle Problem Language Result Execution time Memory
909310 2024-01-17T07:01:34 Z green_gold_dog Game (APIO22_game) C++17
0 / 100
0 ms 344 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 0 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB Wrong Answer[1]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB Wrong Answer[1]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB Wrong Answer[1]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB Wrong Answer[1]
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB Wrong Answer[1]
3 Halted 0 ms 0 KB -