Submission #922971

# Submission time Handle Problem Language Result Execution time Memory
922971 2024-02-06T11:23:12 Z thangdz2k7 Digital Circuit (IOI22_circuit) C++17
100 / 100
863 ms 46464 KB
#include <bits/stdc++.h>
#define pb push_back

using namespace std;

const int maxN = 2e5 + 5;
const int mod = 1000002022;

void add(int &a, int b){
    a += b;
    if (a >= mod) a -= mod;
    if (a < 0) a += mod;
}

vector <int> adj[maxN], pre[maxN], suf[maxN];
int val[maxN], sz[maxN], dp[maxN];

void dfs(int u){
    sz[u] = adj[u].size();
    dp[u] = max(sz[u], 1);
    for (int i = 0; i < sz[u]; ++ i){
        int v = adj[u][i];
        dfs(v);
        if (!i) pre[u].pb(dp[v]);
        else pre[u].pb(1ll * pre[u].back() * dp[v] % mod);
        suf[u].pb(0);
        dp[u] = 1ll * dp[u] * dp[v] % mod;
    }
    for (int i = sz[u] - 1; i >= 0; -- i){
        int v = adj[u][i];
        if (i == sz[u] - 1) suf[u][i] = dp[v];
        else suf[u][i] = 1ll * suf[u][i + 1] * dp[v] % mod;
    }
}

void get(int u){
    for (int i = 0; i < sz[u]; ++ i){
        int v = adj[u][i];
        val[v] = val[u];
        if (i > 0) val[v] = 1ll * val[v] * pre[u][i - 1] % mod;
        if (i < sz[u] - 1) val[v] = 1ll * val[v] * suf[u][i + 1] % mod;
        get(v);
    }
}

int sum[2][4 * maxN];
bool used[maxN], rev[4 * maxN];

void mer(int s){
    sum[0][s] = 0;
    sum[1][s] = 0;
    for (int i = 0; i <= 1; ++ i){
        for (int j = 2 * s; j <= 2 * s + 1; ++ j) add(sum[i][s], sum[i][j]);
    }
}

void build(int s, int l, int r, int n){
    rev[s] = 0;
    if (l == r){
        sum[0][s] = used[l] * val[l + n];
        sum[1][s] = (1 ^ used[l]) * val[l + n];
        return;
    }

    int mid = (l + r) / 2;
    build(2 * s, l, mid, n);
    build(2 * s + 1, mid + 1, r, n);
    mer(s);
}

int kk, gg;

void init(int N, int M, std::vector<int> P, std::vector<int> A){
    kk = N;
    gg = M;
    for (int i = 1; i < N + M; ++ i) adj[P[i]].pb(i);
    dfs(0);
    val[0] = 1;
    get(0);
    for (int i = 0; i < M; ++ i) used[i] = A[i];
    build(1, 0, M - 1, N);
}

void down(int s){
    if (!rev[s]) return;
    for (int i = 2 * s; i <= 2 * s + 1; ++ i) {
        rev[i] ^= 1;
        swap(sum[0][i], sum[1][i]);
    }
    rev[s] = 0;
}

void upd(int s, int l, int r, int u, int v){
    if (u <= l && r <= v){
        rev[s] ^= 1;
        swap(sum[0][s], sum[1][s]);
        return;
    }

    int mid = (l + r) / 2;
    down(s);
    if (mid >= u) upd(2 * s, l, mid, u, v);
    if (mid + 1 <= v) upd(2 * s + 1, mid + 1, r, u, v);
    mer(s);
}

int count_ways(int L, int R){
    upd(1, 0, gg - 1, L - kk, R - kk);
    return sum[0][1];
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 21848 KB Output is correct
2 Correct 5 ms 21848 KB Output is correct
3 Correct 7 ms 21856 KB Output is correct
4 Correct 5 ms 21848 KB Output is correct
5 Correct 5 ms 21848 KB Output is correct
6 Correct 6 ms 21848 KB Output is correct
7 Correct 5 ms 21848 KB Output is correct
8 Correct 6 ms 21848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 21848 KB Output is correct
2 Correct 5 ms 21848 KB Output is correct
3 Correct 5 ms 21848 KB Output is correct
4 Correct 6 ms 21848 KB Output is correct
5 Correct 5 ms 21848 KB Output is correct
6 Correct 5 ms 21848 KB Output is correct
7 Correct 6 ms 21860 KB Output is correct
8 Correct 6 ms 21848 KB Output is correct
9 Correct 5 ms 21848 KB Output is correct
10 Correct 6 ms 21848 KB Output is correct
11 Correct 5 ms 21848 KB Output is correct
12 Correct 6 ms 21848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 21848 KB Output is correct
2 Correct 5 ms 21848 KB Output is correct
3 Correct 7 ms 21856 KB Output is correct
4 Correct 5 ms 21848 KB Output is correct
5 Correct 5 ms 21848 KB Output is correct
6 Correct 6 ms 21848 KB Output is correct
7 Correct 5 ms 21848 KB Output is correct
8 Correct 6 ms 21848 KB Output is correct
9 Correct 5 ms 21848 KB Output is correct
10 Correct 5 ms 21848 KB Output is correct
11 Correct 5 ms 21848 KB Output is correct
12 Correct 6 ms 21848 KB Output is correct
13 Correct 5 ms 21848 KB Output is correct
14 Correct 5 ms 21848 KB Output is correct
15 Correct 6 ms 21860 KB Output is correct
16 Correct 6 ms 21848 KB Output is correct
17 Correct 5 ms 21848 KB Output is correct
18 Correct 6 ms 21848 KB Output is correct
19 Correct 5 ms 21848 KB Output is correct
20 Correct 6 ms 21848 KB Output is correct
21 Correct 7 ms 21848 KB Output is correct
22 Correct 5 ms 22100 KB Output is correct
23 Correct 6 ms 21848 KB Output is correct
24 Correct 6 ms 21960 KB Output is correct
25 Correct 6 ms 21924 KB Output is correct
26 Correct 6 ms 21848 KB Output is correct
27 Correct 7 ms 21848 KB Output is correct
28 Correct 5 ms 21860 KB Output is correct
29 Correct 5 ms 21848 KB Output is correct
30 Correct 6 ms 21900 KB Output is correct
31 Correct 6 ms 21940 KB Output is correct
32 Correct 6 ms 21848 KB Output is correct
33 Correct 6 ms 21848 KB Output is correct
34 Correct 6 ms 21848 KB Output is correct
35 Correct 6 ms 21848 KB Output is correct
36 Correct 6 ms 21936 KB Output is correct
37 Correct 6 ms 21940 KB Output is correct
38 Correct 7 ms 22104 KB Output is correct
39 Correct 6 ms 21880 KB Output is correct
40 Correct 7 ms 21848 KB Output is correct
41 Correct 6 ms 21848 KB Output is correct
42 Correct 6 ms 21848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 428 ms 27660 KB Output is correct
2 Correct 579 ms 31676 KB Output is correct
3 Correct 628 ms 31624 KB Output is correct
4 Correct 600 ms 31612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 428 ms 27660 KB Output is correct
2 Correct 579 ms 31676 KB Output is correct
3 Correct 628 ms 31624 KB Output is correct
4 Correct 600 ms 31612 KB Output is correct
5 Correct 531 ms 27652 KB Output is correct
6 Correct 602 ms 31604 KB Output is correct
7 Correct 669 ms 31596 KB Output is correct
8 Correct 600 ms 31568 KB Output is correct
9 Correct 294 ms 22104 KB Output is correct
10 Correct 613 ms 22360 KB Output is correct
11 Correct 598 ms 22360 KB Output is correct
12 Correct 573 ms 22360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 21848 KB Output is correct
2 Correct 5 ms 21848 KB Output is correct
3 Correct 5 ms 21848 KB Output is correct
4 Correct 6 ms 21848 KB Output is correct
5 Correct 5 ms 21848 KB Output is correct
6 Correct 5 ms 21848 KB Output is correct
7 Correct 6 ms 21860 KB Output is correct
8 Correct 6 ms 21848 KB Output is correct
9 Correct 5 ms 21848 KB Output is correct
10 Correct 6 ms 21848 KB Output is correct
11 Correct 5 ms 21848 KB Output is correct
12 Correct 6 ms 21848 KB Output is correct
13 Correct 428 ms 27660 KB Output is correct
14 Correct 579 ms 31676 KB Output is correct
15 Correct 628 ms 31624 KB Output is correct
16 Correct 600 ms 31612 KB Output is correct
17 Correct 531 ms 27652 KB Output is correct
18 Correct 602 ms 31604 KB Output is correct
19 Correct 669 ms 31596 KB Output is correct
20 Correct 600 ms 31568 KB Output is correct
21 Correct 294 ms 22104 KB Output is correct
22 Correct 613 ms 22360 KB Output is correct
23 Correct 598 ms 22360 KB Output is correct
24 Correct 573 ms 22360 KB Output is correct
25 Correct 751 ms 35456 KB Output is correct
26 Correct 727 ms 35844 KB Output is correct
27 Correct 763 ms 35848 KB Output is correct
28 Correct 596 ms 35808 KB Output is correct
29 Correct 835 ms 45056 KB Output is correct
30 Correct 716 ms 45064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 21848 KB Output is correct
2 Correct 5 ms 21848 KB Output is correct
3 Correct 7 ms 21856 KB Output is correct
4 Correct 5 ms 21848 KB Output is correct
5 Correct 5 ms 21848 KB Output is correct
6 Correct 6 ms 21848 KB Output is correct
7 Correct 5 ms 21848 KB Output is correct
8 Correct 6 ms 21848 KB Output is correct
9 Correct 5 ms 21848 KB Output is correct
10 Correct 5 ms 21848 KB Output is correct
11 Correct 5 ms 21848 KB Output is correct
12 Correct 6 ms 21848 KB Output is correct
13 Correct 5 ms 21848 KB Output is correct
14 Correct 5 ms 21848 KB Output is correct
15 Correct 6 ms 21860 KB Output is correct
16 Correct 6 ms 21848 KB Output is correct
17 Correct 5 ms 21848 KB Output is correct
18 Correct 6 ms 21848 KB Output is correct
19 Correct 5 ms 21848 KB Output is correct
20 Correct 6 ms 21848 KB Output is correct
21 Correct 7 ms 21848 KB Output is correct
22 Correct 5 ms 22100 KB Output is correct
23 Correct 6 ms 21848 KB Output is correct
24 Correct 6 ms 21960 KB Output is correct
25 Correct 6 ms 21924 KB Output is correct
26 Correct 6 ms 21848 KB Output is correct
27 Correct 7 ms 21848 KB Output is correct
28 Correct 5 ms 21860 KB Output is correct
29 Correct 5 ms 21848 KB Output is correct
30 Correct 6 ms 21900 KB Output is correct
31 Correct 6 ms 21940 KB Output is correct
32 Correct 6 ms 21848 KB Output is correct
33 Correct 6 ms 21848 KB Output is correct
34 Correct 6 ms 21848 KB Output is correct
35 Correct 6 ms 21848 KB Output is correct
36 Correct 6 ms 21936 KB Output is correct
37 Correct 6 ms 21940 KB Output is correct
38 Correct 7 ms 22104 KB Output is correct
39 Correct 6 ms 21880 KB Output is correct
40 Correct 7 ms 21848 KB Output is correct
41 Correct 6 ms 21848 KB Output is correct
42 Correct 6 ms 21848 KB Output is correct
43 Correct 468 ms 22104 KB Output is correct
44 Correct 675 ms 20312 KB Output is correct
45 Correct 690 ms 22104 KB Output is correct
46 Correct 651 ms 20312 KB Output is correct
47 Correct 645 ms 20472 KB Output is correct
48 Correct 688 ms 22360 KB Output is correct
49 Correct 692 ms 22360 KB Output is correct
50 Correct 643 ms 22360 KB Output is correct
51 Correct 631 ms 22072 KB Output is correct
52 Correct 706 ms 20092 KB Output is correct
53 Correct 625 ms 22872 KB Output is correct
54 Correct 665 ms 22360 KB Output is correct
55 Correct 658 ms 20056 KB Output is correct
56 Correct 655 ms 20056 KB Output is correct
57 Correct 696 ms 21848 KB Output is correct
58 Correct 684 ms 22872 KB Output is correct
59 Correct 686 ms 22872 KB Output is correct
60 Correct 631 ms 22872 KB Output is correct
61 Correct 655 ms 22360 KB Output is correct
62 Correct 690 ms 22104 KB Output is correct
63 Correct 695 ms 22104 KB Output is correct
64 Correct 713 ms 20056 KB Output is correct
65 Correct 327 ms 22356 KB Output is correct
66 Correct 650 ms 22372 KB Output is correct
67 Correct 694 ms 22360 KB Output is correct
68 Correct 655 ms 22360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 21848 KB Output is correct
2 Correct 5 ms 21848 KB Output is correct
3 Correct 7 ms 21856 KB Output is correct
4 Correct 5 ms 21848 KB Output is correct
5 Correct 5 ms 21848 KB Output is correct
6 Correct 6 ms 21848 KB Output is correct
7 Correct 5 ms 21848 KB Output is correct
8 Correct 6 ms 21848 KB Output is correct
9 Correct 5 ms 21848 KB Output is correct
10 Correct 5 ms 21848 KB Output is correct
11 Correct 5 ms 21848 KB Output is correct
12 Correct 6 ms 21848 KB Output is correct
13 Correct 5 ms 21848 KB Output is correct
14 Correct 5 ms 21848 KB Output is correct
15 Correct 6 ms 21860 KB Output is correct
16 Correct 6 ms 21848 KB Output is correct
17 Correct 5 ms 21848 KB Output is correct
18 Correct 6 ms 21848 KB Output is correct
19 Correct 5 ms 21848 KB Output is correct
20 Correct 6 ms 21848 KB Output is correct
21 Correct 7 ms 21848 KB Output is correct
22 Correct 5 ms 22100 KB Output is correct
23 Correct 6 ms 21848 KB Output is correct
24 Correct 6 ms 21960 KB Output is correct
25 Correct 6 ms 21924 KB Output is correct
26 Correct 6 ms 21848 KB Output is correct
27 Correct 7 ms 21848 KB Output is correct
28 Correct 5 ms 21860 KB Output is correct
29 Correct 5 ms 21848 KB Output is correct
30 Correct 6 ms 21900 KB Output is correct
31 Correct 6 ms 21940 KB Output is correct
32 Correct 6 ms 21848 KB Output is correct
33 Correct 6 ms 21848 KB Output is correct
34 Correct 6 ms 21848 KB Output is correct
35 Correct 6 ms 21848 KB Output is correct
36 Correct 6 ms 21936 KB Output is correct
37 Correct 6 ms 21940 KB Output is correct
38 Correct 7 ms 22104 KB Output is correct
39 Correct 6 ms 21880 KB Output is correct
40 Correct 7 ms 21848 KB Output is correct
41 Correct 6 ms 21848 KB Output is correct
42 Correct 6 ms 21848 KB Output is correct
43 Correct 428 ms 27660 KB Output is correct
44 Correct 579 ms 31676 KB Output is correct
45 Correct 628 ms 31624 KB Output is correct
46 Correct 600 ms 31612 KB Output is correct
47 Correct 531 ms 27652 KB Output is correct
48 Correct 602 ms 31604 KB Output is correct
49 Correct 669 ms 31596 KB Output is correct
50 Correct 600 ms 31568 KB Output is correct
51 Correct 294 ms 22104 KB Output is correct
52 Correct 613 ms 22360 KB Output is correct
53 Correct 598 ms 22360 KB Output is correct
54 Correct 573 ms 22360 KB Output is correct
55 Correct 751 ms 35456 KB Output is correct
56 Correct 727 ms 35844 KB Output is correct
57 Correct 763 ms 35848 KB Output is correct
58 Correct 596 ms 35808 KB Output is correct
59 Correct 835 ms 45056 KB Output is correct
60 Correct 716 ms 45064 KB Output is correct
61 Correct 468 ms 22104 KB Output is correct
62 Correct 675 ms 20312 KB Output is correct
63 Correct 690 ms 22104 KB Output is correct
64 Correct 651 ms 20312 KB Output is correct
65 Correct 645 ms 20472 KB Output is correct
66 Correct 688 ms 22360 KB Output is correct
67 Correct 692 ms 22360 KB Output is correct
68 Correct 643 ms 22360 KB Output is correct
69 Correct 631 ms 22072 KB Output is correct
70 Correct 706 ms 20092 KB Output is correct
71 Correct 625 ms 22872 KB Output is correct
72 Correct 665 ms 22360 KB Output is correct
73 Correct 658 ms 20056 KB Output is correct
74 Correct 655 ms 20056 KB Output is correct
75 Correct 696 ms 21848 KB Output is correct
76 Correct 684 ms 22872 KB Output is correct
77 Correct 686 ms 22872 KB Output is correct
78 Correct 631 ms 22872 KB Output is correct
79 Correct 655 ms 22360 KB Output is correct
80 Correct 690 ms 22104 KB Output is correct
81 Correct 695 ms 22104 KB Output is correct
82 Correct 713 ms 20056 KB Output is correct
83 Correct 327 ms 22356 KB Output is correct
84 Correct 650 ms 22372 KB Output is correct
85 Correct 694 ms 22360 KB Output is correct
86 Correct 655 ms 22360 KB Output is correct
87 Correct 5 ms 21848 KB Output is correct
88 Correct 511 ms 33376 KB Output is correct
89 Correct 786 ms 30764 KB Output is correct
90 Correct 792 ms 31672 KB Output is correct
91 Correct 785 ms 34308 KB Output is correct
92 Correct 849 ms 34204 KB Output is correct
93 Correct 858 ms 32936 KB Output is correct
94 Correct 847 ms 36108 KB Output is correct
95 Correct 756 ms 32264 KB Output is correct
96 Correct 666 ms 24064 KB Output is correct
97 Correct 751 ms 25352 KB Output is correct
98 Correct 605 ms 41224 KB Output is correct
99 Correct 863 ms 33804 KB Output is correct
100 Correct 812 ms 28752 KB Output is correct
101 Correct 786 ms 27612 KB Output is correct
102 Correct 773 ms 25196 KB Output is correct
103 Correct 812 ms 45072 KB Output is correct
104 Correct 786 ms 42416 KB Output is correct
105 Correct 739 ms 46464 KB Output is correct
106 Correct 791 ms 32736 KB Output is correct
107 Correct 753 ms 29216 KB Output is correct
108 Correct 758 ms 28492 KB Output is correct
109 Correct 779 ms 25484 KB Output is correct