Submission #767441

#TimeUsernameProblemLanguageResultExecution timeMemory
767441t6twotwoDigital Circuit (IOI22_circuit)C++17
34 / 100
891 ms5068 KiB
#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, lazy, S, len; void apply(int p, int v) { if (v) { S[p] = len[p] - S[p]; } lazy[p] ^= v; } void push(int p) { apply(p * 2 + 1, lazy[p]); apply(p * 2 + 2, lazy[p]); lazy[p] = 0; } void pull(int p) { S[p] = S[p * 2 + 1] + S[p * 2 + 2]; } void update(int p, int l, int r, int L, int R) { if (R <= l || r <= L) { return; } if (L <= l && r <= R) { apply(p, 1); return; } int m = (l + r + 1) / 2; push(p); update(p * 2 + 1, l, m, L, R); update(p * 2 + 2, m, r, L, R); pull(p); } int T; 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) { S.resize(N + M); tot.resize(N + M); len.resize(N + M); lazy.resize(N + M); for (int i = N; i < N + M; i++) { S[i] = A[i - N]; len[i] = 1; tot[i] = 1; } for (int i = N - 1; i >= 0; i--) { len[i] = len[i * 2 + 1] + len[i * 2 + 2]; S[i] = S[i * 2 + 1] + S[i * 2 + 2]; tot[i] = mul(2, mul(tot[i * 2 + 1], tot[i * 2 + 2])); } T = 1; int x = N; while (x > 0) { T = mul(T, tot[x]); x = (x - 1) / 2; } } } 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, L - N, R - N + 1); return mul(S[0], T); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...