Submission #629924

#TimeUsernameProblemLanguageResultExecution timeMemory
629924cadmiumskyDigital Circuit (IOI22_circuit)C++17
100 / 100
1157 ms40028 KiB
#include "circuit.h" #include <bits/stdc++.h> using namespace std; #define int ll using ll = long long; using pii = pair<int,int>; const int nmax = 1e5 + 5, mod = 1e9 + 2022; int n, m; int cost[nmax]; namespace AINT { int aint[nmax * 4], inv[nmax * 4], lazy[nmax * 4]; int init(int node = 1, int cl = 0, int cr = m - 1) { lazy[node] = 0; inv[node] = 0; if(cl == cr) { aint[node] = cost[cl]; return aint[node]; } int mid = cl + cr >> 1; return aint[node] = (init(2 * node, cl, mid) + init(2 * node + 1, mid + 1, cr)) % mod; } void push(int node, bool to) { if(lazy[node]) swap(aint[node], inv[node]); if(to) lazy[node * 2] ^= lazy[node], lazy[node * 2 + 1] ^= lazy[node]; lazy[node] = 0; return; } int upd(int l, int r, int node = 1, int cl = 0, int cr = m - 1) { push(node, cl != cr); if(r < cl || cr < l) return aint[node]; if(l <= cl && cr <= r) { lazy[node] = 1; push(node, cl != cr); //cerr << l << " <= " << cl << ' ' << cr << " <= " << r << '\n'; //cerr << aint[node] << ' ' << inv[node] << "\n\n"; return aint[node]; } int mid = cl + cr >> 1; aint[node] = ((ll)upd(l, r, 2 * node, cl, mid) + upd(l, r, 2 * node + 1, mid + 1, cr)) % mod; inv[node] = ((ll)inv[2 * node] + inv[2 * node + 1]) % mod; return aint[node]; } } vector<int> g[nmax * 2]; int prod[nmax * 2]; void initdfs(int node) { prod[node] = max(1LL, (int)g[node].size()); for(auto x : g[node]) initdfs(x), prod[node] = ((ll)prod[node] * prod[x]) % mod; return; } void initcost(int node, int accum = 1) { if(g[node].size() == 0) { cost[node - n] = accum; return; } vector<int> pref(g[node].size()), suff(g[node].size()); int tmp = 1; for(int i = 0; i < g[node].size(); i++) { pref[i] = tmp; tmp = (ll)tmp * prod[g[node][i]] % mod; } tmp = 1; for(int i = g[node].size() - 1; i >= 0; i--) { suff[i] = tmp; tmp = (ll)tmp * prod[g[node][i]] % mod; } for(int i = 0; i < g[node].size(); i++) { initcost(g[node][i], (ll)accum * pref[i] % mod * suff[i] % mod); } return; } #undef int void init(int N, int M, std::vector<int> P, std::vector<int> A) { #define int ll for(int i = 1; i < N + M; i++) { g[P[i]].push_back(i); } tie(n, m) = pii{N, M}; initdfs(0); initcost(0, 1); AINT::init(); for(int i = 0; i < m; i++) { //cerr << cost[i] << ' '; if(A[i] == 0) AINT::upd(i, i); //cerr << A[i] << ' ' << AINT::aint[1] << '\n'; } //cerr << '\n'; return; } #undef int int count_ways(int L, int R) { return AINT::upd(L - n, R - n); }

Compilation message (stderr)

circuit.cpp: In function 'll AINT::init(ll, ll, ll)':
circuit.cpp:20:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   20 |     int mid = cl + cr >> 1;
      |               ~~~^~~~
circuit.cpp: In function 'll AINT::upd(ll, ll, ll, ll, ll)':
circuit.cpp:43:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   43 |     int mid = cl + cr >> 1;
      |               ~~~^~~~
circuit.cpp: In function 'void initcost(ll, ll)':
circuit.cpp:68:20: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |   for(int i = 0; i < g[node].size(); i++) {
      |                  ~~^~~~~~~~~~~~~~~~
circuit.cpp:77:20: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |   for(int i = 0; i < g[node].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...