Submission #1078522

#TimeUsernameProblemLanguageResultExecution timeMemory
1078522ArthuroWichDigital Circuit (IOI22_circuit)C++17
52 / 100
764 ms17236 KiB
#include "circuit.h" #include<bits/stdc++.h> using namespace std; vector<int> adj[200005]; int arr[200005], brr[200005], seg1[4*200005], seg0[4*200005], s[4*200005], dep[200005], mod = 1000002022; void lazypropagate(int n, int l, int r) { if (s[n]) { swap(seg1[n], seg0[n]); if (l != r) { s[2*n] ^= 1; s[2*n+1] ^= 1; } s[n] = 0; } } void build(int n, int l, int r) { if (l == r) { seg1[n] = arr[l]; seg0[n] = brr[l]; } else { int m = (l+r)/2; build(2*n, l, m); build(2*n+1, m+1, r); seg1[n] = seg1[2*n] + seg1[2*n+1]; seg1[n] %= mod; seg0[n] = seg0[2*n] + seg0[2*n+1]; seg0[n] %= mod; } } void update(int n, int l, int r, int a, int b) { lazypropagate(n, l, r); if (b < l || r < a) { return; } else if (a <= l && r <= b) { s[n] = 1; lazypropagate(n, l, r); } else { int m = (l+r)/2; update(2*n, l, m, a, b); update(2*n+1, m+1, r, a, b); seg1[n] = seg1[2*n] + seg1[2*n+1]; seg1[n] %= mod; seg0[n] = seg0[2*n] + seg0[2*n+1]; seg0[n] %= mod; } } int n, m; void dfs(int i) { for (int j : adj[i]) { dep[j] = dep[i]+1; dfs(j); } } void init(int N, int M, vector<int> P, vector<int> A) { n = N, m = M; for (int i = 1; i <= n+m-1; i++) { adj[P[i]].push_back(i); } vector<int> b(n+1, 1); for (int i = 1; i <= n; i++) { b[i] = b[i-1]*2; b[i] %= mod; } dfs(0); for (int i = 0; i < m; i++) { if (A[i]) { arr[i] = b[n-dep[n+i]]; } else { brr[i] = b[n-dep[n+i]]; } } build(1, 0, m-1); } int count_ways(int L, int R) { update(1, 0, m-1, L-n, R-n); return seg1[1]; }
#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...