Submission #737650

#TimeUsernameProblemLanguageResultExecution timeMemory
737650minhcoolDigital Circuit (IOI22_circuit)C++17
100 / 100
1644 ms29260 KiB
#include "circuit.h" #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define mp make_pair typedef pair<int, int> ii; typedef pair<ii, int> iii; typedef pair<ii, ii> iiii; const int N = 2e5 + 5; const int oo = 1e18 + 7, mod = 1000002022; int n, m; vector<int> Adj[N]; int arr[N]; long long coor[N]; long long pref[N], suff[N]; long long sav[N]; long long weight[N]; void dfs(int u){ if(!Adj[u].size()) return; for(auto v : Adj[u]) dfs(v); pref[0] = coor[Adj[u][0]]; for(int i = 1; i < Adj[u].size(); i++) pref[i] = (pref[i - 1] * coor[Adj[u][i]]) % mod; suff[Adj[u].size()] = 1; for(int i = Adj[u].size() - 1; i >= 0; i--) suff[i] = (suff[i + 1] * coor[Adj[u][i]]) % mod; //for(int i = 0; i < Adj[u].size(); i++) cout << pref[i] << " " << suff[i] << "\n"; coor[u] = (pref[Adj[u].size() - 1] * Adj[u].size()) % mod; //cout << u << " " << coor[u] << "\n"; for(int i = 0; i < Adj[u].size(); i++){ sav[Adj[u][i]] = (i ? pref[i - 1] : 1); sav[Adj[u][i]] = (sav[Adj[u][i]] * suff[i + 1]) % mod; } //for(int i = 0; i <= m; i++) cout << u << " " << i << " " << coor[u][i] << "\n"; } void dfs2(int u, int total){ if(u >= n){ weight[u - n] = total; return; } for(auto v : Adj[u]){ dfs2(v, (total * sav[v]) % mod); } } long long IT[N << 2], tol_weight[N << 2], laz[N << 2]; void build(int id, int l, int r){ if(l == r){ tol_weight[id] = weight[l]; IT[id] = arr[l] * tol_weight[id]; laz[id] = 0; return; } int mid = (l + r) >> 1; build(id << 1, l, mid); build(id << 1 | 1, mid + 1, r); IT[id] = (IT[id << 1] + IT[id << 1 | 1]) % mod; tol_weight[id] = (tol_weight[id << 1] + tol_weight[id << 1 | 1]) % mod; laz[id] = 0; } void lazy(int id){ if(!laz[id]) return; IT[id << 1] = (tol_weight[id << 1] - IT[id << 1] + mod) % mod; IT[id << 1 | 1] = (tol_weight[id << 1 | 1] - IT[id << 1 | 1] + mod) % mod; laz[id << 1] ^= 1; laz[id << 1 | 1] ^= 1; laz[id] = 0; } void upd(int id, int l, int r, int L, int R){ if(l > R || r < L) return; if(l >= L && r <= R){ IT[id] = (tol_weight[id] - IT[id] + mod) % mod; laz[id] ^= 1; return; } lazy(id); int mid = (l + r) >> 1; upd(id << 1, l, mid, L, R); upd(id << 1 | 1, mid + 1, r, L, R); IT[id] = (IT[id << 1] + IT[id << 1 | 1]) % mod; } void init(int N, int M, vector<int> P, vector<int> A){ n = N, m = M; for(int i = 1; i < n + m; i++) Adj[P[i]].pb(i); for(int i = 0; i < m; i++) arr[i] = A[i]; for(int i = n; i < n + m; i++) coor[i] = 1; dfs(0); sav[0] = 1; //for(int i = 1; i < n + m; i++) cout << i << " " << sav[i] << "\n"; dfs2(0, 1); build(1, 0, m - 1); //for(int i = 0; i < m; i++) cout << coor[0][i] << " "; //cout << "\n"; } int count_ways(int L, int R){ L -= n, R -= n; upd(1, 0, m - 1, L, R); long long temp = IT[1]; int temp2 = temp; return temp2; /* for(int i = L; i <= R; i++) arr[i] ^= 1; long long ans = 0; for(int i = 0; i < m; i++) if(arr[i]) ans += coor[0][i]; ans %= mod; int ans2 = ans; return ans2;*/ }

Compilation message (stderr)

circuit.cpp:16:21: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   16 | const int oo = 1e18 + 7, mod = 1000002022;
      |                ~~~~~^~~
circuit.cpp: In function 'void dfs(int)':
circuit.cpp:33:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |  for(int i = 1; i < Adj[u].size(); i++) pref[i] = (pref[i - 1] * coor[Adj[u][i]]) % mod;
      |                 ~~^~~~~~~~~~~~~~~
circuit.cpp:39:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |  for(int i = 0; i < Adj[u].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...