Submission #991435

# Submission time Handle Problem Language Result Execution time Memory
991435 2024-06-02T09:01:53 Z Forested Werewolf (IOI18_werewolf) C++17
100 / 100
2191 ms 47396 KB
#include <bits/stdc++.h>
#define OVERRIDE4(a, b, c, d, ...) d
#define REP2(i, n) for (i32 i = 0; i < (i32)(n); ++i)
#define REP3(i, l, r) for (i32 i = (i32)(l); i < (i32)(r); ++i)
#define REP(...) OVERRIDE4(__VA_ARGS__, REP3, REP2)(__VA_ARGS__)
#define PER2(i, n) for (i32 i = (i32)(n)-1; i >= 0; --i)
#define PER3(i, l, r) for (i32 i = (i32)(r)-1; i >= (i32)(l); --i)
#define PER(...) OVERRIDE4(__VA_ARGS__, PER3, PER2)(__VA_ARGS__)
#define LEN(x) (i32)(x).size()
#define ALL(x) begin(x), end(x)
using namespace std;
using i32 = int;
using i64 = long long;
template <typename T>
using V = vector<T>;
template <typename T>
bool chmin(T &x, const T &y) {
    if (x > y) {
        x = y;
        return true;
    }
    return false;
}
template <typename T>
bool chmax(T &x, const T &y) {
    if (x < y) {
        x = y;
        return true;
    }
    return false;
}

#include "werewolf.h"

class UF {
    V<i32> par;
    V<pair<i32, i32>> mnx;
public:
    UF(i32 n) : par(n, -1), mnx(n) {
        REP(i, n) {
            mnx[i] = pair<i32, i32>(i, i);
        }
    }
    i32 root(i32 x) {
        if (par[x] < 0) {
            return x;
        } else {
            return par[x] = root(par[x]);
        }
    }
    pair<i32, i32> get_minmax(i32 v) {
        i32 r = root(v);
        return mnx[r];
    }
    bool unite(i32 x, i32 y) {
        x = root(x);
        y = root(y);
        if (x == y) {
            return false;
        }
        if (-par[x] > -par[y]) {
            swap(x, y);
        }
        chmin(mnx[y].first, mnx[x].first);
        chmax(mnx[y].second, mnx[x].second);
        par[y] += par[x];
        par[x] = y;
        return true;
    }
};

V<i32> check_validity(i32 n, V<i32> x, V<i32> y, V<i32> s, V<i32> e, V<i32> l, V<i32> r) {
    i32 q = LEN(s);
    V<V<i32>> g(n);
    REP(i, LEN(x)) {
        g[x[i]].push_back(y[i]);
        g[y[i]].push_back(x[i]);
    }
    V<i32> par0(n, -1), par1(n, -1);
    {
        V<V<i32>> process(n);
        REP(i, q) {
            process[l[i]].push_back(i);
        }
        UF uf(n);
        PER(i, n) {
            for (i32 j : g[i]) {
                if (j > i) {
                    i32 tmp = uf.get_minmax(j).first;
                    if (uf.unite(i, j)) {
                        par0[tmp] = i;
                    }
                }
            }
            for (i32 j : process[i]) {
                s[j] = uf.get_minmax(s[j]).first;
            }
        }
    }
    {
        V<V<i32>> process(n);
        REP(i, q) {
            process[r[i]].push_back(i);
        }
        UF uf(n);
        REP(i, n) {
            for (i32 j : g[i]) {
                if (j < i) {
                    i32 tmp = uf.get_minmax(j).second;
                    if (uf.unite(i, j)) {
                        par1[tmp] = i;
                    }
                }
            }
            for (i32 j : process[i]) {
                e[j] = uf.get_minmax(e[j]).second;
            }
        }
    }
    V<i32> ans(q, 0);
    constexpr i32 B = 64;
    using u64 = unsigned long long;
    i32 blk = (q + B + 1) / B;
    V<u64> dp0(n, 0), dp1(n, 0);
    REP(iter, blk) {
        i32 l = B * iter;
        i32 r = min(q, l + B);
        REP(i, n) {
            dp0[i] = dp1[i] = 0;
        }
        REP(i, l, r) {
            dp0[s[i]] ^= 1ull << (i - l);
            dp1[e[i]] ^= 1ull << (i - l);
        }
        REP(i, 1, n) {
            dp0[i] |= dp0[par0[i]];
        }
        PER(i, n - 1) {
            dp1[i] |= dp1[par1[i]];
        }
        u64 t = 0;
        REP(i, n) {
            t |= dp0[i] & dp1[i];
        }
        REP(i, l, r) {
            if (t & (1ull << (i - l))) {
                ans[i] = 1;
            }
        }
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 436 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 436 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 3 ms 860 KB Output is correct
11 Correct 4 ms 860 KB Output is correct
12 Correct 3 ms 860 KB Output is correct
13 Correct 3 ms 868 KB Output is correct
14 Correct 4 ms 884 KB Output is correct
15 Correct 4 ms 888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1913 ms 32544 KB Output is correct
2 Correct 1643 ms 32668 KB Output is correct
3 Correct 1464 ms 32468 KB Output is correct
4 Correct 1477 ms 32544 KB Output is correct
5 Correct 1465 ms 32456 KB Output is correct
6 Correct 1750 ms 32540 KB Output is correct
7 Correct 1873 ms 31496 KB Output is correct
8 Correct 1619 ms 32536 KB Output is correct
9 Correct 1433 ms 33088 KB Output is correct
10 Correct 1433 ms 33364 KB Output is correct
11 Correct 1433 ms 33360 KB Output is correct
12 Correct 1792 ms 32912 KB Output is correct
13 Correct 2145 ms 32544 KB Output is correct
14 Correct 2072 ms 32468 KB Output is correct
15 Correct 2087 ms 32536 KB Output is correct
16 Correct 2103 ms 32552 KB Output is correct
17 Correct 1823 ms 31824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 436 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 3 ms 860 KB Output is correct
11 Correct 4 ms 860 KB Output is correct
12 Correct 3 ms 860 KB Output is correct
13 Correct 3 ms 868 KB Output is correct
14 Correct 4 ms 884 KB Output is correct
15 Correct 4 ms 888 KB Output is correct
16 Correct 1913 ms 32544 KB Output is correct
17 Correct 1643 ms 32668 KB Output is correct
18 Correct 1464 ms 32468 KB Output is correct
19 Correct 1477 ms 32544 KB Output is correct
20 Correct 1465 ms 32456 KB Output is correct
21 Correct 1750 ms 32540 KB Output is correct
22 Correct 1873 ms 31496 KB Output is correct
23 Correct 1619 ms 32536 KB Output is correct
24 Correct 1433 ms 33088 KB Output is correct
25 Correct 1433 ms 33364 KB Output is correct
26 Correct 1433 ms 33360 KB Output is correct
27 Correct 1792 ms 32912 KB Output is correct
28 Correct 2145 ms 32544 KB Output is correct
29 Correct 2072 ms 32468 KB Output is correct
30 Correct 2087 ms 32536 KB Output is correct
31 Correct 2103 ms 32552 KB Output is correct
32 Correct 1823 ms 31824 KB Output is correct
33 Correct 1957 ms 41176 KB Output is correct
34 Correct 149 ms 31820 KB Output is correct
35 Correct 2165 ms 41852 KB Output is correct
36 Correct 1901 ms 41012 KB Output is correct
37 Correct 2074 ms 41444 KB Output is correct
38 Correct 1965 ms 41280 KB Output is correct
39 Correct 1626 ms 41104 KB Output is correct
40 Correct 1769 ms 47396 KB Output is correct
41 Correct 1994 ms 41680 KB Output is correct
42 Correct 1935 ms 42004 KB Output is correct
43 Correct 2191 ms 44316 KB Output is correct
44 Correct 2033 ms 41428 KB Output is correct
45 Correct 1695 ms 42400 KB Output is correct
46 Correct 1701 ms 41872 KB Output is correct
47 Correct 2122 ms 41044 KB Output is correct
48 Correct 2078 ms 40924 KB Output is correct
49 Correct 2066 ms 41120 KB Output is correct
50 Correct 2080 ms 40976 KB Output is correct
51 Correct 1885 ms 47084 KB Output is correct
52 Correct 1882 ms 46996 KB Output is correct