# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
915222 | Namkhing | 디지털 회로 (IOI22_circuit) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int Max = 2e5 + 1;
const int Mod = 1e9 + 2022;
ll n, m, dp[Max][2];
void update(int node, int left, int right, int idx) {
if (left == idx && right == idx) {
swap(dp[node][0], dp[node][1]);
return;
}
int mid = (left + right) / 2;
int l = node * 2 + 1;
int r = node * 2 + 2;
if (idx <= mid) {
update(l, left, mid, idx);
}
else {
update(r, mid + 1, right, idx);
}
dp[node][0] = dp[l][1] * dp[r][0] + dp[l][0] * dp[r][1] + 2 * dp[l][0] * dp[r][0];
dp[node][1] = dp[l][1] * dp[r][0] + dp[l][0] * dp[r][1] + 2 * dp[l][1] * dp[r][1];
dp[node][0] %= Mod;
dp[node][1] %= Mod;
}
void build(int node, int left, int right, vector<int>& a) {
if (left == right) {
dp[node][A[left]] = 1;
return;
}
int mid = (left + right) / 2;
int l = node * 2 + 1;
int r = node * 2 + 2;
build(l, left, mid, a);
build(r, mid + 1, right, a);
dp[node][0] = dp[l][1] * dp[r][0] + dp[l][0] * dp[r][1] + 2 * dp[l][0] * dp[r][0];
dp[node][1] = dp[l][1] * dp[r][0] + dp[l][0] * dp[r][1] + 2 * dp[l][1] * dp[r][1];
dp[node][0] %= Mod;
dp[node][1] %= Mod;
}
void init(int N, int M, vector<int> P, vector<int> A) {
n = N, m = M;
build(0, 0, M - 1, A);
}
int count_ways(int L, int R) {
update(0, 0, m - 1, L - n);
return dp[0][1];
}