Submission #1042569

#TimeUsernameProblemLanguageResultExecution timeMemory
1042569yanbDigital Circuit (IOI22_circuit)C++17
0 / 100
9 ms7376 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int n, M; vector<int> p, a; vector<vector<int>> ch; vector<int> conv(vector<signed> v) { vector<int> ans(n); for (int i = 0; i < n; i++) ans[i] = v[i]; return ans; } void init(signed n_, signed M_, vector<signed> p_, vector<signed> a_) { n = n_, M = M_, p = conv(p_), a = conv(a_); ch.resize(n + M); for (int i = 1; i < n + M; i++) { ch[p[i]].push_back(i); } } int count_ways(signed l, signed r) { for (int i = l; i <= r; i++) { a[i] = !a[i]; } vector<int> on(n + M), off(n + M); for (int i = n; i < n + M; i++) { if (a[i]) on[i] = 1; else off[i] = 1; } for (int i = n - 1; i >= 0; i--) { if (ch[i].size() == 1) { on[i] = on[ch[i][0]]; off[i] = off[ch[i][0]]; } else { int x1 = on[ch[i][0]], y1 = off[ch[i][0]], x2 = on[ch[i][1]], y2 = off[ch[i][1]]; on[i] = (2 * x1 * x2 + x1 * y2 + y1 * x2) % 1000002022; off[i] = (2 * y1 * y2 + x1 * y2 + y1 * x2) % 1000002022; } } return on[0]; }
#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...