Submission #779706

#TimeUsernameProblemLanguageResultExecution timeMemory
779706IBoryDigital Circuit (IOI22_circuit)C++17
2 / 100
390 ms8232 KiB
#include "circuit.h" #include <bits/stdc++.h> typedef long long ll; using namespace std; const ll SZ = 1 << 17, MOD = 1'000'002'022; vector<int> G[SZ]; ll N, M, S[SZ], A[SZ], ans; ll DFS(int cur) { ll& ret = S[cur] = G[cur].size(); if (G[cur].empty()) ret = 1; for (int next : G[cur]) { ll c = DFS(next); ret = ret * c % MOD; } return ret; } void DFS2(int cur, ll n) { if (G[cur].empty()) { A[cur] = n; return; } vector<ll> D; for (int next : G[cur]) D.push_back(S[next]); for (int i = (int)D.size() - 2; i >= 0; --i) D[i] = D[i] * D[i + 1] % MOD; ll pref = 1; for (int i = 0; i < G[cur].size(); ++i) { ll t = n * pref % MOD; if (i != (int)G[cur].size() - 1) t = t * D[i + 1] % MOD; DFS2(G[cur][i], t); pref = pref * D[i] % MOD; } } struct Seg { ll T[SZ << 1], P[SZ << 1], Z[SZ << 1]; void Build(int N, int M) { for (int i = SZ; i < SZ + M; ++i) P[i] = A[i - SZ + N]; for (int i = SZ - 1; i >= 0; --i) P[i] = P[i * 2] + P[i * 2 + 1]; } void Push(int n) { if (n < SZ) { Z[n * 2] += Z[n]; Z[n * 2 + 1] += Z[n]; } if (Z[n] & 1) T[n] = P[n] - T[n]; Z[n] = 0; } void Update(int L, int R, int sL = 1, int sR = SZ, int n = 1) { Push(n); if (R < sL || sR < L) return; if (L <= sL && sR <= R) { ans += P[n] - 2LL * T[n]; Z[n]++; Push(n); return; } int mid = (sL + sR) >> 1; Update(L, R, sL, mid, n * 2); Update(L, R, mid + 1, sR, n * 2 + 1); T[n] = T[n * 2] + T[n * 2 + 1]; } } T; void init(int _N, int _M, vector<int> P, vector<int> Q) { N = _N, M = _M; for (int i = 1; i < N + M; ++i) G[P[i]].push_back(i); DFS(0); DFS2(0, 1); T.Build(N, M); for (int i = 0; i < M; ++i) if (Q[i]) T.Update(i + 1, i + 1); } int count_ways(int L, int R) { T.Update(L - N + 1, R - N + 1); ll ret = ans % MOD; return ret; }

Compilation message (stderr)

circuit.cpp: In function 'void DFS2(int, ll)':
circuit.cpp:29:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |  for (int i = 0; i < G[cur].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...