Submission #628883

#TimeUsernameProblemLanguageResultExecution timeMemory
628883c28dnv9q3Digital Circuit (IOI22_circuit)C++17
0 / 100
654 ms3236 KiB
#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; }
#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...