Submission #627401

# Submission time Handle Problem Language Result Execution time Memory
627401 2022-08-12T14:31:18 Z phathnv Digital Circuit (IOI22_circuit) C++17
100 / 100
1771 ms 34192 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 2e5 + 10;
const int MOD = 1e9 + 2022;

struct Segtree {
    int n;
    vector<array<int, 2>> a;
    vector<int> lazy;
    void init(int _n, const vector<array<int, 2>> &val) {
        n = _n;
        a.assign(4 * n + 1, {0, 0});
        lazy.assign(4 * n + 1, 0);
        build(1, 0, n - 1, val);
    }
    void build(int id, int l, int r, const vector<array<int, 2>> &val) {
        if (l == r) {
            a[id] = val[l];
            cerr << "build " << a[id][0] << ' ' << a[id][1] << endl;
            return;
        }
        int mid = (l + r) >> 1;
        build(id << 1, l, mid, val);
        build(id << 1 | 1, mid + 1, r, val);
        a[id][0] = (a[id << 1][0] + a[id << 1 | 1][0]) % MOD;
        a[id][1] = (a[id << 1][1] + a[id << 1 | 1][1]) % MOD;
    }
    void doLazy(int id, int l, int r) {
        if (lazy[id]) {
            swap(a[id][0], a[id][1]);
            if (l < r) {
                lazy[id << 1] ^= lazy[id];
                lazy[id << 1 | 1] ^= lazy[id];
            }
            lazy[id] = 0;
        }
    }
    void update(int id, int l, int r, int u, int v) {
        doLazy(id, l, r);
        if (v < l || r < u) {
            return;
        }
        if (u <= l && r <= v) {
            lazy[id] ^= 1;
            doLazy(id, l, r);
            return;
        }
        int mid = (l + r) >> 1;
        update(id << 1, l, mid, u, v);
        update(id << 1 | 1, mid + 1, r, u, v);
        a[id][0] = (a[id << 1][0] + a[id << 1 | 1][0]) % MOD;
        a[id][1] = (a[id << 1][1] + a[id << 1 | 1][1]) % MOD;
    }
    void update(int l, int r) {
        update(1, 0, n - 1, l, r);
    }
    void debug(int id, int l, int r) {
        doLazy(id, l, r);
        if (l == r) {
            return;
        }
        int mid = (l + r) >> 1;
        debug(id << 1, l, mid);
        debug(id << 1 | 1, mid + 1, r);
    }
    int get() {
        doLazy(1, 0, n - 1);
        return a[1][0];
    }
} ST;

int n, m, c[N], f[N];
vector<int> childs[N];

void dfs1(int u) {
    if (childs[u].empty()) {
        c[u] = 1;
        return;
    }
    c[u] = childs[u].size();
    for (int v : childs[u]) {
        dfs1(v);
        c[u] = 1ll * c[u] * c[v] % MOD;
    }
}

void dfs2(int u) {
    if (childs[u].empty()) {
        return;
    }
    int n = childs[u].size();
    vector<int> l(n), r(n);
    l[0] = 1;
    for (int i = 1; i < n; ++i) {
        l[i] = 1ll * l[i - 1] * c[childs[u][i - 1]] % MOD;
    }
    r[n - 1] = 1;
    for (int i = n - 2; i >= 0; --i) {
        r[i] = 1ll * r[i + 1] * c[childs[u][i + 1]] % MOD;
    }
    for (int i = 0; i < n; ++i) {
        int v = childs[u][i];
        f[v] = 1ll * l[i] * r[i] % MOD;
        dfs2(v);
    }
}

void dfs3(int u) {
    for (int v : childs[u]) {
        f[v] = 1ll * f[v] * f[u] % MOD;
        dfs3(v);
    }
}

void init(int _n, int _m, vector<int> p, vector<int> a) {
    n = _n;
    m = _m;
    for (int i = 1; i < m + n; ++i) {
        childs[p[i]].push_back(i);
    }

    dfs1(0);
    fill(f, f + N, 1);
    dfs2(0);
    dfs3(0);

    vector<array<int, 2>> val;
    for (int i = n; i < m + n; ++i) {
        if (a[i - n] == 1) {
            val.push_back({f[i], 0});
        } else {
            val.push_back({0, f[i]});
        }
    }

    ST.init(m, val);
}

int count_ways(int l, int r) {
    ST.update(l - n, r - n);
    return ST.get();
}

# Verdict Execution time Memory Grader output
1 Correct 5 ms 5712 KB Output is correct
2 Correct 5 ms 5788 KB Output is correct
3 Correct 9 ms 5840 KB Output is correct
4 Correct 9 ms 5884 KB Output is correct
5 Correct 9 ms 5840 KB Output is correct
6 Correct 10 ms 5840 KB Output is correct
7 Correct 9 ms 5872 KB Output is correct
8 Correct 9 ms 5872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5712 KB Output is correct
2 Correct 5 ms 5824 KB Output is correct
3 Correct 6 ms 5860 KB Output is correct
4 Correct 6 ms 5840 KB Output is correct
5 Correct 7 ms 5864 KB Output is correct
6 Correct 11 ms 5888 KB Output is correct
7 Correct 10 ms 5932 KB Output is correct
8 Correct 11 ms 5940 KB Output is correct
9 Correct 11 ms 5840 KB Output is correct
10 Correct 11 ms 6048 KB Output is correct
11 Correct 10 ms 5968 KB Output is correct
12 Correct 11 ms 5840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5712 KB Output is correct
2 Correct 5 ms 5788 KB Output is correct
3 Correct 9 ms 5840 KB Output is correct
4 Correct 9 ms 5884 KB Output is correct
5 Correct 9 ms 5840 KB Output is correct
6 Correct 10 ms 5840 KB Output is correct
7 Correct 9 ms 5872 KB Output is correct
8 Correct 9 ms 5872 KB Output is correct
9 Correct 4 ms 5712 KB Output is correct
10 Correct 5 ms 5824 KB Output is correct
11 Correct 6 ms 5860 KB Output is correct
12 Correct 6 ms 5840 KB Output is correct
13 Correct 7 ms 5864 KB Output is correct
14 Correct 11 ms 5888 KB Output is correct
15 Correct 10 ms 5932 KB Output is correct
16 Correct 11 ms 5940 KB Output is correct
17 Correct 11 ms 5840 KB Output is correct
18 Correct 11 ms 6048 KB Output is correct
19 Correct 10 ms 5968 KB Output is correct
20 Correct 11 ms 5840 KB Output is correct
21 Correct 11 ms 5964 KB Output is correct
22 Correct 9 ms 5840 KB Output is correct
23 Correct 8 ms 5840 KB Output is correct
24 Correct 14 ms 5840 KB Output is correct
25 Correct 12 ms 5840 KB Output is correct
26 Correct 11 ms 5920 KB Output is correct
27 Correct 10 ms 5840 KB Output is correct
28 Correct 10 ms 5840 KB Output is correct
29 Correct 9 ms 5880 KB Output is correct
30 Correct 10 ms 5840 KB Output is correct
31 Correct 3 ms 5968 KB Output is correct
32 Correct 10 ms 5840 KB Output is correct
33 Correct 10 ms 5840 KB Output is correct
34 Correct 11 ms 5840 KB Output is correct
35 Correct 8 ms 5880 KB Output is correct
36 Correct 10 ms 6048 KB Output is correct
37 Correct 9 ms 6060 KB Output is correct
38 Correct 9 ms 5968 KB Output is correct
39 Correct 9 ms 5888 KB Output is correct
40 Correct 9 ms 5896 KB Output is correct
41 Correct 10 ms 5880 KB Output is correct
42 Correct 9 ms 5840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 838 ms 10260 KB Output is correct
2 Correct 1221 ms 14720 KB Output is correct
3 Correct 1460 ms 14692 KB Output is correct
4 Correct 1356 ms 14720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 838 ms 10260 KB Output is correct
2 Correct 1221 ms 14720 KB Output is correct
3 Correct 1460 ms 14692 KB Output is correct
4 Correct 1356 ms 14720 KB Output is correct
5 Correct 1020 ms 10316 KB Output is correct
6 Correct 1371 ms 14788 KB Output is correct
7 Correct 1279 ms 14836 KB Output is correct
8 Correct 1150 ms 14652 KB Output is correct
9 Correct 452 ms 6068 KB Output is correct
10 Correct 974 ms 6372 KB Output is correct
11 Correct 906 ms 6372 KB Output is correct
12 Correct 925 ms 6368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5712 KB Output is correct
2 Correct 5 ms 5824 KB Output is correct
3 Correct 6 ms 5860 KB Output is correct
4 Correct 6 ms 5840 KB Output is correct
5 Correct 7 ms 5864 KB Output is correct
6 Correct 11 ms 5888 KB Output is correct
7 Correct 10 ms 5932 KB Output is correct
8 Correct 11 ms 5940 KB Output is correct
9 Correct 11 ms 5840 KB Output is correct
10 Correct 11 ms 6048 KB Output is correct
11 Correct 10 ms 5968 KB Output is correct
12 Correct 11 ms 5840 KB Output is correct
13 Correct 838 ms 10260 KB Output is correct
14 Correct 1221 ms 14720 KB Output is correct
15 Correct 1460 ms 14692 KB Output is correct
16 Correct 1356 ms 14720 KB Output is correct
17 Correct 1020 ms 10316 KB Output is correct
18 Correct 1371 ms 14788 KB Output is correct
19 Correct 1279 ms 14836 KB Output is correct
20 Correct 1150 ms 14652 KB Output is correct
21 Correct 452 ms 6068 KB Output is correct
22 Correct 974 ms 6372 KB Output is correct
23 Correct 906 ms 6372 KB Output is correct
24 Correct 925 ms 6368 KB Output is correct
25 Correct 1605 ms 19288 KB Output is correct
26 Correct 1771 ms 19388 KB Output is correct
27 Correct 1588 ms 19492 KB Output is correct
28 Correct 1337 ms 19484 KB Output is correct
29 Correct 1598 ms 34092 KB Output is correct
30 Correct 1329 ms 34192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5712 KB Output is correct
2 Correct 5 ms 5788 KB Output is correct
3 Correct 9 ms 5840 KB Output is correct
4 Correct 9 ms 5884 KB Output is correct
5 Correct 9 ms 5840 KB Output is correct
6 Correct 10 ms 5840 KB Output is correct
7 Correct 9 ms 5872 KB Output is correct
8 Correct 9 ms 5872 KB Output is correct
9 Correct 4 ms 5712 KB Output is correct
10 Correct 5 ms 5824 KB Output is correct
11 Correct 6 ms 5860 KB Output is correct
12 Correct 6 ms 5840 KB Output is correct
13 Correct 7 ms 5864 KB Output is correct
14 Correct 11 ms 5888 KB Output is correct
15 Correct 10 ms 5932 KB Output is correct
16 Correct 11 ms 5940 KB Output is correct
17 Correct 11 ms 5840 KB Output is correct
18 Correct 11 ms 6048 KB Output is correct
19 Correct 10 ms 5968 KB Output is correct
20 Correct 11 ms 5840 KB Output is correct
21 Correct 11 ms 5964 KB Output is correct
22 Correct 9 ms 5840 KB Output is correct
23 Correct 8 ms 5840 KB Output is correct
24 Correct 14 ms 5840 KB Output is correct
25 Correct 12 ms 5840 KB Output is correct
26 Correct 11 ms 5920 KB Output is correct
27 Correct 10 ms 5840 KB Output is correct
28 Correct 10 ms 5840 KB Output is correct
29 Correct 9 ms 5880 KB Output is correct
30 Correct 10 ms 5840 KB Output is correct
31 Correct 3 ms 5968 KB Output is correct
32 Correct 10 ms 5840 KB Output is correct
33 Correct 10 ms 5840 KB Output is correct
34 Correct 11 ms 5840 KB Output is correct
35 Correct 8 ms 5880 KB Output is correct
36 Correct 10 ms 6048 KB Output is correct
37 Correct 9 ms 6060 KB Output is correct
38 Correct 9 ms 5968 KB Output is correct
39 Correct 9 ms 5888 KB Output is correct
40 Correct 9 ms 5896 KB Output is correct
41 Correct 10 ms 5880 KB Output is correct
42 Correct 9 ms 5840 KB Output is correct
43 Correct 446 ms 6188 KB Output is correct
44 Correct 695 ms 6224 KB Output is correct
45 Correct 837 ms 6224 KB Output is correct
46 Correct 970 ms 6536 KB Output is correct
47 Correct 965 ms 6548 KB Output is correct
48 Correct 672 ms 6532 KB Output is correct
49 Correct 922 ms 6536 KB Output is correct
50 Correct 978 ms 6544 KB Output is correct
51 Correct 977 ms 6296 KB Output is correct
52 Correct 924 ms 6296 KB Output is correct
53 Correct 803 ms 6864 KB Output is correct
54 Correct 911 ms 6528 KB Output is correct
55 Correct 942 ms 6420 KB Output is correct
56 Correct 678 ms 6408 KB Output is correct
57 Correct 924 ms 6340 KB Output is correct
58 Correct 950 ms 7184 KB Output is correct
59 Correct 1317 ms 7120 KB Output is correct
60 Correct 989 ms 7156 KB Output is correct
61 Correct 830 ms 6356 KB Output is correct
62 Correct 1128 ms 6252 KB Output is correct
63 Correct 1022 ms 6216 KB Output is correct
64 Correct 1012 ms 6364 KB Output is correct
65 Correct 482 ms 6060 KB Output is correct
66 Correct 638 ms 6364 KB Output is correct
67 Correct 1004 ms 6440 KB Output is correct
68 Correct 792 ms 6368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5712 KB Output is correct
2 Correct 5 ms 5788 KB Output is correct
3 Correct 9 ms 5840 KB Output is correct
4 Correct 9 ms 5884 KB Output is correct
5 Correct 9 ms 5840 KB Output is correct
6 Correct 10 ms 5840 KB Output is correct
7 Correct 9 ms 5872 KB Output is correct
8 Correct 9 ms 5872 KB Output is correct
9 Correct 4 ms 5712 KB Output is correct
10 Correct 5 ms 5824 KB Output is correct
11 Correct 6 ms 5860 KB Output is correct
12 Correct 6 ms 5840 KB Output is correct
13 Correct 7 ms 5864 KB Output is correct
14 Correct 11 ms 5888 KB Output is correct
15 Correct 10 ms 5932 KB Output is correct
16 Correct 11 ms 5940 KB Output is correct
17 Correct 11 ms 5840 KB Output is correct
18 Correct 11 ms 6048 KB Output is correct
19 Correct 10 ms 5968 KB Output is correct
20 Correct 11 ms 5840 KB Output is correct
21 Correct 11 ms 5964 KB Output is correct
22 Correct 9 ms 5840 KB Output is correct
23 Correct 8 ms 5840 KB Output is correct
24 Correct 14 ms 5840 KB Output is correct
25 Correct 12 ms 5840 KB Output is correct
26 Correct 11 ms 5920 KB Output is correct
27 Correct 10 ms 5840 KB Output is correct
28 Correct 10 ms 5840 KB Output is correct
29 Correct 9 ms 5880 KB Output is correct
30 Correct 10 ms 5840 KB Output is correct
31 Correct 3 ms 5968 KB Output is correct
32 Correct 10 ms 5840 KB Output is correct
33 Correct 10 ms 5840 KB Output is correct
34 Correct 11 ms 5840 KB Output is correct
35 Correct 8 ms 5880 KB Output is correct
36 Correct 10 ms 6048 KB Output is correct
37 Correct 9 ms 6060 KB Output is correct
38 Correct 9 ms 5968 KB Output is correct
39 Correct 9 ms 5888 KB Output is correct
40 Correct 9 ms 5896 KB Output is correct
41 Correct 10 ms 5880 KB Output is correct
42 Correct 9 ms 5840 KB Output is correct
43 Correct 838 ms 10260 KB Output is correct
44 Correct 1221 ms 14720 KB Output is correct
45 Correct 1460 ms 14692 KB Output is correct
46 Correct 1356 ms 14720 KB Output is correct
47 Correct 1020 ms 10316 KB Output is correct
48 Correct 1371 ms 14788 KB Output is correct
49 Correct 1279 ms 14836 KB Output is correct
50 Correct 1150 ms 14652 KB Output is correct
51 Correct 452 ms 6068 KB Output is correct
52 Correct 974 ms 6372 KB Output is correct
53 Correct 906 ms 6372 KB Output is correct
54 Correct 925 ms 6368 KB Output is correct
55 Correct 1605 ms 19288 KB Output is correct
56 Correct 1771 ms 19388 KB Output is correct
57 Correct 1588 ms 19492 KB Output is correct
58 Correct 1337 ms 19484 KB Output is correct
59 Correct 1598 ms 34092 KB Output is correct
60 Correct 1329 ms 34192 KB Output is correct
61 Correct 446 ms 6188 KB Output is correct
62 Correct 695 ms 6224 KB Output is correct
63 Correct 837 ms 6224 KB Output is correct
64 Correct 970 ms 6536 KB Output is correct
65 Correct 965 ms 6548 KB Output is correct
66 Correct 672 ms 6532 KB Output is correct
67 Correct 922 ms 6536 KB Output is correct
68 Correct 978 ms 6544 KB Output is correct
69 Correct 977 ms 6296 KB Output is correct
70 Correct 924 ms 6296 KB Output is correct
71 Correct 803 ms 6864 KB Output is correct
72 Correct 911 ms 6528 KB Output is correct
73 Correct 942 ms 6420 KB Output is correct
74 Correct 678 ms 6408 KB Output is correct
75 Correct 924 ms 6340 KB Output is correct
76 Correct 950 ms 7184 KB Output is correct
77 Correct 1317 ms 7120 KB Output is correct
78 Correct 989 ms 7156 KB Output is correct
79 Correct 830 ms 6356 KB Output is correct
80 Correct 1128 ms 6252 KB Output is correct
81 Correct 1022 ms 6216 KB Output is correct
82 Correct 1012 ms 6364 KB Output is correct
83 Correct 482 ms 6060 KB Output is correct
84 Correct 638 ms 6364 KB Output is correct
85 Correct 1004 ms 6440 KB Output is correct
86 Correct 792 ms 6368 KB Output is correct
87 Correct 3 ms 5712 KB Output is correct
88 Correct 1074 ms 17536 KB Output is correct
89 Correct 1346 ms 13744 KB Output is correct
90 Correct 1250 ms 14016 KB Output is correct
91 Correct 1588 ms 19472 KB Output is correct
92 Correct 1663 ms 19556 KB Output is correct
93 Correct 1573 ms 19540 KB Output is correct
94 Correct 1597 ms 19540 KB Output is correct
95 Correct 1620 ms 19752 KB Output is correct
96 Correct 1533 ms 15152 KB Output is correct
97 Correct 1666 ms 15024 KB Output is correct
98 Correct 779 ms 28804 KB Output is correct
99 Correct 1485 ms 19452 KB Output is correct
100 Correct 1361 ms 17308 KB Output is correct
101 Correct 1558 ms 16748 KB Output is correct
102 Correct 1494 ms 15592 KB Output is correct
103 Correct 1614 ms 34172 KB Output is correct
104 Correct 1696 ms 33812 KB Output is correct
105 Correct 1615 ms 33784 KB Output is correct
106 Correct 1275 ms 16656 KB Output is correct
107 Correct 1314 ms 14028 KB Output is correct
108 Correct 1391 ms 14416 KB Output is correct
109 Correct 1526 ms 15752 KB Output is correct