제출 #1128956

#제출 시각아이디문제언어결과실행 시간메모리
1128956vladilius디지털 회로 (IOI22_circuit)C++20
89 / 100
3057 ms23528 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; #define pb push_back #define ff first #define ss second const int mod = 1000002022; vector<vector<int>> g; vector<int> a; int n, m; vector<int> P; void dfs1(int v){ P[v] = (int) g[v].size(); if (!P[v]) P[v] = 1; for (int i: g[v]){ dfs1(i); P[v] = (1LL * P[v] * P[i]) % mod; } } vector<int> f; void dfs2(int v){ for (int i: g[v]){ int x = 1; for (int j: g[v]){ if (j != i){ x = (1LL * x * P[j]) % mod; } } f[i] = (1LL * f[v] * x) % mod; dfs2(i); } } struct node{ int s, X; }; vector<node> t; vector<bool> p; void build(int v, int tl, int tr){ if (tl == tr){ t[v].X = f[tl + n - 1]; t[v].s = a[tl - 1] * t[v].X; return; } int tm = (tl + tr) / 2, vv = 2 * v; build(vv, tl, tm); build(vv + 1, tm + 1, tr); t[v].s = (t[vv].s + t[vv + 1].s) % mod; t[v].X = (t[vv].X + t[vv + 1].X) % mod; } void push(int& v){ if (!p[v]) return; int vv = 2 * v; t[vv].s = (t[vv].X - t[vv].s) % mod; if (t[vv].s < 0) t[vv].s += mod; t[vv + 1].s = (t[vv + 1].X - t[vv + 1].s) % mod; if (t[vv + 1].s < 0) t[vv + 1].s += mod; p[vv] = !p[vv]; p[vv + 1] = !p[vv + 1]; p[v] = 0; } void upd(int v, int tl, int tr, int& l, int& r){ if (l > tr || r < tl) return; if (l <= tl && tr <= r){ t[v].s = (t[v].X - t[v].s) % mod; if (t[v].s < 0) t[v].s += mod; p[v] = !p[v]; return; } int tm = (tl + tr) / 2, vv = 2 * v; push(v); upd(vv, tl, tm, l, r); upd(vv + 1, tm + 1, tr, l, r); t[v].s = (t[vv].s + t[vv + 1].s) % mod; } void upd(int l, int r){ upd(1, 1, m, l, r); } int count_ways(int l, int r){ l = (l - n + 1); r = (r - n + 1); upd(l, r); return t[1].s; } void init(int N, int M, vector<int> pr, vector<int> A){ n = N; m = M; a = A; g.resize(n + m); for (int i = 1; i < n + m; i++){ g[pr[i]].pb(i); } P.resize(n + m); dfs1(0); f.resize(n + m); f[0] = 1; dfs2(0); t.resize(4 * m); p.resize(4 * m); build(1, 1, m); }
#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...