Submission #1030714

#TimeUsernameProblemLanguageResultExecution timeMemory
103071442kangarooDigital Circuit (IOI22_circuit)C++17
100 / 100
771 ms36032 KiB
#include "circuit.h" #include <vector> using namespace std; vector<int> a; using g_t = vector<vector<int>>; g_t g; using ll = long long; constexpr ll mod = 1000002022; struct SVal { ll pos, fpos; }; SVal comb(SVal l, SVal r) { return SVal{(l.pos + r.pos)%mod, (l.fpos + r.fpos)%mod}; } struct SegTe { vector<SVal> a; vector<bool> lazy; void push(int i) { if (lazy[i]) { swap(a[i].pos, a[i].fpos); if (2 * i + 2 < a.size()) { lazy[2 * i + 1] = !lazy[2 * i + 1]; lazy[2 * i + 2] = !lazy[2 * i + 2]; } lazy[i] = false; } } SVal toggle(int l, int r, int i, int lq, int rq) { push(i); if (rq <= l || r <= lq) return a[i]; if (lq <= l && r <= rq) { lazy[i] = true; push(i); return a[i]; } int m = (l + r) / 2; return a[i] = comb(toggle(l, m, 2 * i + 1, lq, rq), toggle(m, r, 2 * i + 2, lq, rq)); } SVal set(int l, int r, int i, int k, int pos, int fpos) { if (k < l || k >= r) return a[i]; if (l + 1 == r) { return a[i] = {pos, fpos}; } int m = (l + r)/2; return a[i] = comb(set(l, m, 2*i + 1, k, pos, fpos), set(m, r, 2*i + 2, k, pos, fpos)); } }; SegTe se; int n, m; ll dfs(int t, vector<vector<ll>>& re) { if (t >= n) return 1; re[t].resize(g[t].size()); ll tot = g[t].size(); for (int i = 0; i < g[t].size(); ++i) { re[t][i] = dfs(g[t][i], re); tot = (tot*re[t][i])%mod; } return tot; } void dfs2(int t, ll to, vector<vector<ll>>& re, vector<ll>& st) { if (t >= n) { st[t - n] = to; return; } vector<ll> suffMu(re[t].size() + 1, 1); for (int i = re[t].size() - 1; i >= 0; --i) { suffMu[i] = (suffMu[i + 1]*re[t][i])%mod; } ll mu = 1; for (int i = 0; i < re[t].size(); ++i) { dfs2(g[t][i], (((to*mu)%mod)*suffMu[i + 1])%mod, re, st); mu = (mu*re[t][i])%mod; } } void init(int N, int M, std::vector<int> P, std::vector<int> A) { n = N; m = M; g = g_t(N); for (int i = 1; i < N + M; ++i) { g[P[i]].push_back(i); } vector<vector<ll>> re(N); dfs(0, re); vector<ll> res(M); dfs2(0, 1, re, res); se = SegTe{vector<SVal>(4*M), vector<bool>(4*M, false)}; for (int i = 0; i < M; ++i) { if (A[i] == 1) { se.set(0, M, 0, i, res[i], 0); } else { se.set(0, M, 0, i, 0, res[i]); } } } int count_ways(int L, int R) { L -= n; R -= n; return se.toggle(0, m, 0, L, R + 1).pos; }

Compilation message (stderr)

circuit.cpp: In member function 'void SegTe::push(int)':
circuit.cpp:30:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<SVal>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |    if (2 * i + 2 < a.size()) {
      |        ~~~~~~~~~~^~~~~~~~~~
circuit.cpp: In function 'll dfs(int, std::vector<std::vector<long long int> >&)':
circuit.cpp:67:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |  for (int i = 0; i < g[t].size(); ++i) {
      |                  ~~^~~~~~~~~~~~~
circuit.cpp: In function 'void dfs2(int, ll, std::vector<std::vector<long long int> >&, std::vector<long long int>&)':
circuit.cpp:84:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |  for (int i = 0; i < re[t].size(); ++i) {
      |                  ~~^~~~~~~~~~~~~~
#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...