Submission #633073

# Submission time Handle Problem Language Result Execution time Memory
633073 2022-08-21T14:32:15 Z tutis Digital Circuit (IOI22_circuit) C++17
100 / 100
1150 ms 40980 KB
#include "circuit.h"
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000002022;
vector<pair<ll, ll>>a;

vector<int>P;
vector<int>A;
vector<vector<int>>c;
int N, M;
vector<bool> F(200009, false);
vector<int> L, R;
void calc(int i)
{
    int d = c[i].size();
    vector<ll> k(d + 2, 0ll);
    ll v = 1;
    a[i] = {0ll, 0ll};
    for (int j : c[i])
    {
        int v0 = a[j].first;
        int v1 = a[j].second;
        if (F[j])
            swap(v0, v1);
        ll a1_ = 0;
        ll a0_ = 0;
        a1_ = a[i].second * (v0 + v1) + v * v1;
        a0_ = a[i].first * (v0 + v1) + v * v0;
        a[i].first = a0_;
        a[i].second = a1_;
        v *= (v0 + v1);
        a[i].first %= mod;
        a[i].second %= mod;
        v %= mod;
    }
}
vector<int>D;
struct st
{
    int s0, s1;
    int l, r;
    bool lazy = false;
    st *left;
    st *right;
    st() {}
    st(int l, int r): l(l), r(r)
    {
        if (l < r)
        {
            left = new st(l, (l + r) / 2);
            right = new st((l + r) / 2 + 1, r);
            s0 = left->s0 + right->s0;
            s1 = left->s1 + right->s1;
            if (s0 >= mod)
                s0 -= mod;
            if (s1 >= mod)
                s1 -= mod;
        }
        else
        {
            if (A[l] == 1)
            {
                s1 = D[l + N];
                s0 = 0;
            }
            else
            {
                s1 = 0;
                s0 = D[l + N];
            }
        }
    }
    void fix()
    {
        if (lazy)
        {
            swap(s0, s1);
            if (l < r)
            {
                left->lazy ^= true;
                right->lazy ^= true;
            }
        }
        lazy = false;
    }
    void fl(int x, int y)
    {
        if (x <= l && r <= y)
        {
            lazy ^= true;
            return fix();
        }
        if (r < x || y < l)
            return fix();
        fix();
        left->fl(x, y);
        right->fl(x, y);
        s0 = left->s0 + right->s0;
        s1 = left->s1 + right->s1;
        if (s0 >= mod)
            s0 -= mod;
        if (s1 >= mod)
            s1 -= mod;
    }
};
st medis;
void init(int N_, int M_, vector<int> P_, vector<int> A_) {
    P = P_;
    A = A_;
    N = N_;
    M = M_;
    c = vector<vector<int>>(N + M);
    for (int i = 1; i < N + M; i++)
        c[P[i]].push_back(i);
    ll prod[N + M];
    {
        function<void(int)>dfs = [&](int i)->void
        {
            prod[i] = max(1, (int)c[i].size());
            for (int j : c[i])
            {
                dfs(j);
                prod[i] *= prod[j];
                prod[i] %= mod;
            }
        };
        dfs(0);
    }
    D = vector<int>(N + M);
    {
        function<void(int, ll)>dfs = [&](int i, ll ss)->void
        {
            D[i] = (int)ss;
            vector<ll>s;
            int cnt = 0;
            for (int j : c[i])
            {
                s.push_back(prod[j]);
                cnt++;
            }
            vector<ll>t = s;
            reverse(t.begin(), t.end());
            s.insert(s.begin(), 1);
            t.insert(t.begin(), 1);
            for (int i = 1; i < (int)s.size(); i++)
                s[i] = (s[i - 1] * s[i]) % mod;
            for (int i = 1; i < (int)t.size(); i++)
                t[i] = (t[i - 1] * t[i]) % mod;
            int k = 0;
            for (int j : c[i])
            {
                ll s_ = ss;
                s_ *= s[k];
                s_ %= mod;
                s_ *= t[cnt - 1 - k];
                s_ %= mod;
                dfs(j, s_);
                k++;
            }
        };
        dfs(0, 1);
    }
    medis = st(0, M - 1);
}
int count_ways(int X, int Y) {
    medis.fl(X - N, Y - N);
    return medis.s1;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 1 ms 464 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 1 ms 464 KB Output is correct
7 Correct 1 ms 464 KB Output is correct
8 Correct 1 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 2 ms 464 KB Output is correct
7 Correct 1 ms 464 KB Output is correct
8 Correct 2 ms 464 KB Output is correct
9 Correct 2 ms 464 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
11 Correct 1 ms 592 KB Output is correct
12 Correct 1 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 1 ms 464 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 1 ms 464 KB Output is correct
7 Correct 1 ms 464 KB Output is correct
8 Correct 1 ms 464 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 2 ms 464 KB Output is correct
15 Correct 1 ms 464 KB Output is correct
16 Correct 2 ms 464 KB Output is correct
17 Correct 2 ms 464 KB Output is correct
18 Correct 1 ms 592 KB Output is correct
19 Correct 1 ms 592 KB Output is correct
20 Correct 1 ms 464 KB Output is correct
21 Correct 1 ms 464 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 2 ms 336 KB Output is correct
24 Correct 1 ms 464 KB Output is correct
25 Correct 1 ms 464 KB Output is correct
26 Correct 1 ms 464 KB Output is correct
27 Correct 1 ms 464 KB Output is correct
28 Correct 1 ms 464 KB Output is correct
29 Correct 1 ms 464 KB Output is correct
30 Correct 1 ms 464 KB Output is correct
31 Correct 1 ms 592 KB Output is correct
32 Correct 2 ms 464 KB Output is correct
33 Correct 2 ms 464 KB Output is correct
34 Correct 1 ms 464 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 1 ms 592 KB Output is correct
37 Correct 1 ms 720 KB Output is correct
38 Correct 1 ms 720 KB Output is correct
39 Correct 1 ms 464 KB Output is correct
40 Correct 1 ms 464 KB Output is correct
41 Correct 1 ms 464 KB Output is correct
42 Correct 1 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 451 ms 7860 KB Output is correct
2 Correct 1033 ms 15372 KB Output is correct
3 Correct 1006 ms 15428 KB Output is correct
4 Correct 929 ms 15432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 451 ms 7860 KB Output is correct
2 Correct 1033 ms 15372 KB Output is correct
3 Correct 1006 ms 15428 KB Output is correct
4 Correct 929 ms 15432 KB Output is correct
5 Correct 759 ms 7836 KB Output is correct
6 Correct 1059 ms 15364 KB Output is correct
7 Correct 1086 ms 15472 KB Output is correct
8 Correct 759 ms 15432 KB Output is correct
9 Correct 408 ms 720 KB Output is correct
10 Correct 956 ms 1232 KB Output is correct
11 Correct 942 ms 1276 KB Output is correct
12 Correct 906 ms 1232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 2 ms 464 KB Output is correct
7 Correct 1 ms 464 KB Output is correct
8 Correct 2 ms 464 KB Output is correct
9 Correct 2 ms 464 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
11 Correct 1 ms 592 KB Output is correct
12 Correct 1 ms 464 KB Output is correct
13 Correct 451 ms 7860 KB Output is correct
14 Correct 1033 ms 15372 KB Output is correct
15 Correct 1006 ms 15428 KB Output is correct
16 Correct 929 ms 15432 KB Output is correct
17 Correct 759 ms 7836 KB Output is correct
18 Correct 1059 ms 15364 KB Output is correct
19 Correct 1086 ms 15472 KB Output is correct
20 Correct 759 ms 15432 KB Output is correct
21 Correct 408 ms 720 KB Output is correct
22 Correct 956 ms 1232 KB Output is correct
23 Correct 942 ms 1276 KB Output is correct
24 Correct 906 ms 1232 KB Output is correct
25 Correct 1150 ms 22996 KB Output is correct
26 Correct 1042 ms 23376 KB Output is correct
27 Correct 1065 ms 23380 KB Output is correct
28 Correct 730 ms 23368 KB Output is correct
29 Correct 1043 ms 40520 KB Output is correct
30 Correct 886 ms 40648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 1 ms 464 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 1 ms 464 KB Output is correct
7 Correct 1 ms 464 KB Output is correct
8 Correct 1 ms 464 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 2 ms 464 KB Output is correct
15 Correct 1 ms 464 KB Output is correct
16 Correct 2 ms 464 KB Output is correct
17 Correct 2 ms 464 KB Output is correct
18 Correct 1 ms 592 KB Output is correct
19 Correct 1 ms 592 KB Output is correct
20 Correct 1 ms 464 KB Output is correct
21 Correct 1 ms 464 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 2 ms 336 KB Output is correct
24 Correct 1 ms 464 KB Output is correct
25 Correct 1 ms 464 KB Output is correct
26 Correct 1 ms 464 KB Output is correct
27 Correct 1 ms 464 KB Output is correct
28 Correct 1 ms 464 KB Output is correct
29 Correct 1 ms 464 KB Output is correct
30 Correct 1 ms 464 KB Output is correct
31 Correct 1 ms 592 KB Output is correct
32 Correct 2 ms 464 KB Output is correct
33 Correct 2 ms 464 KB Output is correct
34 Correct 1 ms 464 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 1 ms 592 KB Output is correct
37 Correct 1 ms 720 KB Output is correct
38 Correct 1 ms 720 KB Output is correct
39 Correct 1 ms 464 KB Output is correct
40 Correct 1 ms 464 KB Output is correct
41 Correct 1 ms 464 KB Output is correct
42 Correct 1 ms 464 KB Output is correct
43 Correct 590 ms 976 KB Output is correct
44 Correct 855 ms 976 KB Output is correct
45 Correct 764 ms 976 KB Output is correct
46 Correct 648 ms 1488 KB Output is correct
47 Correct 910 ms 1488 KB Output is correct
48 Correct 776 ms 1488 KB Output is correct
49 Correct 920 ms 1488 KB Output is correct
50 Correct 923 ms 1488 KB Output is correct
51 Correct 896 ms 1068 KB Output is correct
52 Correct 902 ms 1068 KB Output is correct
53 Correct 789 ms 1872 KB Output is correct
54 Correct 970 ms 1360 KB Output is correct
55 Correct 723 ms 1232 KB Output is correct
56 Correct 796 ms 1104 KB Output is correct
57 Correct 789 ms 976 KB Output is correct
58 Correct 924 ms 2256 KB Output is correct
59 Correct 874 ms 2344 KB Output is correct
60 Correct 876 ms 2344 KB Output is correct
61 Correct 608 ms 1104 KB Output is correct
62 Correct 929 ms 976 KB Output is correct
63 Correct 839 ms 976 KB Output is correct
64 Correct 807 ms 1104 KB Output is correct
65 Correct 389 ms 720 KB Output is correct
66 Correct 1031 ms 1232 KB Output is correct
67 Correct 891 ms 1232 KB Output is correct
68 Correct 722 ms 1232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 1 ms 464 KB Output is correct
5 Correct 1 ms 464 KB Output is correct
6 Correct 1 ms 464 KB Output is correct
7 Correct 1 ms 464 KB Output is correct
8 Correct 1 ms 464 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 2 ms 464 KB Output is correct
15 Correct 1 ms 464 KB Output is correct
16 Correct 2 ms 464 KB Output is correct
17 Correct 2 ms 464 KB Output is correct
18 Correct 1 ms 592 KB Output is correct
19 Correct 1 ms 592 KB Output is correct
20 Correct 1 ms 464 KB Output is correct
21 Correct 1 ms 464 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 2 ms 336 KB Output is correct
24 Correct 1 ms 464 KB Output is correct
25 Correct 1 ms 464 KB Output is correct
26 Correct 1 ms 464 KB Output is correct
27 Correct 1 ms 464 KB Output is correct
28 Correct 1 ms 464 KB Output is correct
29 Correct 1 ms 464 KB Output is correct
30 Correct 1 ms 464 KB Output is correct
31 Correct 1 ms 592 KB Output is correct
32 Correct 2 ms 464 KB Output is correct
33 Correct 2 ms 464 KB Output is correct
34 Correct 1 ms 464 KB Output is correct
35 Correct 1 ms 336 KB Output is correct
36 Correct 1 ms 592 KB Output is correct
37 Correct 1 ms 720 KB Output is correct
38 Correct 1 ms 720 KB Output is correct
39 Correct 1 ms 464 KB Output is correct
40 Correct 1 ms 464 KB Output is correct
41 Correct 1 ms 464 KB Output is correct
42 Correct 1 ms 464 KB Output is correct
43 Correct 451 ms 7860 KB Output is correct
44 Correct 1033 ms 15372 KB Output is correct
45 Correct 1006 ms 15428 KB Output is correct
46 Correct 929 ms 15432 KB Output is correct
47 Correct 759 ms 7836 KB Output is correct
48 Correct 1059 ms 15364 KB Output is correct
49 Correct 1086 ms 15472 KB Output is correct
50 Correct 759 ms 15432 KB Output is correct
51 Correct 408 ms 720 KB Output is correct
52 Correct 956 ms 1232 KB Output is correct
53 Correct 942 ms 1276 KB Output is correct
54 Correct 906 ms 1232 KB Output is correct
55 Correct 1150 ms 22996 KB Output is correct
56 Correct 1042 ms 23376 KB Output is correct
57 Correct 1065 ms 23380 KB Output is correct
58 Correct 730 ms 23368 KB Output is correct
59 Correct 1043 ms 40520 KB Output is correct
60 Correct 886 ms 40648 KB Output is correct
61 Correct 590 ms 976 KB Output is correct
62 Correct 855 ms 976 KB Output is correct
63 Correct 764 ms 976 KB Output is correct
64 Correct 648 ms 1488 KB Output is correct
65 Correct 910 ms 1488 KB Output is correct
66 Correct 776 ms 1488 KB Output is correct
67 Correct 920 ms 1488 KB Output is correct
68 Correct 923 ms 1488 KB Output is correct
69 Correct 896 ms 1068 KB Output is correct
70 Correct 902 ms 1068 KB Output is correct
71 Correct 789 ms 1872 KB Output is correct
72 Correct 970 ms 1360 KB Output is correct
73 Correct 723 ms 1232 KB Output is correct
74 Correct 796 ms 1104 KB Output is correct
75 Correct 789 ms 976 KB Output is correct
76 Correct 924 ms 2256 KB Output is correct
77 Correct 874 ms 2344 KB Output is correct
78 Correct 876 ms 2344 KB Output is correct
79 Correct 608 ms 1104 KB Output is correct
80 Correct 929 ms 976 KB Output is correct
81 Correct 839 ms 976 KB Output is correct
82 Correct 807 ms 1104 KB Output is correct
83 Correct 389 ms 720 KB Output is correct
84 Correct 1031 ms 1232 KB Output is correct
85 Correct 891 ms 1232 KB Output is correct
86 Correct 722 ms 1232 KB Output is correct
87 Correct 0 ms 208 KB Output is correct
88 Correct 628 ms 20224 KB Output is correct
89 Correct 801 ms 13844 KB Output is correct
90 Correct 1056 ms 14300 KB Output is correct
91 Correct 969 ms 23448 KB Output is correct
92 Correct 915 ms 23496 KB Output is correct
93 Correct 1004 ms 23504 KB Output is correct
94 Correct 1099 ms 23624 KB Output is correct
95 Correct 916 ms 23496 KB Output is correct
96 Correct 841 ms 15912 KB Output is correct
97 Correct 985 ms 15888 KB Output is correct
98 Correct 781 ms 31600 KB Output is correct
99 Correct 1054 ms 23400 KB Output is correct
100 Correct 1018 ms 19468 KB Output is correct
101 Correct 1022 ms 17968 KB Output is correct
102 Correct 1132 ms 16048 KB Output is correct
103 Correct 1117 ms 40520 KB Output is correct
104 Correct 966 ms 40980 KB Output is correct
105 Correct 927 ms 40980 KB Output is correct
106 Correct 1056 ms 16444 KB Output is correct
107 Correct 1018 ms 13696 KB Output is correct
108 Correct 760 ms 14624 KB Output is correct
109 Correct 1069 ms 16052 KB Output is correct