Submission #628925

# Submission time Handle Problem Language Result Execution time Memory
628925 2022-08-13T20:33:02 Z imeimi2000 Digital Circuit (IOI22_circuit) C++17
100 / 100
1112 ms 29588 KB
#include "circuit.h"

#include <bits/stdc++.h>

using namespace std;

const int mod = 1000002022;
int n, m;
vector<int> E[200005];
int S[200005], C[200005];

void dfs1(int x) {
    S[x] = max(1, int(E[x].size()));
    for (int i : E[x]) {
        dfs1(i);
        S[x] = 1ll * S[x] * S[i] % mod;
    }
}

void dfs2(int x) {
    // printf("S[%d] = %d, C[%d] = %d\n", x, S[x], x, C[x]);
    vector<int> R(E[x].size());
    R.push_back(1);
    for (int i = E[x].size(); i--; ) {
        R[i] = 1ll * R[i + 1] * S[E[x][i]] % mod;
    }
    int L = 1;
    for (int i = 0; i < int(E[x].size()); ++i) {
        C[E[x][i]] = 1ll * L * R[i + 1] % mod * C[x] % mod;
        dfs2(E[x][i]);
        L = 1ll * L * S[E[x][i]] % mod;
    }
}

int add(int x, int y) {
    x += y;
    if (x >= mod) return x - mod;
    return x;
}

vector<int> A;
int seg[1 << 18], rev[1 << 18], lz[1 << 18];

void init(int i, int s, int e) {
    if (s == e) {
        seg[i] = 0;
        rev[i] = C[s];
        lz[i] = 0;
        if (A[s - n]) swap(seg[i], rev[i]);
        return;
    }
    int m = (s + e) / 2;
    init(i + i, s, m);
    init(i + i + 1, m + 1, e);
    seg[i] = add(seg[i + i], seg[i + i + 1]);
    rev[i] = add(rev[i + i], rev[i + i + 1]);
    lz[i] = 0;
}

void update(int i, int s, int e, int x, int y) {
    if (e < x || y < s) return;
    if (x <= s && e <= y) {
        swap(seg[i], rev[i]);
        lz[i] ^= 1;
        return;
    }
    int m = (s + e) / 2;
    if (lz[i]) {
        lz[i] = 0;
        swap(seg[i + i], rev[i + i]);
        lz[i + i] ^= 1;
        swap(seg[i + i + 1], rev[i + i + 1]);
        lz[i + i + 1] ^= 1;
    }
    update(i + i, s, m, x, y);
    update(i + i + 1, m + 1, e, x, y);
    seg[i] = add(seg[i + i], seg[i + i + 1]);
    rev[i] = add(rev[i + i], rev[i + i + 1]);
}

void init(int N, int M, vector<int> P, vector<int> A) {
    n = N;
    m = M;
    for (int i = 1; i < n + m; ++i) E[P[i]].push_back(i);
    dfs1(0);
    C[0] = 1;
    dfs2(0);
    ::A = A;
    init(1, n, n + m - 1);
}

int count_ways(int L, int R) {
    update(1, n, n + m - 1, L, R);
    return seg[1];
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 4988 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 4 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 4 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 3 ms 5072 KB Output is correct
10 Correct 3 ms 5200 KB Output is correct
11 Correct 3 ms 5200 KB Output is correct
12 Correct 4 ms 5072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 4988 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 3 ms 4944 KB Output is correct
11 Correct 3 ms 5072 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 4 ms 5072 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 4 ms 5072 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 3 ms 5200 KB Output is correct
19 Correct 3 ms 5200 KB Output is correct
20 Correct 4 ms 5072 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 4 ms 5072 KB Output is correct
23 Correct 4 ms 5072 KB Output is correct
24 Correct 3 ms 5200 KB Output is correct
25 Correct 3 ms 5072 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 4 ms 5124 KB Output is correct
28 Correct 3 ms 5072 KB Output is correct
29 Correct 3 ms 5072 KB Output is correct
30 Correct 3 ms 5072 KB Output is correct
31 Correct 3 ms 5200 KB Output is correct
32 Correct 3 ms 5072 KB Output is correct
33 Correct 3 ms 5072 KB Output is correct
34 Correct 3 ms 5072 KB Output is correct
35 Correct 3 ms 5072 KB Output is correct
36 Correct 3 ms 5200 KB Output is correct
37 Correct 3 ms 5200 KB Output is correct
38 Correct 3 ms 5200 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 3 ms 5072 KB Output is correct
41 Correct 3 ms 5024 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 686 ms 8136 KB Output is correct
2 Correct 905 ms 11336 KB Output is correct
3 Correct 830 ms 11396 KB Output is correct
4 Correct 796 ms 11336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 686 ms 8136 KB Output is correct
2 Correct 905 ms 11336 KB Output is correct
3 Correct 830 ms 11396 KB Output is correct
4 Correct 796 ms 11336 KB Output is correct
5 Correct 687 ms 8216 KB Output is correct
6 Correct 861 ms 11400 KB Output is correct
7 Correct 1112 ms 11400 KB Output is correct
8 Correct 937 ms 11392 KB Output is correct
9 Correct 506 ms 5200 KB Output is correct
10 Correct 816 ms 5328 KB Output is correct
11 Correct 963 ms 5328 KB Output is correct
12 Correct 811 ms 5416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 4 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 4 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 3 ms 5072 KB Output is correct
10 Correct 3 ms 5200 KB Output is correct
11 Correct 3 ms 5200 KB Output is correct
12 Correct 4 ms 5072 KB Output is correct
13 Correct 686 ms 8136 KB Output is correct
14 Correct 905 ms 11336 KB Output is correct
15 Correct 830 ms 11396 KB Output is correct
16 Correct 796 ms 11336 KB Output is correct
17 Correct 687 ms 8216 KB Output is correct
18 Correct 861 ms 11400 KB Output is correct
19 Correct 1112 ms 11400 KB Output is correct
20 Correct 937 ms 11392 KB Output is correct
21 Correct 506 ms 5200 KB Output is correct
22 Correct 816 ms 5328 KB Output is correct
23 Correct 963 ms 5328 KB Output is correct
24 Correct 811 ms 5416 KB Output is correct
25 Correct 1087 ms 15372 KB Output is correct
26 Correct 1101 ms 15480 KB Output is correct
27 Correct 1074 ms 15572 KB Output is correct
28 Correct 995 ms 15504 KB Output is correct
29 Correct 1102 ms 29176 KB Output is correct
30 Correct 1051 ms 29148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 4988 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 3 ms 4944 KB Output is correct
11 Correct 3 ms 5072 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 4 ms 5072 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 4 ms 5072 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 3 ms 5200 KB Output is correct
19 Correct 3 ms 5200 KB Output is correct
20 Correct 4 ms 5072 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 4 ms 5072 KB Output is correct
23 Correct 4 ms 5072 KB Output is correct
24 Correct 3 ms 5200 KB Output is correct
25 Correct 3 ms 5072 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 4 ms 5124 KB Output is correct
28 Correct 3 ms 5072 KB Output is correct
29 Correct 3 ms 5072 KB Output is correct
30 Correct 3 ms 5072 KB Output is correct
31 Correct 3 ms 5200 KB Output is correct
32 Correct 3 ms 5072 KB Output is correct
33 Correct 3 ms 5072 KB Output is correct
34 Correct 3 ms 5072 KB Output is correct
35 Correct 3 ms 5072 KB Output is correct
36 Correct 3 ms 5200 KB Output is correct
37 Correct 3 ms 5200 KB Output is correct
38 Correct 3 ms 5200 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 3 ms 5072 KB Output is correct
41 Correct 3 ms 5024 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
43 Correct 641 ms 5312 KB Output is correct
44 Correct 879 ms 5368 KB Output is correct
45 Correct 964 ms 5280 KB Output is correct
46 Correct 687 ms 5584 KB Output is correct
47 Correct 818 ms 5584 KB Output is correct
48 Correct 933 ms 5584 KB Output is correct
49 Correct 692 ms 5584 KB Output is correct
50 Correct 842 ms 5584 KB Output is correct
51 Correct 781 ms 5328 KB Output is correct
52 Correct 759 ms 5328 KB Output is correct
53 Correct 1014 ms 5840 KB Output is correct
54 Correct 698 ms 5584 KB Output is correct
55 Correct 832 ms 5456 KB Output is correct
56 Correct 909 ms 5328 KB Output is correct
57 Correct 667 ms 5328 KB Output is correct
58 Correct 807 ms 6224 KB Output is correct
59 Correct 923 ms 6224 KB Output is correct
60 Correct 713 ms 6252 KB Output is correct
61 Correct 684 ms 5456 KB Output is correct
62 Correct 990 ms 5200 KB Output is correct
63 Correct 865 ms 5200 KB Output is correct
64 Correct 916 ms 5328 KB Output is correct
65 Correct 352 ms 5200 KB Output is correct
66 Correct 968 ms 5312 KB Output is correct
67 Correct 965 ms 5388 KB Output is correct
68 Correct 878 ms 5328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 4988 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 3 ms 4944 KB Output is correct
11 Correct 3 ms 5072 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 4 ms 5072 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 4 ms 5072 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 3 ms 5200 KB Output is correct
19 Correct 3 ms 5200 KB Output is correct
20 Correct 4 ms 5072 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 4 ms 5072 KB Output is correct
23 Correct 4 ms 5072 KB Output is correct
24 Correct 3 ms 5200 KB Output is correct
25 Correct 3 ms 5072 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 4 ms 5124 KB Output is correct
28 Correct 3 ms 5072 KB Output is correct
29 Correct 3 ms 5072 KB Output is correct
30 Correct 3 ms 5072 KB Output is correct
31 Correct 3 ms 5200 KB Output is correct
32 Correct 3 ms 5072 KB Output is correct
33 Correct 3 ms 5072 KB Output is correct
34 Correct 3 ms 5072 KB Output is correct
35 Correct 3 ms 5072 KB Output is correct
36 Correct 3 ms 5200 KB Output is correct
37 Correct 3 ms 5200 KB Output is correct
38 Correct 3 ms 5200 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 3 ms 5072 KB Output is correct
41 Correct 3 ms 5024 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
43 Correct 686 ms 8136 KB Output is correct
44 Correct 905 ms 11336 KB Output is correct
45 Correct 830 ms 11396 KB Output is correct
46 Correct 796 ms 11336 KB Output is correct
47 Correct 687 ms 8216 KB Output is correct
48 Correct 861 ms 11400 KB Output is correct
49 Correct 1112 ms 11400 KB Output is correct
50 Correct 937 ms 11392 KB Output is correct
51 Correct 506 ms 5200 KB Output is correct
52 Correct 816 ms 5328 KB Output is correct
53 Correct 963 ms 5328 KB Output is correct
54 Correct 811 ms 5416 KB Output is correct
55 Correct 1087 ms 15372 KB Output is correct
56 Correct 1101 ms 15480 KB Output is correct
57 Correct 1074 ms 15572 KB Output is correct
58 Correct 995 ms 15504 KB Output is correct
59 Correct 1102 ms 29176 KB Output is correct
60 Correct 1051 ms 29148 KB Output is correct
61 Correct 641 ms 5312 KB Output is correct
62 Correct 879 ms 5368 KB Output is correct
63 Correct 964 ms 5280 KB Output is correct
64 Correct 687 ms 5584 KB Output is correct
65 Correct 818 ms 5584 KB Output is correct
66 Correct 933 ms 5584 KB Output is correct
67 Correct 692 ms 5584 KB Output is correct
68 Correct 842 ms 5584 KB Output is correct
69 Correct 781 ms 5328 KB Output is correct
70 Correct 759 ms 5328 KB Output is correct
71 Correct 1014 ms 5840 KB Output is correct
72 Correct 698 ms 5584 KB Output is correct
73 Correct 832 ms 5456 KB Output is correct
74 Correct 909 ms 5328 KB Output is correct
75 Correct 667 ms 5328 KB Output is correct
76 Correct 807 ms 6224 KB Output is correct
77 Correct 923 ms 6224 KB Output is correct
78 Correct 713 ms 6252 KB Output is correct
79 Correct 684 ms 5456 KB Output is correct
80 Correct 990 ms 5200 KB Output is correct
81 Correct 865 ms 5200 KB Output is correct
82 Correct 916 ms 5328 KB Output is correct
83 Correct 352 ms 5200 KB Output is correct
84 Correct 968 ms 5312 KB Output is correct
85 Correct 965 ms 5388 KB Output is correct
86 Correct 878 ms 5328 KB Output is correct
87 Correct 3 ms 4944 KB Output is correct
88 Correct 587 ms 14848 KB Output is correct
89 Correct 672 ms 11592 KB Output is correct
90 Correct 951 ms 11200 KB Output is correct
91 Correct 911 ms 15604 KB Output is correct
92 Correct 1004 ms 15612 KB Output is correct
93 Correct 957 ms 15620 KB Output is correct
94 Correct 1000 ms 15524 KB Output is correct
95 Correct 974 ms 15656 KB Output is correct
96 Correct 687 ms 11164 KB Output is correct
97 Correct 1027 ms 11184 KB Output is correct
98 Correct 737 ms 23760 KB Output is correct
99 Correct 1064 ms 15432 KB Output is correct
100 Correct 1006 ms 13148 KB Output is correct
101 Correct 634 ms 12488 KB Output is correct
102 Correct 869 ms 11216 KB Output is correct
103 Correct 1026 ms 29136 KB Output is correct
104 Correct 1026 ms 29496 KB Output is correct
105 Correct 837 ms 29588 KB Output is correct
106 Correct 844 ms 14172 KB Output is correct
107 Correct 905 ms 11848 KB Output is correct
108 Correct 906 ms 11720 KB Output is correct
109 Correct 1014 ms 11396 KB Output is correct