Submission #1025196

# Submission time Handle Problem Language Result Execution time Memory
1025196 2024-07-16T17:20:07 Z mansur Digital Circuit (IOI22_circuit) C++17
100 / 100
836 ms 82332 KB
#include "circuit.h"
#include <bits/stdc++.h>

using namespace std;

#define rall(s) s.rbegin(), s.rend()
#define all(s) s.begin(), s.end()
#define sz(s) (int) s.size()
#define s second 
#define f first 

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int N = 1e6, mod = 1000002022;

int n, m, is = 1;
vector<int> g[N], a(N);

vector<ll> pr(N), sf(N), val(N), gvl(N);

void calc(int u) {
    for (int to: g[u]) {
        calc(to);
    }
    int M = sz(g[u]);
    if (!M) {
        val[u] = 1;
        return;
    }
    for (int i = 0; i < M; i++) {
        if (i) pr[i] = pr[i - 1];
        else pr[i] = 1;
        pr[i] = (pr[i] * val[g[u][i]]) % mod;
    }
    for (int i = M - 1; i >= 0; i--) {
        if (i < M - 1) sf[i] = sf[i + 1];
        else sf[i] = 1;
        sf[i] = (sf[i] * val[g[u][i]]) % mod; 
    }
    for (int i = 0; i < M; i++) {
        gvl[g[u][i]] = ((i ? pr[i - 1] : 1ll) * (i < M - 1 ? sf[i + 1] : 1ll)) % mod;
    }
    val[u] = (pr[M - 1] * M) % mod;
}

ll vl[N];

void dfs(int u, int x) {
    int M = sz(g[u]);
    if (!M) {
        vl[u - n] = x;
        return;
    }
    for (int to: g[u]) {
        dfs(to, (x * gvl[to]) % mod);
    }
}

pll t[4 * N];
int swp[4 * N];

void bld(int u = 1, int tl = 0, int tr = m - 1) {
    if (tl == tr) {
        if (a[tl]) t[u].f = vl[tl];
        else t[u].s = vl[tl];
        return;
    }
    int mid = (tl + tr) / 2;
    bld(u * 2, tl, mid);
    bld(u * 2 + 1, mid + 1, tr);
    t[u].f = (t[u * 2].f + t[u  * 2 + 1].f) % mod;
    t[u].s = (t[u * 2].s + t[u  * 2 + 1].s) % mod;
}

void push(int u, int tl, int tr) {
    if (!swp[u]) return;
    swap(t[u].f, t[u].s);
    if (tl < tr) {
        swp[u * 2] ^= 1;
        swp[u * 2 + 1] ^= 1;
    }
    swp[u] = 0;
}

void upd(int l, int r, int u = 1, int tl = 0, int tr = m - 1) {
    push(u, tl, tr);
    if (tl > r || tr < l) return;
    if (tl >= l && tr <= r) {
        swp[u] = 1;
        push(u, tl, tr);
        return;
    }
    int mid = (tl + tr) / 2;
    upd(l, r, u * 2, tl, mid);
    upd(l, r, u * 2 + 1, mid + 1, tr);    
    t[u].f = (t[u * 2].f + t[u  * 2 + 1].f) % mod;
    t[u].s = (t[u * 2].s + t[u  * 2 + 1].s) % mod;
}


void init(int nn, int M, vector<int> P, vector<int> A) {
    n = nn, m = M;
    for (int i = 0; i < m; i++) a[i] = A[i];
    for (int i = 1; i < n + m; i++) g[P[i]].push_back(i);
    calc(0), dfs(0, 1), bld();
}

int count_ways(int l, int r) {
    upd(l - n, r - n);
    return t[1].f;
}
# Verdict Execution time Memory Grader output
1 Correct 12 ms 64856 KB Output is correct
2 Correct 13 ms 64856 KB Output is correct
3 Correct 12 ms 64952 KB Output is correct
4 Correct 12 ms 64856 KB Output is correct
5 Correct 11 ms 64960 KB Output is correct
6 Correct 10 ms 64856 KB Output is correct
7 Correct 11 ms 64856 KB Output is correct
8 Correct 11 ms 64856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 64852 KB Output is correct
2 Correct 13 ms 64856 KB Output is correct
3 Correct 12 ms 64856 KB Output is correct
4 Correct 12 ms 64856 KB Output is correct
5 Correct 12 ms 64856 KB Output is correct
6 Correct 12 ms 65112 KB Output is correct
7 Correct 11 ms 64892 KB Output is correct
8 Correct 11 ms 65112 KB Output is correct
9 Correct 11 ms 65112 KB Output is correct
10 Correct 10 ms 65196 KB Output is correct
11 Correct 11 ms 65112 KB Output is correct
12 Correct 11 ms 65020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 64856 KB Output is correct
2 Correct 13 ms 64856 KB Output is correct
3 Correct 12 ms 64952 KB Output is correct
4 Correct 12 ms 64856 KB Output is correct
5 Correct 11 ms 64960 KB Output is correct
6 Correct 10 ms 64856 KB Output is correct
7 Correct 11 ms 64856 KB Output is correct
8 Correct 11 ms 64856 KB Output is correct
9 Correct 14 ms 64852 KB Output is correct
10 Correct 13 ms 64856 KB Output is correct
11 Correct 12 ms 64856 KB Output is correct
12 Correct 12 ms 64856 KB Output is correct
13 Correct 12 ms 64856 KB Output is correct
14 Correct 12 ms 65112 KB Output is correct
15 Correct 11 ms 64892 KB Output is correct
16 Correct 11 ms 65112 KB Output is correct
17 Correct 11 ms 65112 KB Output is correct
18 Correct 10 ms 65196 KB Output is correct
19 Correct 11 ms 65112 KB Output is correct
20 Correct 11 ms 65020 KB Output is correct
21 Correct 11 ms 65112 KB Output is correct
22 Correct 11 ms 65112 KB Output is correct
23 Correct 10 ms 64904 KB Output is correct
24 Correct 11 ms 65112 KB Output is correct
25 Correct 11 ms 65112 KB Output is correct
26 Correct 14 ms 65076 KB Output is correct
27 Correct 11 ms 64912 KB Output is correct
28 Correct 11 ms 64980 KB Output is correct
29 Correct 10 ms 64956 KB Output is correct
30 Correct 11 ms 64980 KB Output is correct
31 Correct 11 ms 64964 KB Output is correct
32 Correct 11 ms 65112 KB Output is correct
33 Correct 11 ms 65112 KB Output is correct
34 Correct 10 ms 64856 KB Output is correct
35 Correct 11 ms 64856 KB Output is correct
36 Correct 11 ms 65112 KB Output is correct
37 Correct 11 ms 65112 KB Output is correct
38 Correct 11 ms 65112 KB Output is correct
39 Correct 11 ms 65112 KB Output is correct
40 Correct 11 ms 65112 KB Output is correct
41 Correct 12 ms 65112 KB Output is correct
42 Correct 12 ms 64948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 477 ms 68696 KB Output is correct
2 Correct 715 ms 70488 KB Output is correct
3 Correct 651 ms 70488 KB Output is correct
4 Correct 649 ms 70700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 477 ms 68696 KB Output is correct
2 Correct 715 ms 70488 KB Output is correct
3 Correct 651 ms 70488 KB Output is correct
4 Correct 649 ms 70700 KB Output is correct
5 Correct 604 ms 70760 KB Output is correct
6 Correct 743 ms 72164 KB Output is correct
7 Correct 785 ms 70480 KB Output is correct
8 Correct 718 ms 70488 KB Output is correct
9 Correct 332 ms 65364 KB Output is correct
10 Correct 697 ms 65312 KB Output is correct
11 Correct 717 ms 65312 KB Output is correct
12 Correct 684 ms 65292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 64852 KB Output is correct
2 Correct 13 ms 64856 KB Output is correct
3 Correct 12 ms 64856 KB Output is correct
4 Correct 12 ms 64856 KB Output is correct
5 Correct 12 ms 64856 KB Output is correct
6 Correct 12 ms 65112 KB Output is correct
7 Correct 11 ms 64892 KB Output is correct
8 Correct 11 ms 65112 KB Output is correct
9 Correct 11 ms 65112 KB Output is correct
10 Correct 10 ms 65196 KB Output is correct
11 Correct 11 ms 65112 KB Output is correct
12 Correct 11 ms 65020 KB Output is correct
13 Correct 477 ms 68696 KB Output is correct
14 Correct 715 ms 70488 KB Output is correct
15 Correct 651 ms 70488 KB Output is correct
16 Correct 649 ms 70700 KB Output is correct
17 Correct 604 ms 70760 KB Output is correct
18 Correct 743 ms 72164 KB Output is correct
19 Correct 785 ms 70480 KB Output is correct
20 Correct 718 ms 70488 KB Output is correct
21 Correct 332 ms 65364 KB Output is correct
22 Correct 697 ms 65312 KB Output is correct
23 Correct 717 ms 65312 KB Output is correct
24 Correct 684 ms 65292 KB Output is correct
25 Correct 736 ms 75612 KB Output is correct
26 Correct 743 ms 74644 KB Output is correct
27 Correct 740 ms 74728 KB Output is correct
28 Correct 564 ms 74464 KB Output is correct
29 Correct 829 ms 80756 KB Output is correct
30 Correct 720 ms 80972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 64856 KB Output is correct
2 Correct 13 ms 64856 KB Output is correct
3 Correct 12 ms 64952 KB Output is correct
4 Correct 12 ms 64856 KB Output is correct
5 Correct 11 ms 64960 KB Output is correct
6 Correct 10 ms 64856 KB Output is correct
7 Correct 11 ms 64856 KB Output is correct
8 Correct 11 ms 64856 KB Output is correct
9 Correct 14 ms 64852 KB Output is correct
10 Correct 13 ms 64856 KB Output is correct
11 Correct 12 ms 64856 KB Output is correct
12 Correct 12 ms 64856 KB Output is correct
13 Correct 12 ms 64856 KB Output is correct
14 Correct 12 ms 65112 KB Output is correct
15 Correct 11 ms 64892 KB Output is correct
16 Correct 11 ms 65112 KB Output is correct
17 Correct 11 ms 65112 KB Output is correct
18 Correct 10 ms 65196 KB Output is correct
19 Correct 11 ms 65112 KB Output is correct
20 Correct 11 ms 65020 KB Output is correct
21 Correct 11 ms 65112 KB Output is correct
22 Correct 11 ms 65112 KB Output is correct
23 Correct 10 ms 64904 KB Output is correct
24 Correct 11 ms 65112 KB Output is correct
25 Correct 11 ms 65112 KB Output is correct
26 Correct 14 ms 65076 KB Output is correct
27 Correct 11 ms 64912 KB Output is correct
28 Correct 11 ms 64980 KB Output is correct
29 Correct 10 ms 64956 KB Output is correct
30 Correct 11 ms 64980 KB Output is correct
31 Correct 11 ms 64964 KB Output is correct
32 Correct 11 ms 65112 KB Output is correct
33 Correct 11 ms 65112 KB Output is correct
34 Correct 10 ms 64856 KB Output is correct
35 Correct 11 ms 64856 KB Output is correct
36 Correct 11 ms 65112 KB Output is correct
37 Correct 11 ms 65112 KB Output is correct
38 Correct 11 ms 65112 KB Output is correct
39 Correct 11 ms 65112 KB Output is correct
40 Correct 11 ms 65112 KB Output is correct
41 Correct 12 ms 65112 KB Output is correct
42 Correct 12 ms 64948 KB Output is correct
43 Correct 487 ms 65256 KB Output is correct
44 Correct 755 ms 65280 KB Output is correct
45 Correct 674 ms 65260 KB Output is correct
46 Correct 701 ms 65388 KB Output is correct
47 Correct 722 ms 65404 KB Output is correct
48 Correct 662 ms 65404 KB Output is correct
49 Correct 702 ms 65400 KB Output is correct
50 Correct 719 ms 65368 KB Output is correct
51 Correct 667 ms 65200 KB Output is correct
52 Correct 770 ms 65248 KB Output is correct
53 Correct 635 ms 65552 KB Output is correct
54 Correct 667 ms 65388 KB Output is correct
55 Correct 684 ms 65300 KB Output is correct
56 Correct 660 ms 65276 KB Output is correct
57 Correct 593 ms 65224 KB Output is correct
58 Correct 648 ms 65704 KB Output is correct
59 Correct 643 ms 65752 KB Output is correct
60 Correct 568 ms 65712 KB Output is correct
61 Correct 652 ms 65368 KB Output is correct
62 Correct 630 ms 65228 KB Output is correct
63 Correct 608 ms 65200 KB Output is correct
64 Correct 549 ms 65232 KB Output is correct
65 Correct 237 ms 65176 KB Output is correct
66 Correct 592 ms 65308 KB Output is correct
67 Correct 677 ms 65312 KB Output is correct
68 Correct 621 ms 65292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 64856 KB Output is correct
2 Correct 13 ms 64856 KB Output is correct
3 Correct 12 ms 64952 KB Output is correct
4 Correct 12 ms 64856 KB Output is correct
5 Correct 11 ms 64960 KB Output is correct
6 Correct 10 ms 64856 KB Output is correct
7 Correct 11 ms 64856 KB Output is correct
8 Correct 11 ms 64856 KB Output is correct
9 Correct 14 ms 64852 KB Output is correct
10 Correct 13 ms 64856 KB Output is correct
11 Correct 12 ms 64856 KB Output is correct
12 Correct 12 ms 64856 KB Output is correct
13 Correct 12 ms 64856 KB Output is correct
14 Correct 12 ms 65112 KB Output is correct
15 Correct 11 ms 64892 KB Output is correct
16 Correct 11 ms 65112 KB Output is correct
17 Correct 11 ms 65112 KB Output is correct
18 Correct 10 ms 65196 KB Output is correct
19 Correct 11 ms 65112 KB Output is correct
20 Correct 11 ms 65020 KB Output is correct
21 Correct 11 ms 65112 KB Output is correct
22 Correct 11 ms 65112 KB Output is correct
23 Correct 10 ms 64904 KB Output is correct
24 Correct 11 ms 65112 KB Output is correct
25 Correct 11 ms 65112 KB Output is correct
26 Correct 14 ms 65076 KB Output is correct
27 Correct 11 ms 64912 KB Output is correct
28 Correct 11 ms 64980 KB Output is correct
29 Correct 10 ms 64956 KB Output is correct
30 Correct 11 ms 64980 KB Output is correct
31 Correct 11 ms 64964 KB Output is correct
32 Correct 11 ms 65112 KB Output is correct
33 Correct 11 ms 65112 KB Output is correct
34 Correct 10 ms 64856 KB Output is correct
35 Correct 11 ms 64856 KB Output is correct
36 Correct 11 ms 65112 KB Output is correct
37 Correct 11 ms 65112 KB Output is correct
38 Correct 11 ms 65112 KB Output is correct
39 Correct 11 ms 65112 KB Output is correct
40 Correct 11 ms 65112 KB Output is correct
41 Correct 12 ms 65112 KB Output is correct
42 Correct 12 ms 64948 KB Output is correct
43 Correct 477 ms 68696 KB Output is correct
44 Correct 715 ms 70488 KB Output is correct
45 Correct 651 ms 70488 KB Output is correct
46 Correct 649 ms 70700 KB Output is correct
47 Correct 604 ms 70760 KB Output is correct
48 Correct 743 ms 72164 KB Output is correct
49 Correct 785 ms 70480 KB Output is correct
50 Correct 718 ms 70488 KB Output is correct
51 Correct 332 ms 65364 KB Output is correct
52 Correct 697 ms 65312 KB Output is correct
53 Correct 717 ms 65312 KB Output is correct
54 Correct 684 ms 65292 KB Output is correct
55 Correct 736 ms 75612 KB Output is correct
56 Correct 743 ms 74644 KB Output is correct
57 Correct 740 ms 74728 KB Output is correct
58 Correct 564 ms 74464 KB Output is correct
59 Correct 829 ms 80756 KB Output is correct
60 Correct 720 ms 80972 KB Output is correct
61 Correct 487 ms 65256 KB Output is correct
62 Correct 755 ms 65280 KB Output is correct
63 Correct 674 ms 65260 KB Output is correct
64 Correct 701 ms 65388 KB Output is correct
65 Correct 722 ms 65404 KB Output is correct
66 Correct 662 ms 65404 KB Output is correct
67 Correct 702 ms 65400 KB Output is correct
68 Correct 719 ms 65368 KB Output is correct
69 Correct 667 ms 65200 KB Output is correct
70 Correct 770 ms 65248 KB Output is correct
71 Correct 635 ms 65552 KB Output is correct
72 Correct 667 ms 65388 KB Output is correct
73 Correct 684 ms 65300 KB Output is correct
74 Correct 660 ms 65276 KB Output is correct
75 Correct 593 ms 65224 KB Output is correct
76 Correct 648 ms 65704 KB Output is correct
77 Correct 643 ms 65752 KB Output is correct
78 Correct 568 ms 65712 KB Output is correct
79 Correct 652 ms 65368 KB Output is correct
80 Correct 630 ms 65228 KB Output is correct
81 Correct 608 ms 65200 KB Output is correct
82 Correct 549 ms 65232 KB Output is correct
83 Correct 237 ms 65176 KB Output is correct
84 Correct 592 ms 65308 KB Output is correct
85 Correct 677 ms 65312 KB Output is correct
86 Correct 621 ms 65292 KB Output is correct
87 Correct 16 ms 64852 KB Output is correct
88 Correct 492 ms 74204 KB Output is correct
89 Correct 776 ms 70784 KB Output is correct
90 Correct 724 ms 72180 KB Output is correct
91 Correct 818 ms 74576 KB Output is correct
92 Correct 776 ms 74616 KB Output is correct
93 Correct 827 ms 74664 KB Output is correct
94 Correct 760 ms 74692 KB Output is correct
95 Correct 635 ms 75656 KB Output is correct
96 Correct 658 ms 71120 KB Output is correct
97 Correct 711 ms 71496 KB Output is correct
98 Correct 584 ms 75016 KB Output is correct
99 Correct 773 ms 74664 KB Output is correct
100 Correct 787 ms 72740 KB Output is correct
101 Correct 771 ms 72364 KB Output is correct
102 Correct 715 ms 71464 KB Output is correct
103 Correct 836 ms 80824 KB Output is correct
104 Correct 830 ms 81276 KB Output is correct
105 Correct 738 ms 82332 KB Output is correct
106 Correct 687 ms 72152 KB Output is correct
107 Correct 733 ms 72676 KB Output is correct
108 Correct 755 ms 73168 KB Output is correct
109 Correct 806 ms 71552 KB Output is correct