#include "circuit.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define pb push_back
const ll MOD = 1e9 + 2022;
void chadd(ll &x, ll y) { x = (x + y) % MOD; }
void chmul(ll &x, ll y) { x = (x * y) % MOD; }
const int mxN = 2e5 + 10;
vector<int> adj[mxN];
int n, m;
bool state[mxN];
ll contrib[mxN];
void dfs1(int u = 0) {
if (u >= n) {
contrib[u] = 1; return;
}
contrib[u] = adj[u].size();
for (int v : adj[u]) {
dfs1(v);
chmul(contrib[u], contrib[v]);
}
}
void dfs2(int u = 0, ll pass = 1) {
if (u >= n) {
contrib[u] = pass;
return;
}
int sz = adj[u].size();
vector<ll> pref(sz + 2), suff(sz + 1);
pref[0] = 1;
for (int i = 1; i <= sz; i++) {
pref[i] = pref[i - 1];
chmul(pref[i], contrib[adj[u][i - 1]]);
}
suff[sz + 1] = 1;
for (int i = sz; i >= 1; i--) {
suff[i] = suff[i + 1];
chmul(suff[i], contrib[adj[u][i - 1]]);
}
for (int i = 1; i <= sz; i++) {
ll nxt = pass;
chmul(nxt, pref[i - 1]);
chmul(nxt, suff[i + 1]);
dfs2(adj[u][i - 1], nxt);
}
}
void init(int N, int M, vector<int> P, vector<int> A) {
n = N; m = M;
for (int i = 1; i < (int)(P.size()); i++) adj[P[i]].pb(i);
for (int i = 0; i < (int)(A.size()); i++) state[n + i] = A[i];
dfs1();
// for (int i = 0; i < n + m; i++) cerr << contrib[i] << ' ';
// cerr << endl;
dfs2();
// for (int i = n; i < n + m; i++) cerr << contrib[i] << ' ';
// cerr << endl;
}
int count_ways(int L, int R) {
for (int i = L; i <= R; i++) state[i] ^= 1;
ll ans = 0;
for (int i = n; i < n + m; i++) {
if (state[i]) chadd(ans, contrib[i]);
}
return (int)(ans);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
6 ms |
13144 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
7 ms |
13144 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
6 ms |
13144 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
18 ms |
17104 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
18 ms |
17104 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
7 ms |
13144 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
6 ms |
13144 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
6 ms |
13144 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |