답안 #628883

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
628883 2022-08-13T19:00:41 Z c28dnv9q3 디지털 회로 (IOI22_circuit) C++17
0 / 100
654 ms 3236 KB
#include "circuit.h"
#include <vector>
#include <cstdio>

using namespace std;
using ll = long long;

// N ... num threshold gates
// M ... num source gates

vector<int> A;
int N, M;
const int MOD = 1000002022;

struct segtree {
  ll v, tot;
};

vector<segtree> tree;
ll mmod(ll v) {
  return ((v % MOD) + MOD) % MOD;
}

void init_tree(int i, int l, int r) {
  if (l+1 == r) {
    tree[i].v = A[l];
    tree[i].tot = 1;
    return;
  }
  int m = (l+r)/2;
  init_tree(2*i, l, m);
  init_tree(2*i+1, m, r);
  tree[i].tot = (2LL * tree[2*i].tot * tree[2*i+1].tot) % MOD;
  auto x = tree[2*i];
  auto y = tree[2*i+1];
  tree[i].v = mmod(
    x.v * mmod(y.tot - y.v)
    + y.v * mmod(x.tot - x.v)
    + x.v * y.v
  );
}
void update_tree(int i, int l, int r, int q) {
  if (q < l || q >= r) return;
  if (l+1 == r) {
    tree[i].v ^= 1;
    // printf("update LEAF %d (i=%d) -> %lld\n", l, i, tree[i].v);
    return;
  }
  int m = (l+r)/2;
  update_tree(2*i, l, m, q);
  update_tree(2*i+1, m, r, q);
  auto x = tree[2*i];
  auto y = tree[2*i+1];
  tree[i].v = mmod(
    x.v * mmod(y.tot - y.v)
    + y.v * mmod(x.tot - x.v)
    + 2 * x.v * y.v
  );
  // printf("update v %d -> %lld\n", i, tree[i].v);
}

void init(int N, int M, vector<int> P, vector<int> A) {
  ::A = A;
  ::N = N;
  ::M = M;
  tree.resize(4*N);
  init_tree(1, 0, M);
}

// toggle state of source gates between L and R (inclusive)
// return num distinctive param assignments with gate#0 = 1
int count_ways(int L, int R) {
  for (int i = L; i <= R; i++)
    update_tree(1, 0, M, i-N);
  
  return tree[1].v;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Runtime error 1 ms 464 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Incorrect 1 ms 256 KB 1st lines differ - on the 1st token, expected: '52130940', found: '237029892'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Runtime error 1 ms 464 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 654 ms 3236 KB 1st lines differ - on the 1st token, expected: '431985922', found: '22358198'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 654 ms 3236 KB 1st lines differ - on the 1st token, expected: '431985922', found: '22358198'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Incorrect 1 ms 256 KB 1st lines differ - on the 1st token, expected: '52130940', found: '237029892'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Runtime error 1 ms 464 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Runtime error 1 ms 464 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -