Submission #820189

# Submission time Handle Problem Language Result Execution time Memory
820189 2023-08-11T00:45:10 Z maeola Digital Circuit (IOI22_circuit) C++17
2 / 100
719 ms 11300 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;
                        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];
}
# 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 3 ms 5120 KB Output is correct
4 Correct 2 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 2 ms 5072 KB Output is correct
7 Correct 2 ms 5072 KB Output is correct
8 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 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 2 ms 5008 KB Output is correct
5 Incorrect 2 ms 5072 KB 1st lines differ - on the 1st token, expected: '655368480', found: '-344633542'
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 3 ms 5120 KB Output is correct
4 Correct 2 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 2 ms 5072 KB Output is correct
7 Correct 2 ms 5072 KB Output is correct
8 Correct 2 ms 5072 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 2 ms 4944 KB Output is correct
11 Correct 3 ms 5072 KB Output is correct
12 Correct 2 ms 5008 KB Output is correct
13 Incorrect 2 ms 5072 KB 1st lines differ - on the 1st token, expected: '655368480', found: '-344633542'
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 465 ms 8060 KB Output is correct
2 Incorrect 719 ms 11300 KB 3rd lines differ - on the 1st token, expected: '913758140', found: '943578984'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 465 ms 8060 KB Output is correct
2 Incorrect 719 ms 11300 KB 3rd lines differ - on the 1st token, expected: '913758140', found: '943578984'
3 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 3 ms 5072 KB Output is correct
4 Correct 2 ms 5008 KB Output is correct
5 Incorrect 2 ms 5072 KB 1st lines differ - on the 1st token, expected: '655368480', found: '-344633542'
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 3 ms 5120 KB Output is correct
4 Correct 2 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 2 ms 5072 KB Output is correct
7 Correct 2 ms 5072 KB Output is correct
8 Correct 2 ms 5072 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 2 ms 4944 KB Output is correct
11 Correct 3 ms 5072 KB Output is correct
12 Correct 2 ms 5008 KB Output is correct
13 Incorrect 2 ms 5072 KB 1st lines differ - on the 1st token, expected: '655368480', found: '-344633542'
14 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 3 ms 5120 KB Output is correct
4 Correct 2 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 2 ms 5072 KB Output is correct
7 Correct 2 ms 5072 KB Output is correct
8 Correct 2 ms 5072 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 2 ms 4944 KB Output is correct
11 Correct 3 ms 5072 KB Output is correct
12 Correct 2 ms 5008 KB Output is correct
13 Incorrect 2 ms 5072 KB 1st lines differ - on the 1st token, expected: '655368480', found: '-344633542'
14 Halted 0 ms 0 KB -