Submission #820187

# Submission time Handle Problem Language Result Execution time Memory
820187 2023-08-11T00:32:51 Z maeola Digital Circuit (IOI22_circuit) C++17
50 / 100
3000 ms 9672 KB
#include "circuit.h"

#include <bits/stdc++.h>

using ll = long long;

using namespace std;

constexpr int mod = 1e9 + 2022;

struct ST
{
        int pool[2];
};

vector<int> adj[200005];
int choices[200005], coef[200005];
ll ans = 0;
int N, M;

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);
        }
}

int A[100005];

void init(int N_, int M_, vector<int> P, vector<int> A_)
{
        N = N_, M = M_;
        memcpy(A, A_.data(), sizeof(int) * M);
        assert((int)A_.size() == M);
        for (int i = 1; i < N + M; i++)
                adj[P[i]].push_back(i);
        dfs1(0);
        dfs2(0, 1);

        for (int i = 0; i < M; i++)
        {
                ans += A[i] * coef[i + N];
                ans %= mod;
        }
}

int count_ways(int L, int R)
{
        L -= N, R -= N;
        for (int i = L; i <= R; i++)
        {
                if (A[i])
                {
                        A[i] = 0;
                        ans = (ans + mod - coef[i + N]) % mod;
                }
                else
                {
                        A[i] = 1;
                        ans = (ans + coef[i + N]) % mod;
                }
        }
        return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 5012 KB Output is correct
3 Correct 3 ms 4944 KB Output is correct
4 Correct 2 ms 4944 KB Output is correct
5 Correct 2 ms 4944 KB Output is correct
6 Correct 2 ms 4944 KB Output is correct
7 Correct 2 ms 4944 KB Output is correct
8 Correct 2 ms 4944 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 4944 KB Output is correct
4 Correct 2 ms 4944 KB Output is correct
5 Correct 2 ms 4944 KB Output is correct
6 Correct 2 ms 4944 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 2 ms 5016 KB Output is correct
10 Correct 3 ms 5232 KB Output is correct
11 Correct 3 ms 5200 KB Output is correct
12 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 5012 KB Output is correct
3 Correct 3 ms 4944 KB Output is correct
4 Correct 2 ms 4944 KB Output is correct
5 Correct 2 ms 4944 KB Output is correct
6 Correct 2 ms 4944 KB Output is correct
7 Correct 2 ms 4944 KB Output is correct
8 Correct 2 ms 4944 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 4944 KB Output is correct
12 Correct 2 ms 4944 KB Output is correct
13 Correct 2 ms 4944 KB Output is correct
14 Correct 2 ms 4944 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 2 ms 5016 KB Output is correct
18 Correct 3 ms 5232 KB Output is correct
19 Correct 3 ms 5200 KB Output is correct
20 Correct 2 ms 5072 KB Output is correct
21 Correct 2 ms 4944 KB Output is correct
22 Correct 2 ms 4944 KB Output is correct
23 Correct 2 ms 4944 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 2 ms 5072 KB Output is correct
26 Correct 3 ms 4996 KB Output is correct
27 Correct 2 ms 5072 KB Output is correct
28 Correct 3 ms 5072 KB Output is correct
29 Correct 2 ms 4944 KB Output is correct
30 Correct 3 ms 4944 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 4944 KB Output is correct
34 Correct 2 ms 4944 KB Output is correct
35 Correct 2 ms 4944 KB Output is correct
36 Correct 3 ms 5200 KB Output is correct
37 Correct 3 ms 5200 KB Output is correct
38 Correct 3 ms 5268 KB Output is correct
39 Correct 2 ms 5072 KB Output is correct
40 Correct 2 ms 4944 KB Output is correct
41 Correct 2 ms 4944 KB Output is correct
42 Correct 2 ms 4944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 477 ms 7232 KB Output is correct
2 Correct 716 ms 9620 KB Output is correct
3 Correct 804 ms 9672 KB Output is correct
4 Correct 703 ms 9544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 477 ms 7232 KB Output is correct
2 Correct 716 ms 9620 KB Output is correct
3 Correct 804 ms 9672 KB Output is correct
4 Correct 703 ms 9544 KB Output is correct
5 Execution timed out 3009 ms 7248 KB Time limit exceeded
6 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 4944 KB Output is correct
4 Correct 2 ms 4944 KB Output is correct
5 Correct 2 ms 4944 KB Output is correct
6 Correct 2 ms 4944 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 2 ms 5016 KB Output is correct
10 Correct 3 ms 5232 KB Output is correct
11 Correct 3 ms 5200 KB Output is correct
12 Correct 2 ms 5072 KB Output is correct
13 Correct 477 ms 7232 KB Output is correct
14 Correct 716 ms 9620 KB Output is correct
15 Correct 804 ms 9672 KB Output is correct
16 Correct 703 ms 9544 KB Output is correct
17 Execution timed out 3009 ms 7248 KB Time limit exceeded
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 5012 KB Output is correct
3 Correct 3 ms 4944 KB Output is correct
4 Correct 2 ms 4944 KB Output is correct
5 Correct 2 ms 4944 KB Output is correct
6 Correct 2 ms 4944 KB Output is correct
7 Correct 2 ms 4944 KB Output is correct
8 Correct 2 ms 4944 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 4944 KB Output is correct
12 Correct 2 ms 4944 KB Output is correct
13 Correct 2 ms 4944 KB Output is correct
14 Correct 2 ms 4944 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 2 ms 5016 KB Output is correct
18 Correct 3 ms 5232 KB Output is correct
19 Correct 3 ms 5200 KB Output is correct
20 Correct 2 ms 5072 KB Output is correct
21 Correct 2 ms 4944 KB Output is correct
22 Correct 2 ms 4944 KB Output is correct
23 Correct 2 ms 4944 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 2 ms 5072 KB Output is correct
26 Correct 3 ms 4996 KB Output is correct
27 Correct 2 ms 5072 KB Output is correct
28 Correct 3 ms 5072 KB Output is correct
29 Correct 2 ms 4944 KB Output is correct
30 Correct 3 ms 4944 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 4944 KB Output is correct
34 Correct 2 ms 4944 KB Output is correct
35 Correct 2 ms 4944 KB Output is correct
36 Correct 3 ms 5200 KB Output is correct
37 Correct 3 ms 5200 KB Output is correct
38 Correct 3 ms 5268 KB Output is correct
39 Correct 2 ms 5072 KB Output is correct
40 Correct 2 ms 4944 KB Output is correct
41 Correct 2 ms 4944 KB Output is correct
42 Correct 2 ms 4944 KB Output is correct
43 Correct 733 ms 5200 KB Output is correct
44 Correct 1020 ms 5200 KB Output is correct
45 Correct 1010 ms 5200 KB Output is correct
46 Correct 763 ms 5284 KB Output is correct
47 Correct 1422 ms 5328 KB Output is correct
48 Correct 1154 ms 5272 KB Output is correct
49 Correct 1326 ms 5328 KB Output is correct
50 Correct 2268 ms 5328 KB Output is correct
51 Correct 2261 ms 5200 KB Output is correct
52 Correct 1431 ms 5200 KB Output is correct
53 Correct 540 ms 6224 KB Output is correct
54 Correct 1308 ms 5328 KB Output is correct
55 Correct 1338 ms 5252 KB Output is correct
56 Correct 1222 ms 5200 KB Output is correct
57 Correct 1385 ms 5072 KB Output is correct
58 Correct 1325 ms 6352 KB Output is correct
59 Correct 1268 ms 6352 KB Output is correct
60 Correct 2439 ms 6352 KB Output is correct
61 Correct 905 ms 5456 KB Output is correct
62 Correct 1150 ms 5072 KB Output is correct
63 Correct 1031 ms 5072 KB Output is correct
64 Correct 1223 ms 5072 KB Output is correct
65 Correct 440 ms 5072 KB Output is correct
66 Correct 1089 ms 5200 KB Output is correct
67 Correct 1203 ms 5200 KB Output is correct
68 Correct 2132 ms 5200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 5012 KB Output is correct
3 Correct 3 ms 4944 KB Output is correct
4 Correct 2 ms 4944 KB Output is correct
5 Correct 2 ms 4944 KB Output is correct
6 Correct 2 ms 4944 KB Output is correct
7 Correct 2 ms 4944 KB Output is correct
8 Correct 2 ms 4944 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 4944 KB Output is correct
12 Correct 2 ms 4944 KB Output is correct
13 Correct 2 ms 4944 KB Output is correct
14 Correct 2 ms 4944 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 2 ms 5016 KB Output is correct
18 Correct 3 ms 5232 KB Output is correct
19 Correct 3 ms 5200 KB Output is correct
20 Correct 2 ms 5072 KB Output is correct
21 Correct 2 ms 4944 KB Output is correct
22 Correct 2 ms 4944 KB Output is correct
23 Correct 2 ms 4944 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 2 ms 5072 KB Output is correct
26 Correct 3 ms 4996 KB Output is correct
27 Correct 2 ms 5072 KB Output is correct
28 Correct 3 ms 5072 KB Output is correct
29 Correct 2 ms 4944 KB Output is correct
30 Correct 3 ms 4944 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 4944 KB Output is correct
34 Correct 2 ms 4944 KB Output is correct
35 Correct 2 ms 4944 KB Output is correct
36 Correct 3 ms 5200 KB Output is correct
37 Correct 3 ms 5200 KB Output is correct
38 Correct 3 ms 5268 KB Output is correct
39 Correct 2 ms 5072 KB Output is correct
40 Correct 2 ms 4944 KB Output is correct
41 Correct 2 ms 4944 KB Output is correct
42 Correct 2 ms 4944 KB Output is correct
43 Correct 477 ms 7232 KB Output is correct
44 Correct 716 ms 9620 KB Output is correct
45 Correct 804 ms 9672 KB Output is correct
46 Correct 703 ms 9544 KB Output is correct
47 Execution timed out 3009 ms 7248 KB Time limit exceeded
48 Halted 0 ms 0 KB -