답안 #767413

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
767413 2023-06-26T18:14:03 Z t6twotwo 디지털 회로 (IOI22_circuit) C++17
컴파일 오류
0 ms 0 KB
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int mod = 1000002022;
int add(int x, int y) {
    int z = x + y;
    if (z >= mod) {
        z -= mod;
    }
    return z;
}
int sub(int x, int y) {
    int z = x - y;
    if (z < 0) {
        z += mod;
    }
    return z;
}
int mul(int x, int y) {
    return (ll)x * y % mod;
}
int N, M;
vector<int> P, A, tot, dp;
void init(int n, int m, vector<int> p, vector<int> a) {
    N = n, M = m;
    P = p, A = a;
    if (M == N + 1 && (1 << __lg(M)) == M) {
        tot.resize(N + M);
        dp.resize(N + M);
        for (int i = 0; i < M; i++) {
            dp[i + N] = A[i];
            tot[i + N] = 1;
        }
        for (int i = N - 1; i >= 0; i--) {
            int x = i * 2 + 1;
            int y = i * 2 + 2;
            dp[i] = add(mul(dp[x], tot[y]), mul(dp[y], tot[x]));
            tot[i] = mul(2, mul(tot[x], tot[y]));
        }
    }
}
void update(int p, int l, int r) {
    if (r - l == 1) {
        dp[p] = sub(tot[p], dp[p]);
        return;
    }
    int m = (l + r + 1) / 2;
    if (L - N < m) {
        update(p * 2 + 1, l, m);
    } else {
        update(p * 2 + 2, m, r);
    }
    dp[p] = add(mul(dp[p * 2 + 1], tot[p * 2 + 2]), mul(dp[p * 2 + 2], tot[p * 2 + 1]));
}
int count_ways(int L, int R) {
    if (N <= 1000 && M <= 1000) {
        vector dp(N, vector{1});
        vector<int> on(N + M), off(N + M), tot(N + M, 1);
        for (int i = L; i <= R; i++) {
            A[i - N] ^= 1;
        }
        for (int i = N + M - 1; i >= 0; i--) {
            if (i >= N) {
                on[i] = A[i - N];
                off[i] = tot[i] - on[i];
            } else {
                int sum = 0;
                for (int j = dp[i].size() - 1; j; j--) {
                    sum = add(sum, dp[i][j]);
                    on[i] = add(on[i], sum);
                }
                tot[i] = mul(tot[i], (int)dp[i].size() - 1);
                off[i] = sub(tot[i], on[i]);
            }
            if (i) {
                int K = dp[P[i]].size();
                dp[P[i]].resize(K + 1);
                for (int j = K; j; j--) {
                    dp[P[i]][j] = add(mul(dp[P[i]][j], off[i]), mul(dp[P[i]][j - 1], on[i]));
                }
                dp[P[i]][0] = mul(dp[P[i]][0], off[i]);
                tot[P[i]] = mul(tot[P[i]], tot[i]);
            }
        }
        return on[0];
    }
    update(0, 0, M);
    return dp[0];
}

Compilation message

circuit.cpp: In function 'void update(int, int, int)':
circuit.cpp:49:9: error: 'L' was not declared in this scope
   49 |     if (L - N < m) {
      |         ^