Submission #820163

# Submission time Handle Problem Language Result Execution time Memory
820163 2023-08-10T21:52:11 Z wenqi Digital Circuit (IOI22_circuit) C++17
0 / 100
523 ms 7248 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)
{
        choices[i] = max<int>(1, 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++)
                dfs2(adj[i][j], 1ll * (j ? l[j - 1] : 1) * (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++)
        {
                // cerr << i << ' ' << coef[i + N] << endl;
                ans += A[i] * coef[i + N];
                ans %= mod;
        }
}

int count_ways(int L, int R)
{
        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 Incorrect 2 ms 4944 KB 2nd lines differ - on the 1st token, expected: '2', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4944 KB 2nd lines differ - on the 1st token, expected: '2', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4944 KB 2nd lines differ - on the 1st token, expected: '2', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 523 ms 7248 KB 1st lines differ - on the 1st token, expected: '431985922', found: '16401'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 523 ms 7248 KB 1st lines differ - on the 1st token, expected: '431985922', found: '16401'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4944 KB 2nd lines differ - on the 1st token, expected: '2', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4944 KB 2nd lines differ - on the 1st token, expected: '2', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4944 KB 2nd lines differ - on the 1st token, expected: '2', found: '1'
2 Halted 0 ms 0 KB -