Submission #820239

# Submission time Handle Problem Language Result Execution time Memory
820239 2023-08-11T02:01:16 Z maeola Digital Circuit (IOI22_circuit) C++17
46 / 100
808 ms 11080 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[200005], total[200005];
        int lazy[200005];

        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);
        st.clean(1);
        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 2 ms 5072 KB Output is correct
5 Correct 2 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 2 ms 5072 KB Output is correct
8 Correct 2 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 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 5088 KB Output is correct
9 Correct 2 ms 5072 KB Output is correct
10 Correct 3 ms 5328 KB Output is correct
11 Correct 4 ms 5324 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 2 ms 5072 KB Output is correct
5 Correct 2 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 2 ms 5072 KB Output is correct
8 Correct 2 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 2 ms 5072 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 5088 KB Output is correct
17 Correct 2 ms 5072 KB Output is correct
18 Correct 3 ms 5328 KB Output is correct
19 Correct 4 ms 5324 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 2 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 3 ms 5072 KB Output is correct
30 Correct 3 ms 5072 KB Output is correct
31 Correct 2 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 2 ms 5072 KB Output is correct
36 Correct 3 ms 5200 KB Output is correct
37 Correct 3 ms 5348 KB Output is correct
38 Correct 3 ms 5328 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 2 ms 5072 KB Output is correct
41 Correct 3 ms 5084 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 533 ms 8096 KB Output is correct
2 Incorrect 712 ms 11080 KB 3rd lines differ - on the 1st token, expected: '913758140', found: '943578984'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 533 ms 8096 KB Output is correct
2 Incorrect 712 ms 11080 KB 3rd lines differ - on the 1st token, expected: '913758140', found: '943578984'
3 Halted 0 ms 0 KB -
# 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 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 5088 KB Output is correct
9 Correct 2 ms 5072 KB Output is correct
10 Correct 3 ms 5328 KB Output is correct
11 Correct 4 ms 5324 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 533 ms 8096 KB Output is correct
14 Incorrect 712 ms 11080 KB 3rd lines differ - on the 1st token, expected: '913758140', found: '943578984'
15 Halted 0 ms 0 KB -
# 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 2 ms 5072 KB Output is correct
5 Correct 2 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 2 ms 5072 KB Output is correct
8 Correct 2 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 2 ms 5072 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 5088 KB Output is correct
17 Correct 2 ms 5072 KB Output is correct
18 Correct 3 ms 5328 KB Output is correct
19 Correct 4 ms 5324 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 2 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 3 ms 5072 KB Output is correct
30 Correct 3 ms 5072 KB Output is correct
31 Correct 2 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 2 ms 5072 KB Output is correct
36 Correct 3 ms 5200 KB Output is correct
37 Correct 3 ms 5348 KB Output is correct
38 Correct 3 ms 5328 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 2 ms 5072 KB Output is correct
41 Correct 3 ms 5084 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
43 Correct 469 ms 5328 KB Output is correct
44 Correct 724 ms 5328 KB Output is correct
45 Correct 663 ms 5328 KB Output is correct
46 Correct 653 ms 5584 KB Output is correct
47 Correct 720 ms 5584 KB Output is correct
48 Correct 535 ms 5584 KB Output is correct
49 Correct 698 ms 5584 KB Output is correct
50 Correct 764 ms 5584 KB Output is correct
51 Correct 710 ms 5456 KB Output is correct
52 Correct 651 ms 5456 KB Output is correct
53 Correct 645 ms 6224 KB Output is correct
54 Correct 722 ms 5616 KB Output is correct
55 Correct 720 ms 5456 KB Output is correct
56 Correct 669 ms 5456 KB Output is correct
57 Correct 680 ms 5328 KB Output is correct
58 Correct 633 ms 6608 KB Output is correct
59 Correct 661 ms 6608 KB Output is correct
60 Correct 670 ms 6608 KB Output is correct
61 Correct 646 ms 5584 KB Output is correct
62 Correct 677 ms 5296 KB Output is correct
63 Correct 656 ms 5200 KB Output is correct
64 Correct 808 ms 5456 KB Output is correct
65 Correct 326 ms 5200 KB Output is correct
66 Correct 739 ms 5328 KB Output is correct
67 Correct 612 ms 5328 KB Output is correct
68 Correct 689 ms 5328 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 2 ms 5072 KB Output is correct
5 Correct 2 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 2 ms 5072 KB Output is correct
8 Correct 2 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 2 ms 5072 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 5088 KB Output is correct
17 Correct 2 ms 5072 KB Output is correct
18 Correct 3 ms 5328 KB Output is correct
19 Correct 4 ms 5324 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 2 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 3 ms 5072 KB Output is correct
30 Correct 3 ms 5072 KB Output is correct
31 Correct 2 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 2 ms 5072 KB Output is correct
36 Correct 3 ms 5200 KB Output is correct
37 Correct 3 ms 5348 KB Output is correct
38 Correct 3 ms 5328 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 2 ms 5072 KB Output is correct
41 Correct 3 ms 5084 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
43 Correct 533 ms 8096 KB Output is correct
44 Incorrect 712 ms 11080 KB 3rd lines differ - on the 1st token, expected: '913758140', found: '943578984'
45 Halted 0 ms 0 KB -