This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "circuit.h"
#include "bits/stdc++.h"
using namespace std;
#define int long long
#include <vector>
const int MAXN = 2e5 + 12;
const int MOD = 1e9 + 2022;
int n, m;
vector<int> adj[MAXN];
int contrib[MAXN];
int ans;
int a[MAXN];
int lazy[MAXN];
int Y[MAXN];
void calc_y(int node) {
Y[node] = adj[node].size();
Y[node] = max(1ll, Y[node]);
for(int x: adj[node]) {
calc_y(x);
Y[node] *= Y[x];
Y[node] %= MOD;
}
}
void propagate(int node) {
for(int x: adj[node]) {
lazy[x] *= lazy[node];
lazy[x] %= MOD;
propagate(x);
}
}
void init(int32_t N, int32_t M, std::vector<int32_t> P, std::vector<int32_t> A) {
for(int i=0; i<M; i++) contrib[i] = 1;
for(int i=1; i<N+M; i++) adj[P[i]].push_back(i);
for(int i=0; i<M; i++) a[i] = A[i];
n = N;
m = M;
ans = 0;
calc_y(0);
for(int i=0; i<N+M; i++) lazy[i] = 1;
for(int i=0; i<N; i++) {
for(int x: adj[i]) {
for(int y: adj[i]) {
if(x != y) {
lazy[y] *= Y[x];
lazy[y] %= MOD;
}
}
}
}
propagate(0);
for(int i=0; i<N+M; i++) {
contrib[i] = lazy[i];
}
}
int32_t count_ways(int32_t L, int32_t R) {
L -= n;
R -= n;
for(int i=L; i<=R; i++) {
a[i] ^= 1;
}
int ans = 0;
for(int i=0; i<m; i++) {
if(a[i]) ans = (ans + contrib[n+i]) % MOD;
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |