제출 #826145

#제출 시각아이디문제언어결과실행 시간메모리
826145PixelCatDigital Circuit (IOI22_circuit)C++17
0 / 100
438 ms8600 KiB
#include "circuit.h" #ifdef NYAOWO #include "stub.cpp" #endif #include <bits/stdc++.h> #define For(i, a, b) for(int i = a; i <= b; i++) #define Forr(i, a, b) for(int i = a; i >= b; i--) #define F first #define S second #define all(x) x.begin(), x.end() #define sz(x) ((int)x.size()) #define eb emplace_back #define int LL using namespace std; using i32 = int32_t; using LL = long long; using pii = pair<int, int>; const int MAXN = 200'000; const int MOD = 1'000'002'022; int n, m; vector<int> adj[MAXN + 10]; int p[MAXN + 10]; // int dp[MAXN + 10][2]; int a[MAXN + 10]; // int flip[MAXN + 10]; // void update(int x) { // if(x >= n) { // dp[x][a[x]] = 1; // dp[x][1 - a[x]] = 0; // if(flip[x]) swap(dp[x][0], dp[x][1]); // return; // } // vector<int> v(1, 1); // for(auto &child:adj[x]) { // vector<int> v2; // v2.eb(v[0] * dp[child][0] % MOD); // For(i, 1, sz(v) - 1) { // v2.eb((v[i] * dp[child][0] + v[i - 1] * dp[child][1]) % MOD); // } // v2.eb(v.back() * dp[child][1] % MOD); // v.swap(v2); // } // dp[x][0] = dp[x][1] = 0; // int c = sz(adj[x]); // For(i, 0, c) { // dp[x][0] = (dp[x][0] + v[i] * (c - i)) % MOD; // dp[x][1] = (dp[x][1] + v[i] * i) % MOD; // } // if(flip[x]) swap(dp[x][0], dp[x][1]); // } int s[MAXN + 10]; int xs[MAXN + 10]; void dfs(int x) { if(x >= n) { s[x] = 1; return; } xs[x] = 0; s[x] = sz(adj[x]); for(auto &i:adj[x]) { dfs(i); s[x] = s[x] * s[i] % MOD; xs[x] ^= s[i]; } } int ss[MAXN + 10]; void dfs2(int x, int owo) { if(x >= n) { ss[x] = owo; return; } for(auto &i:adj[x]) { dfs2(i, (owo * (xs[x] ^ s[i])) % MOD); } } int ans = 0; void add(int pos, int val) { ans = ((ans + ss[pos] * val) % MOD + MOD) % MOD; } void init(i32 N, i32 M, std::vector<i32> P, std::vector<i32> A) { n = N; m = M; p[0] = -1; For(i, 1, n + m - 1) { adj[P[i]].eb(i); p[i] = P[i]; } dfs(0); dfs2(0, 1); For(i, 0, m - 1) { a[n + i] = A[i]; if(A[i]) add(i, 1); } // Forr(i, n + m - 1, 0) update(i); } // #define L(id) ((id) * 2 + 1) // #define R(id) ((id) * 2 + 2) // void range_flip(int id, int l, int r, int L, int R) { // if(l >= L && r <= R) { // flip[id] ^= 1; // update(id); // // cerr << id << " " << l << " " << r << " " << dp[id][1] << dp[id][0] << "\n"; // return; // } // int mi = (l + r) / 2; // if(L <= mi) range_flip(L(id), l, mi, L, R); // if(R > mi) range_flip(R(id), mi + 1, r, L, R); // update(id); // } i32 count_ways(i32 L, i32 R) { For(i, L, R) { int na = 1 - a[i]; add(i, na - a[i]); a[i] = na; } return (i32)ans; // int i = L; // swap(dp[i][0], dp[i][1]); // i = p[i]; // while(i >= 0) { // update(i); // i = p[i]; // } // range_flip(0, n, n + m - 1, L, R); // return (i32)dp[0][1]; } /* 3 4 3 -1 0 1 2 1 1 0 1 0 1 0 3 4 4 5 3 6 2 0 6 */
#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...