Submission #797585

#TimeUsernameProblemLanguageResultExecution timeMemory
797585jakobrsDigital Circuit (IOI22_circuit)C++17
7 / 100
3154 ms1656640 KiB
#include <iostream> #include <vector> using i64 = int64_t; int n, m; std::vector<int> p, a; std::vector<std::vector<int>> children; const i64 MOD = 1'000'002'022; void init(int N, int M, std::vector<int> P, std::vector<int> A) { n = N; m = M; p = P; a = A; children.resize(N); for (i64 i = 1; i < N + M; i++) { children[P[i]].push_back(i); } } auto dfs(int node) -> std::pair<i64, i64> { if (node >= n) { return {a[node - n] ? 1 : 0, 1}; } auto [a1, ax] = dfs(children[node][0]); auto [b1, bx] = dfs(children[node][1]); return {(a1 * bx + ax * b1) % MOD, ax * bx * 2 % MOD}; } int count_ways(int l, int r) { r += 1; l -= n; r -= n; for (i64 i = l; i < r; i++) { a[i] = !a[i]; } return dfs(0).first; }
#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...