Submission #413593

# Submission time Handle Problem Language Result Execution time Memory
413593 2021-05-29T03:27:14 Z timmyfeng Werewolf (IOI18_werewolf) C++17
100 / 100
912 ms 114480 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 200000, L = __lg(N) + 1;

struct segtree {
    segtree *left, *right;
    int maxi;

    segtree(int l, int r) {
        maxi = 0;
        if (l < r) {
            int m = (l + r) / 2;
            left = new segtree(l, m);
            right = new segtree(m + 1, r);
        }
    }

    void update(int a, int x, int l, int r) {
        if (l == r) {
            maxi = x;
        } else {
            int m = (l + r) / 2;
            if (a <= m) {
                left->update(a, x, l, m);
            } else {
                right->update(a, x, m + 1, r);
            }
            maxi = max(left->maxi, right->maxi);
        }
    }

    int query(int a, int b, int l, int r) {
        if (b < l || r < a) {
            return INT_MIN;
        } else if (a <= l && r <= b) {
            return maxi;
        } else {
            int m = (l + r) / 2;
            return max(
                left->query(a, b, l, m),
                right->query(a, b, m + 1, r)
            );
        }
    }
};

int in_l[N], out_l[N], par_l[L][N], in_r[N], out_r[N], par_r[L][N], t;
vector<int> tree_l[N], tree_r[N];

int dsu[N];

int find(int u) {
    if (dsu[u] == -1) {
        return u;
    }
    dsu[u] = find(dsu[u]);
    return dsu[u];
}

void dfs(int u, vector<int> *adj, int *in, int *out, int *par) {
    in[u] = ++t;
    for (auto c : adj[u]) {
        par[c] = u;
        dfs(c, adj, in, out, par);
    }
    out[u] = t;
}

vector<int> check_validity(int n, vector<int> x, vector<int> y, vector<int> s, vector<int> e, vector<int> l, vector<int> r) {
    int m = x.size();
    vector<vector<int>> adj(n);
    for (int i = 0; i < m; ++i) {
        adj[x[i]].push_back(y[i]);
        adj[y[i]].push_back(x[i]);
    }

    fill(dsu, dsu + n, -1);
    for (int i = 0; i < n; ++i) {
        for (auto j : adj[i]) {
            if (j < i && find(j) != i) {
                tree_l[i].push_back(find(j));
                dsu[find(j)] = i;
            }
        }
    }
    par_l[0][n - 1] = n - 1;
    dfs(n - 1, tree_l, in_l, out_l, par_l[0]);

    fill(dsu, dsu + n, -1);
    for (int i = n - 1; i >= 0; --i) {
        for (auto j : adj[i]) {
            if (j > i && find(j) != i) {
                tree_r[i].push_back(find(j));
                dsu[find(j)] = i;
            }
        }
    }
    par_r[0][0] = 0;
    dfs(0, tree_r, in_r, out_r, par_r[0]);

    for (int i = 1; i <= __lg(n); ++i) {
        for (int j = 0; j < n; ++j) {
            par_l[i][j] = par_l[i - 1][par_l[i - 1][j]];
            par_r[i][j] = par_r[i - 1][par_r[i - 1][j]];
        }
    }

    int q = s.size();
    vector<array<int, 3>> queries;
    for (int i = 0; i < q; ++i) {
        for (int j = __lg(n); j >= 0; --j) {
            if (par_l[j][e[i]] <= r[i]) {
                e[i] = par_l[j][e[i]];
            }

            if (par_r[j][s[i]] >= l[i]) {
                s[i] = par_r[j][s[i]];
            }
        }
        queries.push_back({out_r[s[i]], 1, i});
    }

    for (int i = 0; i < n; ++i) {
        queries.push_back({in_r[i], 0, in_l[i]});
    }
    sort(queries.begin(), queries.end());

    vector<int> ans(q);
    segtree *maxi = new segtree(1, n);
    for (auto [a, b, c] : queries) {
        if (b == 0) {
            maxi->update(c, a, 1, n);
        } else {
            ans[c] = maxi->query(in_l[e[c]], out_l[e[c]], 1, n) >= in_r[s[c]];
        }
    }

    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 9804 KB Output is correct
2 Correct 8 ms 9828 KB Output is correct
3 Correct 7 ms 9804 KB Output is correct
4 Correct 7 ms 9712 KB Output is correct
5 Correct 7 ms 9804 KB Output is correct
6 Correct 7 ms 9780 KB Output is correct
7 Correct 7 ms 9804 KB Output is correct
8 Correct 7 ms 9804 KB Output is correct
9 Correct 7 ms 9804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 9804 KB Output is correct
2 Correct 8 ms 9828 KB Output is correct
3 Correct 7 ms 9804 KB Output is correct
4 Correct 7 ms 9712 KB Output is correct
5 Correct 7 ms 9804 KB Output is correct
6 Correct 7 ms 9780 KB Output is correct
7 Correct 7 ms 9804 KB Output is correct
8 Correct 7 ms 9804 KB Output is correct
9 Correct 7 ms 9804 KB Output is correct
10 Correct 16 ms 10996 KB Output is correct
11 Correct 13 ms 11048 KB Output is correct
12 Correct 13 ms 11024 KB Output is correct
13 Correct 14 ms 11188 KB Output is correct
14 Correct 13 ms 11212 KB Output is correct
15 Correct 14 ms 11116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 795 ms 96976 KB Output is correct
2 Correct 848 ms 102572 KB Output is correct
3 Correct 828 ms 98760 KB Output is correct
4 Correct 747 ms 97192 KB Output is correct
5 Correct 747 ms 97180 KB Output is correct
6 Correct 758 ms 97008 KB Output is correct
7 Correct 669 ms 96836 KB Output is correct
8 Correct 832 ms 102676 KB Output is correct
9 Correct 675 ms 98720 KB Output is correct
10 Correct 536 ms 97204 KB Output is correct
11 Correct 581 ms 97168 KB Output is correct
12 Correct 579 ms 96936 KB Output is correct
13 Correct 848 ms 108860 KB Output is correct
14 Correct 855 ms 108900 KB Output is correct
15 Correct 797 ms 108976 KB Output is correct
16 Correct 846 ms 108888 KB Output is correct
17 Correct 758 ms 96848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 9804 KB Output is correct
2 Correct 8 ms 9828 KB Output is correct
3 Correct 7 ms 9804 KB Output is correct
4 Correct 7 ms 9712 KB Output is correct
5 Correct 7 ms 9804 KB Output is correct
6 Correct 7 ms 9780 KB Output is correct
7 Correct 7 ms 9804 KB Output is correct
8 Correct 7 ms 9804 KB Output is correct
9 Correct 7 ms 9804 KB Output is correct
10 Correct 16 ms 10996 KB Output is correct
11 Correct 13 ms 11048 KB Output is correct
12 Correct 13 ms 11024 KB Output is correct
13 Correct 14 ms 11188 KB Output is correct
14 Correct 13 ms 11212 KB Output is correct
15 Correct 14 ms 11116 KB Output is correct
16 Correct 795 ms 96976 KB Output is correct
17 Correct 848 ms 102572 KB Output is correct
18 Correct 828 ms 98760 KB Output is correct
19 Correct 747 ms 97192 KB Output is correct
20 Correct 747 ms 97180 KB Output is correct
21 Correct 758 ms 97008 KB Output is correct
22 Correct 669 ms 96836 KB Output is correct
23 Correct 832 ms 102676 KB Output is correct
24 Correct 675 ms 98720 KB Output is correct
25 Correct 536 ms 97204 KB Output is correct
26 Correct 581 ms 97168 KB Output is correct
27 Correct 579 ms 96936 KB Output is correct
28 Correct 848 ms 108860 KB Output is correct
29 Correct 855 ms 108900 KB Output is correct
30 Correct 797 ms 108976 KB Output is correct
31 Correct 846 ms 108888 KB Output is correct
32 Correct 758 ms 96848 KB Output is correct
33 Correct 829 ms 97888 KB Output is correct
34 Correct 379 ms 43712 KB Output is correct
35 Correct 894 ms 101880 KB Output is correct
36 Correct 878 ms 97856 KB Output is correct
37 Correct 870 ms 100740 KB Output is correct
38 Correct 826 ms 98888 KB Output is correct
39 Correct 901 ms 113940 KB Output is correct
40 Correct 912 ms 109148 KB Output is correct
41 Correct 737 ms 100096 KB Output is correct
42 Correct 578 ms 97980 KB Output is correct
43 Correct 898 ms 108084 KB Output is correct
44 Correct 824 ms 100656 KB Output is correct
45 Correct 833 ms 114480 KB Output is correct
46 Correct 765 ms 114028 KB Output is correct
47 Correct 810 ms 109000 KB Output is correct
48 Correct 876 ms 108828 KB Output is correct
49 Correct 797 ms 109036 KB Output is correct
50 Correct 832 ms 108932 KB Output is correct
51 Correct 787 ms 109080 KB Output is correct
52 Correct 809 ms 109020 KB Output is correct