Submission #820244

# Submission time Handle Problem Language Result Execution time Memory
820244 2023-08-11T02:05:39 Z maeola Digital Circuit (IOI22_circuit) C++17
100 / 100
961 ms 36204 KB
#include "circuit.h"

#include <bits/stdc++.h>

using ll = long long;

using namespace std;

constexpr int mod = 1e9 + 2022;

vector<int> adj[200005];
int choices[200005], coef[200005], *C;
int N, M;

struct ST
{
        int pool[800005], total[800005];
        int lazy[800005];

        void build(int i, int l, int r)
        {
                if (l == r)
                {
                        total[i] = C[l];
                        return;
                }
                int m = (l + r) / 2;
                build(i << 1, l, m);
                build(i << 1 | 1, m + 1, r);
                total[i] = (total[i << 1] + total[i << 1 | 1]) % mod;
        }

        void clean(int i)
        {
                if (lazy[i])
                {
                        pool[i] = (total[i] - pool[i] + mod) % mod;
                        lazy[i << 1] ^= 1;
                        lazy[i << 1 | 1] ^= 1;
                        lazy[i] = 0;
                }
        }

        void flip(int i, int l, int r, int ql, int qr)
        {
                clean(i);
                if (qr < l or ql > r)
                        return;
                if (ql <= l and qr >= r)
                {
                        lazy[i] = 1;
                        clean(i);
                        return;
                }
                int m = (l + r) / 2;
                flip(i << 1, l, m, ql, qr);
                flip(i << 1 | 1, m + 1, r, ql, qr);
                pool[i] = (pool[i << 1] + pool[i << 1 | 1]) % mod;
        }
} st;

void dfs1(int i)
{
        if (i >= N)
                return choices[i] = 1, void();
        choices[i] = adj[i].size();
        for (int j : adj[i])
        {
                dfs1(j);
                choices[i] = 1ll * choices[i] * choices[j] % mod;
        }
}

void dfs2(int i, int x)
{
        if (i >= N)
        {
                coef[i] = x;
                return;
        }
        int n = adj[i].size();
        vector<int> l(n), r(n);
        for (int j = 0; j < n; j++)
        {
                int w = adj[i][j];
                l[j] = r[j] = choices[w];
                if (j)
                        l[j] = 1ll * l[j] * l[j - 1] % mod;
        }
        for (int j = n - 2; j >= 0; j--)
                r[j] = 1ll * r[j] * r[j + 1] % mod;
        for (int j = 0; j < n; j++)
        {
                ll q = 1ll * x * (j ? l[j - 1] : 1) % mod;
                dfs2(adj[i][j], q * (j != n - 1 ? r[j + 1] : 1) % mod);
        }
}

void init(int N_, int M_, vector<int> P, vector<int> A)
{
        N = N_, M = M_;
        for (int i = 1; i < N + M; i++)
                adj[P[i]].push_back(i);
        dfs1(0);
        dfs2(0, 1);
        C = coef + N;

        st.build(1, 0, M - 1);
        for (int i = 0; i < M; i++)
                if (A[i])
                        st.flip(1, 0, M - 1, i, i);
}

int count_ways(int L, int R)
{
        L -= N, R -= N;
        st.flip(1, 0, M - 1, L, R);
        return st.pool[1];
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 2 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 2 ms 5072 KB Output is correct
6 Correct 2 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 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 3 ms 5060 KB Output is correct
4 Correct 2 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 5072 KB Output is correct
10 Correct 3 ms 5200 KB Output is correct
11 Correct 3 ms 5328 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 2 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 2 ms 5072 KB Output is correct
6 Correct 2 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 2 ms 4944 KB Output is correct
10 Correct 2 ms 4944 KB Output is correct
11 Correct 3 ms 5060 KB Output is correct
12 Correct 2 ms 5072 KB Output is correct
13 Correct 3 ms 5072 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 3 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 5328 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 2 ms 5072 KB Output is correct
22 Correct 3 ms 5072 KB Output is correct
23 Correct 3 ms 5072 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 3 ms 5072 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Correct 3 ms 5072 KB Output is correct
29 Correct 2 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 2 ms 5072 KB Output is correct
35 Correct 2 ms 5072 KB Output is correct
36 Correct 3 ms 5328 KB Output is correct
37 Correct 3 ms 5328 KB Output is correct
38 Correct 2 ms 5328 KB Output is correct
39 Correct 4 ms 5072 KB Output is correct
40 Correct 2 ms 5072 KB Output is correct
41 Correct 3 ms 5072 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 519 ms 8144 KB Output is correct
2 Correct 786 ms 11152 KB Output is correct
3 Correct 813 ms 11080 KB Output is correct
4 Correct 777 ms 10424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 519 ms 8144 KB Output is correct
2 Correct 786 ms 11152 KB Output is correct
3 Correct 813 ms 11080 KB Output is correct
4 Correct 777 ms 10424 KB Output is correct
5 Correct 688 ms 8092 KB Output is correct
6 Correct 961 ms 11080 KB Output is correct
7 Correct 723 ms 11124 KB Output is correct
8 Correct 779 ms 11140 KB Output is correct
9 Correct 302 ms 5200 KB Output is correct
10 Correct 625 ms 5328 KB Output is correct
11 Correct 682 ms 5328 KB Output is correct
12 Correct 669 ms 5376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 3 ms 5060 KB Output is correct
4 Correct 2 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 5072 KB Output is correct
10 Correct 3 ms 5200 KB Output is correct
11 Correct 3 ms 5328 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 519 ms 8144 KB Output is correct
14 Correct 786 ms 11152 KB Output is correct
15 Correct 813 ms 11080 KB Output is correct
16 Correct 777 ms 10424 KB Output is correct
17 Correct 688 ms 8092 KB Output is correct
18 Correct 961 ms 11080 KB Output is correct
19 Correct 723 ms 11124 KB Output is correct
20 Correct 779 ms 11140 KB Output is correct
21 Correct 302 ms 5200 KB Output is correct
22 Correct 625 ms 5328 KB Output is correct
23 Correct 682 ms 5328 KB Output is correct
24 Correct 669 ms 5376 KB Output is correct
25 Correct 859 ms 15364 KB Output is correct
26 Correct 717 ms 15448 KB Output is correct
27 Correct 687 ms 15484 KB Output is correct
28 Correct 681 ms 15520 KB Output is correct
29 Correct 815 ms 35836 KB Output is correct
30 Correct 646 ms 35828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 2 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 2 ms 5072 KB Output is correct
6 Correct 2 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 2 ms 4944 KB Output is correct
10 Correct 2 ms 4944 KB Output is correct
11 Correct 3 ms 5060 KB Output is correct
12 Correct 2 ms 5072 KB Output is correct
13 Correct 3 ms 5072 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 3 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 5328 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 2 ms 5072 KB Output is correct
22 Correct 3 ms 5072 KB Output is correct
23 Correct 3 ms 5072 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 3 ms 5072 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Correct 3 ms 5072 KB Output is correct
29 Correct 2 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 2 ms 5072 KB Output is correct
35 Correct 2 ms 5072 KB Output is correct
36 Correct 3 ms 5328 KB Output is correct
37 Correct 3 ms 5328 KB Output is correct
38 Correct 2 ms 5328 KB Output is correct
39 Correct 4 ms 5072 KB Output is correct
40 Correct 2 ms 5072 KB Output is correct
41 Correct 3 ms 5072 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
43 Correct 507 ms 5348 KB Output is correct
44 Correct 470 ms 5328 KB Output is correct
45 Correct 894 ms 5288 KB Output is correct
46 Correct 785 ms 5584 KB Output is correct
47 Correct 676 ms 5584 KB Output is correct
48 Correct 740 ms 5584 KB Output is correct
49 Correct 617 ms 5524 KB Output is correct
50 Correct 682 ms 5580 KB Output is correct
51 Correct 506 ms 5456 KB Output is correct
52 Correct 738 ms 5456 KB Output is correct
53 Correct 682 ms 6224 KB Output is correct
54 Correct 783 ms 5584 KB Output is correct
55 Correct 541 ms 5456 KB Output is correct
56 Correct 601 ms 5584 KB Output is correct
57 Correct 722 ms 5328 KB Output is correct
58 Correct 732 ms 6608 KB Output is correct
59 Correct 579 ms 6632 KB Output is correct
60 Correct 659 ms 6608 KB Output is correct
61 Correct 668 ms 5584 KB Output is correct
62 Correct 661 ms 5328 KB Output is correct
63 Correct 650 ms 5200 KB Output is correct
64 Correct 674 ms 5456 KB Output is correct
65 Correct 262 ms 5200 KB Output is correct
66 Correct 750 ms 5328 KB Output is correct
67 Correct 746 ms 5328 KB Output is correct
68 Correct 763 ms 5412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 2 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 2 ms 5072 KB Output is correct
6 Correct 2 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 2 ms 4944 KB Output is correct
10 Correct 2 ms 4944 KB Output is correct
11 Correct 3 ms 5060 KB Output is correct
12 Correct 2 ms 5072 KB Output is correct
13 Correct 3 ms 5072 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 3 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 5328 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 2 ms 5072 KB Output is correct
22 Correct 3 ms 5072 KB Output is correct
23 Correct 3 ms 5072 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 3 ms 5072 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Correct 3 ms 5072 KB Output is correct
29 Correct 2 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 2 ms 5072 KB Output is correct
35 Correct 2 ms 5072 KB Output is correct
36 Correct 3 ms 5328 KB Output is correct
37 Correct 3 ms 5328 KB Output is correct
38 Correct 2 ms 5328 KB Output is correct
39 Correct 4 ms 5072 KB Output is correct
40 Correct 2 ms 5072 KB Output is correct
41 Correct 3 ms 5072 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
43 Correct 519 ms 8144 KB Output is correct
44 Correct 786 ms 11152 KB Output is correct
45 Correct 813 ms 11080 KB Output is correct
46 Correct 777 ms 10424 KB Output is correct
47 Correct 688 ms 8092 KB Output is correct
48 Correct 961 ms 11080 KB Output is correct
49 Correct 723 ms 11124 KB Output is correct
50 Correct 779 ms 11140 KB Output is correct
51 Correct 302 ms 5200 KB Output is correct
52 Correct 625 ms 5328 KB Output is correct
53 Correct 682 ms 5328 KB Output is correct
54 Correct 669 ms 5376 KB Output is correct
55 Correct 859 ms 15364 KB Output is correct
56 Correct 717 ms 15448 KB Output is correct
57 Correct 687 ms 15484 KB Output is correct
58 Correct 681 ms 15520 KB Output is correct
59 Correct 815 ms 35836 KB Output is correct
60 Correct 646 ms 35828 KB Output is correct
61 Correct 507 ms 5348 KB Output is correct
62 Correct 470 ms 5328 KB Output is correct
63 Correct 894 ms 5288 KB Output is correct
64 Correct 785 ms 5584 KB Output is correct
65 Correct 676 ms 5584 KB Output is correct
66 Correct 740 ms 5584 KB Output is correct
67 Correct 617 ms 5524 KB Output is correct
68 Correct 682 ms 5580 KB Output is correct
69 Correct 506 ms 5456 KB Output is correct
70 Correct 738 ms 5456 KB Output is correct
71 Correct 682 ms 6224 KB Output is correct
72 Correct 783 ms 5584 KB Output is correct
73 Correct 541 ms 5456 KB Output is correct
74 Correct 601 ms 5584 KB Output is correct
75 Correct 722 ms 5328 KB Output is correct
76 Correct 732 ms 6608 KB Output is correct
77 Correct 579 ms 6632 KB Output is correct
78 Correct 659 ms 6608 KB Output is correct
79 Correct 668 ms 5584 KB Output is correct
80 Correct 661 ms 5328 KB Output is correct
81 Correct 650 ms 5200 KB Output is correct
82 Correct 674 ms 5456 KB Output is correct
83 Correct 262 ms 5200 KB Output is correct
84 Correct 750 ms 5328 KB Output is correct
85 Correct 746 ms 5328 KB Output is correct
86 Correct 763 ms 5412 KB Output is correct
87 Correct 2 ms 4944 KB Output is correct
88 Correct 511 ms 14968 KB Output is correct
89 Correct 758 ms 11456 KB Output is correct
90 Correct 768 ms 11232 KB Output is correct
91 Correct 750 ms 15616 KB Output is correct
92 Correct 862 ms 15512 KB Output is correct
93 Correct 728 ms 14720 KB Output is correct
94 Correct 929 ms 15604 KB Output is correct
95 Correct 853 ms 15512 KB Output is correct
96 Correct 684 ms 11700 KB Output is correct
97 Correct 750 ms 11732 KB Output is correct
98 Correct 735 ms 29776 KB Output is correct
99 Correct 753 ms 15512 KB Output is correct
100 Correct 721 ms 13296 KB Output is correct
101 Correct 845 ms 12748 KB Output is correct
102 Correct 790 ms 11684 KB Output is correct
103 Correct 772 ms 35872 KB Output is correct
104 Correct 693 ms 36200 KB Output is correct
105 Correct 781 ms 36204 KB Output is correct
106 Correct 716 ms 15612 KB Output is correct
107 Correct 754 ms 12104 KB Output is correct
108 Correct 806 ms 12044 KB Output is correct
109 Correct 822 ms 11772 KB Output is correct