답안 #1057855

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1057855 2024-08-14T06:51:25 Z aykhn 디지털 회로 (IOI22_circuit) C++17
0 / 100
448 ms 12372 KB
#include <bits/stdc++.h>
#include "circuit.h"

using namespace std;

#define int long long

const int MXN = 2e5 + 5;
const int mod = 1e9 + 2022;

int n, m;
vector<int> A, P;
vector<int> adj[MXN];
int dp[2][MXN], lz[MXN];

void calc(int a)
{
  dp[0][a] = dp[1][a] = 0;
  if (adj[a].empty())
  {
    dp[0][a] = A[a] ^ 1;
    dp[1][a] = A[a];
    return;
  }
  int sz = adj[a].size();
  vector<int> dp1(sz + 1, 0);
  dp1[0] = 1;
  for (int &v : adj[a])
  {
    for (int i = sz; i >= 0; i--)
    {
      dp1[i] = (dp1[i] * dp[0][v]) % mod;
      if (i) dp1[i] = (dp1[i] + ((dp1[i - 1] * dp[1][v]) % mod)) % mod;
    }
  }
  for (int i = 0; i <= sz; i++)
  {
    dp[0][a] = (dp[0][a] + (((sz - i) * dp1[i]) % mod)) % mod;
    dp[1][a] = (dp[1][a] +  ((i * dp1[i]) % mod)) % mod;
  }
}

void dfs(int a)
{
  for (int &v : adj[a])
  {
    dfs(v);
  }
  calc(a);
}

int pw = 1;

void init(int32_t N, int32_t M, vector<int32_t> PP, vector<int32_t> AA) 
{
  n = N, m = M;
  for (int32_t &i : PP) P.push_back(i);
  for (int32_t &i : AA) A.push_back(i);
  for (int i = 0; i < N; i++) pw = (pw << 1) % mod;
  reverse(A.begin(), A.end());
  A.resize(N + M, 0);
  reverse(A.begin(), A.end());
  for (int i = 1; i < N + M; i++) adj[(i - 1) / 2].push_back(i);
  dfs(0);
}

void relax(int l, int r, int x)
{
  if (!lz[x]) return;
  swap(dp[0][x], dp[1][x]);
  if (l == r)
  {
    lz[x] = 0;
    return;
  }
  lz[2*x + 1] ^= lz[x], lz[2*x + 2] ^= lz[x];
  lz[x] = 0;
}


void upd(int l, int r, int x, int lx, int rx)
{
  relax(l, r, x);
  if (l > rx || r < lx) return;
  if (l >= lx && r <= rx)
  {
    lz[x] ^= 1;
    relax(l, r, x);
    return;
  }
  int mid = (l + r) >> 1;
  upd(l, mid, 2*x + 1, lx, rx);
  upd(mid + 1, r, 2*x + 2, lx, rx);
  calc(x);
}

int32_t count_ways(int32_t L, int32_t R) {
  upd(0, n + m - 1, 0, L, R);
  assert((dp[1][0] + dp[0][0]) % mod == pw);
  return dp[1][0];
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 9560 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 9560 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 9560 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 448 ms 12372 KB 1st lines differ - on the 1st token, expected: '431985922', found: '394586018'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 448 ms 12372 KB 1st lines differ - on the 1st token, expected: '431985922', found: '394586018'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 9560 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 9560 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 9560 KB 1st lines differ - on the 1st token, expected: '1', found: '0'
2 Halted 0 ms 0 KB -