Submission #630039

# Submission time Handle Problem Language Result Execution time Memory
630039 2022-08-15T14:52:36 Z qwerasdfzxcl Digital Circuit (IOI22_circuit) C++17
100 / 100
1238 ms 45344 KB
#include "circuit.h"
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int MOD = 1'000'002'022;
vector<int> adj[800800];
int n, m, a[800800];

struct Seg1{
    ll tree[800800], sz;
    void init(int n){
        sz = n;
        for (int i=sz;i<sz*2;i++) tree[i] = adj[i-sz].size();
        for (int i=sz-1;i;i--) tree[i] = tree[i<<1] * tree[i<<1|1] % MOD;
    }
    void update(int p, int x){
        for (tree[p+=sz]=x;p>1;p>>=1) tree[p>>1] = tree[p] * tree[p^1] % MOD;
    }
}tree1;

struct Seg2{
    pair<ll, ll> tree[800800];
    int lazy[800800];
    pair<ll, ll> combine(pair<ll, ll> x, pair<ll, ll> y){return {(x.first + y.first)%MOD, (x.second + y.second)%MOD};}
    void init(int i, int l, int r){
        lazy[i] = 0;
        if (l==r) {tree[i] = {0, a[l]}; return;}
        int m = (l+r)>>1;
        init(i<<1, l, m); init(i<<1|1, m+1, r);
        tree[i] = combine(tree[i<<1], tree[i<<1|1]);
    }
    void propagate(int i, int l, int r){
        if (!lazy[i]) return;
        swap(tree[i].first, tree[i].second);
        if (l!=r){
            lazy[i<<1] ^= 1;
            lazy[i<<1|1] ^= 1;
        }
        lazy[i] = 0;
    }
    void update(int i, int l, int r, int s, int e){
        propagate(i, l, r);
        if (r<s || e<l) return;
        if (s<=l && r<=e){
            lazy[i] ^= 1;
            propagate(i, l, r);
            return;
        }
        int m = (l+r)>>1;
        update(i<<1, l, m, s, e); update(i<<1|1, m+1, r, s, e);
        tree[i] = combine(tree[i<<1], tree[i<<1|1]);
    }
}tree2;

void dfs(int s){
    if (s<=n) tree1.update(s, 1);
    else a[s-n] = tree1.tree[1];

    for (auto &v:adj[s]) dfs(v);

    if (s<=n) tree1.update(s, adj[s].size());
}

void init(int N, int M, std::vector<int> P, std::vector<int> A) {
    adj[0].push_back(0);
    n = N, m = M;

    for (int i=1;i<n+m;i++){
        adj[P[i]+1].push_back(i+1);
    }

    tree1.init(n+1);
    dfs(1);
    tree2.init(1, 1, m);

    for (int i=0;i<m;i++) if (A[i]) tree2.update(1, 1, m, i+1, i+1);
}

int count_ways(int L, int R) {
    tree2.update(1, 1, m, L-n+1, R-n+1);
    return tree2.tree[1].first;
}
# Verdict Execution time Memory Grader output
1 Correct 15 ms 31568 KB Output is correct
2 Correct 14 ms 31636 KB Output is correct
3 Correct 14 ms 31696 KB Output is correct
4 Correct 14 ms 31636 KB Output is correct
5 Correct 15 ms 31624 KB Output is correct
6 Correct 15 ms 31672 KB Output is correct
7 Correct 15 ms 31696 KB Output is correct
8 Correct 19 ms 31696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 31556 KB Output is correct
2 Correct 16 ms 31568 KB Output is correct
3 Correct 17 ms 31688 KB Output is correct
4 Correct 15 ms 31696 KB Output is correct
5 Correct 15 ms 31668 KB Output is correct
6 Correct 14 ms 31696 KB Output is correct
7 Correct 21 ms 31716 KB Output is correct
8 Correct 15 ms 31716 KB Output is correct
9 Correct 16 ms 31648 KB Output is correct
10 Correct 17 ms 31696 KB Output is correct
11 Correct 16 ms 31696 KB Output is correct
12 Correct 17 ms 31660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 31568 KB Output is correct
2 Correct 14 ms 31636 KB Output is correct
3 Correct 14 ms 31696 KB Output is correct
4 Correct 14 ms 31636 KB Output is correct
5 Correct 15 ms 31624 KB Output is correct
6 Correct 15 ms 31672 KB Output is correct
7 Correct 15 ms 31696 KB Output is correct
8 Correct 19 ms 31696 KB Output is correct
9 Correct 17 ms 31556 KB Output is correct
10 Correct 16 ms 31568 KB Output is correct
11 Correct 17 ms 31688 KB Output is correct
12 Correct 15 ms 31696 KB Output is correct
13 Correct 15 ms 31668 KB Output is correct
14 Correct 14 ms 31696 KB Output is correct
15 Correct 21 ms 31716 KB Output is correct
16 Correct 15 ms 31716 KB Output is correct
17 Correct 16 ms 31648 KB Output is correct
18 Correct 17 ms 31696 KB Output is correct
19 Correct 16 ms 31696 KB Output is correct
20 Correct 17 ms 31660 KB Output is correct
21 Correct 17 ms 31696 KB Output is correct
22 Correct 20 ms 31696 KB Output is correct
23 Correct 16 ms 31696 KB Output is correct
24 Correct 18 ms 31688 KB Output is correct
25 Correct 18 ms 31632 KB Output is correct
26 Correct 17 ms 31696 KB Output is correct
27 Correct 18 ms 31748 KB Output is correct
28 Correct 16 ms 31696 KB Output is correct
29 Correct 19 ms 31616 KB Output is correct
30 Correct 16 ms 31668 KB Output is correct
31 Correct 15 ms 31760 KB Output is correct
32 Correct 20 ms 31688 KB Output is correct
33 Correct 16 ms 31712 KB Output is correct
34 Correct 16 ms 31652 KB Output is correct
35 Correct 19 ms 31632 KB Output is correct
36 Correct 17 ms 31704 KB Output is correct
37 Correct 19 ms 31728 KB Output is correct
38 Correct 16 ms 31804 KB Output is correct
39 Correct 16 ms 31644 KB Output is correct
40 Correct 16 ms 31592 KB Output is correct
41 Correct 18 ms 31616 KB Output is correct
42 Correct 17 ms 31620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 623 ms 34364 KB Output is correct
2 Correct 1102 ms 37012 KB Output is correct
3 Correct 931 ms 36936 KB Output is correct
4 Correct 980 ms 37032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 623 ms 34364 KB Output is correct
2 Correct 1102 ms 37012 KB Output is correct
3 Correct 931 ms 36936 KB Output is correct
4 Correct 980 ms 37032 KB Output is correct
5 Correct 725 ms 34344 KB Output is correct
6 Correct 996 ms 37032 KB Output is correct
7 Correct 1024 ms 36936 KB Output is correct
8 Correct 875 ms 37028 KB Output is correct
9 Correct 539 ms 31824 KB Output is correct
10 Correct 982 ms 31912 KB Output is correct
11 Correct 864 ms 31952 KB Output is correct
12 Correct 778 ms 31952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 31556 KB Output is correct
2 Correct 16 ms 31568 KB Output is correct
3 Correct 17 ms 31688 KB Output is correct
4 Correct 15 ms 31696 KB Output is correct
5 Correct 15 ms 31668 KB Output is correct
6 Correct 14 ms 31696 KB Output is correct
7 Correct 21 ms 31716 KB Output is correct
8 Correct 15 ms 31716 KB Output is correct
9 Correct 16 ms 31648 KB Output is correct
10 Correct 17 ms 31696 KB Output is correct
11 Correct 16 ms 31696 KB Output is correct
12 Correct 17 ms 31660 KB Output is correct
13 Correct 623 ms 34364 KB Output is correct
14 Correct 1102 ms 37012 KB Output is correct
15 Correct 931 ms 36936 KB Output is correct
16 Correct 980 ms 37032 KB Output is correct
17 Correct 725 ms 34344 KB Output is correct
18 Correct 996 ms 37032 KB Output is correct
19 Correct 1024 ms 36936 KB Output is correct
20 Correct 875 ms 37028 KB Output is correct
21 Correct 539 ms 31824 KB Output is correct
22 Correct 982 ms 31912 KB Output is correct
23 Correct 864 ms 31952 KB Output is correct
24 Correct 778 ms 31952 KB Output is correct
25 Correct 830 ms 39948 KB Output is correct
26 Correct 1074 ms 40088 KB Output is correct
27 Correct 1092 ms 40116 KB Output is correct
28 Correct 784 ms 40124 KB Output is correct
29 Correct 941 ms 44812 KB Output is correct
30 Correct 982 ms 44720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 31568 KB Output is correct
2 Correct 14 ms 31636 KB Output is correct
3 Correct 14 ms 31696 KB Output is correct
4 Correct 14 ms 31636 KB Output is correct
5 Correct 15 ms 31624 KB Output is correct
6 Correct 15 ms 31672 KB Output is correct
7 Correct 15 ms 31696 KB Output is correct
8 Correct 19 ms 31696 KB Output is correct
9 Correct 17 ms 31556 KB Output is correct
10 Correct 16 ms 31568 KB Output is correct
11 Correct 17 ms 31688 KB Output is correct
12 Correct 15 ms 31696 KB Output is correct
13 Correct 15 ms 31668 KB Output is correct
14 Correct 14 ms 31696 KB Output is correct
15 Correct 21 ms 31716 KB Output is correct
16 Correct 15 ms 31716 KB Output is correct
17 Correct 16 ms 31648 KB Output is correct
18 Correct 17 ms 31696 KB Output is correct
19 Correct 16 ms 31696 KB Output is correct
20 Correct 17 ms 31660 KB Output is correct
21 Correct 17 ms 31696 KB Output is correct
22 Correct 20 ms 31696 KB Output is correct
23 Correct 16 ms 31696 KB Output is correct
24 Correct 18 ms 31688 KB Output is correct
25 Correct 18 ms 31632 KB Output is correct
26 Correct 17 ms 31696 KB Output is correct
27 Correct 18 ms 31748 KB Output is correct
28 Correct 16 ms 31696 KB Output is correct
29 Correct 19 ms 31616 KB Output is correct
30 Correct 16 ms 31668 KB Output is correct
31 Correct 15 ms 31760 KB Output is correct
32 Correct 20 ms 31688 KB Output is correct
33 Correct 16 ms 31712 KB Output is correct
34 Correct 16 ms 31652 KB Output is correct
35 Correct 19 ms 31632 KB Output is correct
36 Correct 17 ms 31704 KB Output is correct
37 Correct 19 ms 31728 KB Output is correct
38 Correct 16 ms 31804 KB Output is correct
39 Correct 16 ms 31644 KB Output is correct
40 Correct 16 ms 31592 KB Output is correct
41 Correct 18 ms 31616 KB Output is correct
42 Correct 17 ms 31620 KB Output is correct
43 Correct 684 ms 31856 KB Output is correct
44 Correct 830 ms 31952 KB Output is correct
45 Correct 856 ms 31824 KB Output is correct
46 Correct 792 ms 32080 KB Output is correct
47 Correct 761 ms 32092 KB Output is correct
48 Correct 931 ms 32080 KB Output is correct
49 Correct 832 ms 32060 KB Output is correct
50 Correct 674 ms 32032 KB Output is correct
51 Correct 575 ms 31824 KB Output is correct
52 Correct 1099 ms 31824 KB Output is correct
53 Correct 936 ms 32072 KB Output is correct
54 Correct 876 ms 32028 KB Output is correct
55 Correct 593 ms 31944 KB Output is correct
56 Correct 948 ms 31824 KB Output is correct
57 Correct 952 ms 31744 KB Output is correct
58 Correct 1238 ms 32208 KB Output is correct
59 Correct 1099 ms 32440 KB Output is correct
60 Correct 1028 ms 32372 KB Output is correct
61 Correct 1006 ms 31904 KB Output is correct
62 Correct 766 ms 31856 KB Output is correct
63 Correct 901 ms 31752 KB Output is correct
64 Correct 833 ms 31824 KB Output is correct
65 Correct 560 ms 31740 KB Output is correct
66 Correct 878 ms 32008 KB Output is correct
67 Correct 814 ms 31952 KB Output is correct
68 Correct 882 ms 31912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 31568 KB Output is correct
2 Correct 14 ms 31636 KB Output is correct
3 Correct 14 ms 31696 KB Output is correct
4 Correct 14 ms 31636 KB Output is correct
5 Correct 15 ms 31624 KB Output is correct
6 Correct 15 ms 31672 KB Output is correct
7 Correct 15 ms 31696 KB Output is correct
8 Correct 19 ms 31696 KB Output is correct
9 Correct 17 ms 31556 KB Output is correct
10 Correct 16 ms 31568 KB Output is correct
11 Correct 17 ms 31688 KB Output is correct
12 Correct 15 ms 31696 KB Output is correct
13 Correct 15 ms 31668 KB Output is correct
14 Correct 14 ms 31696 KB Output is correct
15 Correct 21 ms 31716 KB Output is correct
16 Correct 15 ms 31716 KB Output is correct
17 Correct 16 ms 31648 KB Output is correct
18 Correct 17 ms 31696 KB Output is correct
19 Correct 16 ms 31696 KB Output is correct
20 Correct 17 ms 31660 KB Output is correct
21 Correct 17 ms 31696 KB Output is correct
22 Correct 20 ms 31696 KB Output is correct
23 Correct 16 ms 31696 KB Output is correct
24 Correct 18 ms 31688 KB Output is correct
25 Correct 18 ms 31632 KB Output is correct
26 Correct 17 ms 31696 KB Output is correct
27 Correct 18 ms 31748 KB Output is correct
28 Correct 16 ms 31696 KB Output is correct
29 Correct 19 ms 31616 KB Output is correct
30 Correct 16 ms 31668 KB Output is correct
31 Correct 15 ms 31760 KB Output is correct
32 Correct 20 ms 31688 KB Output is correct
33 Correct 16 ms 31712 KB Output is correct
34 Correct 16 ms 31652 KB Output is correct
35 Correct 19 ms 31632 KB Output is correct
36 Correct 17 ms 31704 KB Output is correct
37 Correct 19 ms 31728 KB Output is correct
38 Correct 16 ms 31804 KB Output is correct
39 Correct 16 ms 31644 KB Output is correct
40 Correct 16 ms 31592 KB Output is correct
41 Correct 18 ms 31616 KB Output is correct
42 Correct 17 ms 31620 KB Output is correct
43 Correct 623 ms 34364 KB Output is correct
44 Correct 1102 ms 37012 KB Output is correct
45 Correct 931 ms 36936 KB Output is correct
46 Correct 980 ms 37032 KB Output is correct
47 Correct 725 ms 34344 KB Output is correct
48 Correct 996 ms 37032 KB Output is correct
49 Correct 1024 ms 36936 KB Output is correct
50 Correct 875 ms 37028 KB Output is correct
51 Correct 539 ms 31824 KB Output is correct
52 Correct 982 ms 31912 KB Output is correct
53 Correct 864 ms 31952 KB Output is correct
54 Correct 778 ms 31952 KB Output is correct
55 Correct 830 ms 39948 KB Output is correct
56 Correct 1074 ms 40088 KB Output is correct
57 Correct 1092 ms 40116 KB Output is correct
58 Correct 784 ms 40124 KB Output is correct
59 Correct 941 ms 44812 KB Output is correct
60 Correct 982 ms 44720 KB Output is correct
61 Correct 684 ms 31856 KB Output is correct
62 Correct 830 ms 31952 KB Output is correct
63 Correct 856 ms 31824 KB Output is correct
64 Correct 792 ms 32080 KB Output is correct
65 Correct 761 ms 32092 KB Output is correct
66 Correct 931 ms 32080 KB Output is correct
67 Correct 832 ms 32060 KB Output is correct
68 Correct 674 ms 32032 KB Output is correct
69 Correct 575 ms 31824 KB Output is correct
70 Correct 1099 ms 31824 KB Output is correct
71 Correct 936 ms 32072 KB Output is correct
72 Correct 876 ms 32028 KB Output is correct
73 Correct 593 ms 31944 KB Output is correct
74 Correct 948 ms 31824 KB Output is correct
75 Correct 952 ms 31744 KB Output is correct
76 Correct 1238 ms 32208 KB Output is correct
77 Correct 1099 ms 32440 KB Output is correct
78 Correct 1028 ms 32372 KB Output is correct
79 Correct 1006 ms 31904 KB Output is correct
80 Correct 766 ms 31856 KB Output is correct
81 Correct 901 ms 31752 KB Output is correct
82 Correct 833 ms 31824 KB Output is correct
83 Correct 560 ms 31740 KB Output is correct
84 Correct 878 ms 32008 KB Output is correct
85 Correct 814 ms 31952 KB Output is correct
86 Correct 882 ms 31912 KB Output is correct
87 Correct 18 ms 31544 KB Output is correct
88 Correct 638 ms 39448 KB Output is correct
89 Correct 822 ms 37448 KB Output is correct
90 Correct 1033 ms 37100 KB Output is correct
91 Correct 1113 ms 40208 KB Output is correct
92 Correct 1141 ms 40216 KB Output is correct
93 Correct 1047 ms 40128 KB Output is correct
94 Correct 1018 ms 40112 KB Output is correct
95 Correct 1153 ms 40220 KB Output is correct
96 Correct 1012 ms 35124 KB Output is correct
97 Correct 1085 ms 35120 KB Output is correct
98 Correct 1109 ms 41848 KB Output is correct
99 Correct 1214 ms 40160 KB Output is correct
100 Correct 1098 ms 37484 KB Output is correct
101 Correct 1178 ms 36552 KB Output is correct
102 Correct 1008 ms 35116 KB Output is correct
103 Correct 991 ms 44752 KB Output is correct
104 Correct 988 ms 45232 KB Output is correct
105 Correct 1081 ms 45344 KB Output is correct
106 Correct 915 ms 38176 KB Output is correct
107 Correct 1080 ms 36272 KB Output is correct
108 Correct 979 ms 36088 KB Output is correct
109 Correct 994 ms 35092 KB Output is correct