Submission #630141

#TimeUsernameProblemLanguageResultExecution timeMemory
630141flashmtDigital Circuit (IOI22_circuit)C++17
100 / 100
1158 ms34328 KiB
#include <bits/stdc++.h> #include "circuit.h" using namespace std; const int BASE = 1e9 + 2022; const int N = 200200; struct SegmentTree { int low, mid, high; long long value, sum; int flip; SegmentTree *l, *r; SegmentTree(int low, int high, vector<long long> &coef, vector<int> &state): low(low), high(high) { mid = (low + high) / 2; value = sum = flip = 0; if (low == high) { l = r = NULL; sum = coef[low]; value = state[low] * sum; } else { l = new SegmentTree(low, mid, coef, state); r = new SegmentTree(mid + 1, high, coef, state); sum = l->sum + r->sum; value = l->value + r->value; } } void update(int x, int y) { if (low == x && high == y) { value = sum - value; flip ^= 1; return; } if (x <= mid) l->update(x, min(y, mid)); if (mid < y) r->update(max(x, mid + 1), y); value = l->value + r->value; if (flip) value = sum - value; } }; int n; vector<int> a[N]; vector<long long> coef, ways; SegmentTree *tree; void dfsWay(int x) { if (empty(a[x])) return; for (int y : a[x]) { dfsWay(y); ways[x] *= ways[y]; ways[x] %= BASE; } ways[x] *= size(a[x]); ways[x] %= BASE; } void dfsCoef(int x) { vector<long long> prefix(size(a[x])); for (int i = 0; i < size(a[x]); i++) { prefix[i] = ways[a[x][i]]; if (i) prefix[i] = prefix[i] * prefix[i - 1] % BASE; } long long suffix = 1; for (int i = int(size(a[x])) - 1; i >= 0; i--) { int y = a[x][i]; coef[y] = suffix; if (i) coef[y] = coef[y] * prefix[i - 1] % BASE; suffix *= ways[y]; suffix %= BASE; } for (int y : a[x]) { coef[y] = coef[y] * coef[x] % BASE; dfsCoef(y); } } void init(int N, int m, vector<int> P, vector<int> A) { n = N; for (int i = 1; i < n + m; i++) a[P[i]].push_back(i); ways.assign(n + m, 1); dfsWay(0); coef.assign(n + m, 1); dfsCoef(0); for (int i = 0; i < m; i++) coef[i] = coef[i + n]; coef.resize(m); tree = new SegmentTree(0, m - 1, coef, A); } int count_ways(int L, int R) { tree->update(L - n, R - n); return int(tree->value % BASE); }

Compilation message (stderr)

circuit.cpp: In function 'void dfsCoef(int)':
circuit.cpp:73:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   73 |   for (int i = 0; i < size(a[x]); 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...