답안 #820190

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
820190 2023-08-11T00:47:12 Z maeola 디지털 회로 (IOI22_circuit) C++17
46 / 100
820 ms 11140 KB
#include "circuit.h"

#include <bits/stdc++.h>

using ll = long long;

using namespace std;

constexpr int mod = 1e9 + 2022;

vector<int> adj[200005];
int choices[200005], coef[200005], *C;
int N, M;

struct ST
{
        int pool[200005], total[200005];
        int lazy[200005];

        void build(int i, int l, int r)
        {
                if (l == r)
                {
                        total[i] = C[l];
                        return;
                }
                int m = (l + r) / 2;
                build(i << 1, l, m);
                build(i << 1 | 1, m + 1, r);
                total[i] = (total[i << 1] + total[i << 1 | 1]) % mod;
        }

        void clean(int i)
        {
                if (lazy[i])
                {
                        pool[i] = total[i] - pool[i];
                        if (pool[i] >= mod)
                                pool[i] -= mod;
                        if (pool[i] < 0)
                                pool[i] += mod;
                        lazy[i << 1] ^= 1;
                        lazy[i << 1 | 1] ^= 1;
                        lazy[i] = 0;
                }
        }

        void flip(int i, int l, int r, int ql, int qr)
        {
                clean(i);
                if (qr < l or ql > r)
                        return;
                if (ql <= l and qr >= r)
                {
                        lazy[i] = 1;
                        clean(i);
                        return;
                }
                int m = (l + r) / 2;
                flip(i << 1, l, m, ql, qr);
                flip(i << 1 | 1, m + 1, r, ql, qr);
                pool[i] = (pool[i << 1] + pool[i << 1 | 1]) % mod;
        }
} st;

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

void init(int N_, int M_, vector<int> P, vector<int> A)
{
        N = N_, M = M_;
        for (int i = 1; i < N + M; i++)
                adj[P[i]].push_back(i);
        dfs1(0);
        dfs2(0, 1);
        C = coef + N;

        st.build(1, 0, M - 1);
        for (int i = 0; i < M; i++)
                if (A[i])
                        st.flip(1, 0, M - 1, i, i);
}

int count_ways(int L, int R)
{
        L -= N, R -= N;
        st.flip(1, 0, M - 1, L, R);
        st.clean(1);
        return st.pool[1];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 2 ms 5072 KB Output is correct
5 Correct 2 ms 5072 KB Output is correct
6 Correct 3 ms 5008 KB Output is correct
7 Correct 2 ms 5072 KB Output is correct
8 Correct 2 ms 5052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 2 ms 5072 KB Output is correct
4 Correct 2 ms 5072 KB Output is correct
5 Correct 2 ms 5072 KB Output is correct
6 Correct 2 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 3 ms 5072 KB Output is correct
10 Correct 3 ms 5200 KB Output is correct
11 Correct 3 ms 5200 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 2 ms 5072 KB Output is correct
5 Correct 2 ms 5072 KB Output is correct
6 Correct 3 ms 5008 KB Output is correct
7 Correct 2 ms 5072 KB Output is correct
8 Correct 2 ms 5052 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 3 ms 4944 KB Output is correct
11 Correct 2 ms 5072 KB Output is correct
12 Correct 2 ms 5072 KB Output is correct
13 Correct 2 ms 5072 KB Output is correct
14 Correct 2 ms 5072 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 3 ms 5200 KB Output is correct
19 Correct 3 ms 5200 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 2 ms 5072 KB Output is correct
23 Correct 2 ms 5072 KB Output is correct
24 Correct 2 ms 5072 KB Output is correct
25 Correct 3 ms 5072 KB Output is correct
26 Correct 2 ms 5072 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Correct 3 ms 5072 KB Output is correct
29 Correct 2 ms 5072 KB Output is correct
30 Correct 2 ms 5072 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 5072 KB Output is correct
34 Correct 2 ms 5072 KB Output is correct
35 Correct 2 ms 5072 KB Output is correct
36 Correct 4 ms 5200 KB Output is correct
37 Correct 3 ms 5328 KB Output is correct
38 Correct 3 ms 5328 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 3 ms 5072 KB Output is correct
41 Correct 2 ms 5072 KB Output is correct
42 Correct 2 ms 5072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 514 ms 8016 KB Output is correct
2 Incorrect 769 ms 11140 KB 3rd lines differ - on the 1st token, expected: '913758140', found: '943578984'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 514 ms 8016 KB Output is correct
2 Incorrect 769 ms 11140 KB 3rd lines differ - on the 1st token, expected: '913758140', found: '943578984'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 2 ms 5072 KB Output is correct
4 Correct 2 ms 5072 KB Output is correct
5 Correct 2 ms 5072 KB Output is correct
6 Correct 2 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 3 ms 5072 KB Output is correct
10 Correct 3 ms 5200 KB Output is correct
11 Correct 3 ms 5200 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 514 ms 8016 KB Output is correct
14 Incorrect 769 ms 11140 KB 3rd lines differ - on the 1st token, expected: '913758140', found: '943578984'
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 2 ms 5072 KB Output is correct
5 Correct 2 ms 5072 KB Output is correct
6 Correct 3 ms 5008 KB Output is correct
7 Correct 2 ms 5072 KB Output is correct
8 Correct 2 ms 5052 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 3 ms 4944 KB Output is correct
11 Correct 2 ms 5072 KB Output is correct
12 Correct 2 ms 5072 KB Output is correct
13 Correct 2 ms 5072 KB Output is correct
14 Correct 2 ms 5072 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 3 ms 5200 KB Output is correct
19 Correct 3 ms 5200 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 2 ms 5072 KB Output is correct
23 Correct 2 ms 5072 KB Output is correct
24 Correct 2 ms 5072 KB Output is correct
25 Correct 3 ms 5072 KB Output is correct
26 Correct 2 ms 5072 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Correct 3 ms 5072 KB Output is correct
29 Correct 2 ms 5072 KB Output is correct
30 Correct 2 ms 5072 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 5072 KB Output is correct
34 Correct 2 ms 5072 KB Output is correct
35 Correct 2 ms 5072 KB Output is correct
36 Correct 4 ms 5200 KB Output is correct
37 Correct 3 ms 5328 KB Output is correct
38 Correct 3 ms 5328 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 3 ms 5072 KB Output is correct
41 Correct 2 ms 5072 KB Output is correct
42 Correct 2 ms 5072 KB Output is correct
43 Correct 566 ms 5348 KB Output is correct
44 Correct 714 ms 5452 KB Output is correct
45 Correct 820 ms 5296 KB Output is correct
46 Correct 601 ms 5584 KB Output is correct
47 Correct 684 ms 5584 KB Output is correct
48 Correct 645 ms 5612 KB Output is correct
49 Correct 713 ms 5584 KB Output is correct
50 Correct 588 ms 5584 KB Output is correct
51 Correct 735 ms 5456 KB Output is correct
52 Correct 653 ms 5456 KB Output is correct
53 Correct 564 ms 6224 KB Output is correct
54 Correct 602 ms 5584 KB Output is correct
55 Correct 685 ms 5456 KB Output is correct
56 Correct 805 ms 5456 KB Output is correct
57 Correct 539 ms 5328 KB Output is correct
58 Correct 687 ms 6608 KB Output is correct
59 Correct 649 ms 6608 KB Output is correct
60 Correct 544 ms 6608 KB Output is correct
61 Correct 784 ms 5584 KB Output is correct
62 Correct 514 ms 5328 KB Output is correct
63 Correct 805 ms 5200 KB Output is correct
64 Correct 665 ms 5328 KB Output is correct
65 Correct 315 ms 5224 KB Output is correct
66 Correct 563 ms 5328 KB Output is correct
67 Correct 711 ms 5452 KB Output is correct
68 Correct 613 ms 5328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 2 ms 5072 KB Output is correct
5 Correct 2 ms 5072 KB Output is correct
6 Correct 3 ms 5008 KB Output is correct
7 Correct 2 ms 5072 KB Output is correct
8 Correct 2 ms 5052 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 3 ms 4944 KB Output is correct
11 Correct 2 ms 5072 KB Output is correct
12 Correct 2 ms 5072 KB Output is correct
13 Correct 2 ms 5072 KB Output is correct
14 Correct 2 ms 5072 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 3 ms 5200 KB Output is correct
19 Correct 3 ms 5200 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 2 ms 5072 KB Output is correct
23 Correct 2 ms 5072 KB Output is correct
24 Correct 2 ms 5072 KB Output is correct
25 Correct 3 ms 5072 KB Output is correct
26 Correct 2 ms 5072 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Correct 3 ms 5072 KB Output is correct
29 Correct 2 ms 5072 KB Output is correct
30 Correct 2 ms 5072 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 5072 KB Output is correct
34 Correct 2 ms 5072 KB Output is correct
35 Correct 2 ms 5072 KB Output is correct
36 Correct 4 ms 5200 KB Output is correct
37 Correct 3 ms 5328 KB Output is correct
38 Correct 3 ms 5328 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 3 ms 5072 KB Output is correct
41 Correct 2 ms 5072 KB Output is correct
42 Correct 2 ms 5072 KB Output is correct
43 Correct 514 ms 8016 KB Output is correct
44 Incorrect 769 ms 11140 KB 3rd lines differ - on the 1st token, expected: '913758140', found: '943578984'
45 Halted 0 ms 0 KB -