#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 + 2);
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 |
Correct |
2 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Correct |
2 ms |
6744 KB |
Output is correct |
4 |
Correct |
4 ms |
6576 KB |
Output is correct |
5 |
Correct |
1 ms |
6744 KB |
Output is correct |
6 |
Correct |
1 ms |
6744 KB |
Output is correct |
7 |
Correct |
2 ms |
6744 KB |
Output is correct |
8 |
Correct |
2 ms |
6744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
2 ms |
6744 KB |
Output is correct |
3 |
Correct |
1 ms |
6744 KB |
Output is correct |
4 |
Correct |
2 ms |
6744 KB |
Output is correct |
5 |
Correct |
2 ms |
6744 KB |
Output is correct |
6 |
Correct |
3 ms |
6744 KB |
Output is correct |
7 |
Correct |
2 ms |
6744 KB |
Output is correct |
8 |
Correct |
2 ms |
6744 KB |
Output is correct |
9 |
Correct |
2 ms |
6744 KB |
Output is correct |
10 |
Correct |
2 ms |
7000 KB |
Output is correct |
11 |
Correct |
2 ms |
7000 KB |
Output is correct |
12 |
Correct |
2 ms |
6744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Correct |
2 ms |
6744 KB |
Output is correct |
4 |
Correct |
4 ms |
6576 KB |
Output is correct |
5 |
Correct |
1 ms |
6744 KB |
Output is correct |
6 |
Correct |
1 ms |
6744 KB |
Output is correct |
7 |
Correct |
2 ms |
6744 KB |
Output is correct |
8 |
Correct |
2 ms |
6744 KB |
Output is correct |
9 |
Correct |
1 ms |
6488 KB |
Output is correct |
10 |
Correct |
2 ms |
6744 KB |
Output is correct |
11 |
Correct |
1 ms |
6744 KB |
Output is correct |
12 |
Correct |
2 ms |
6744 KB |
Output is correct |
13 |
Correct |
2 ms |
6744 KB |
Output is correct |
14 |
Correct |
3 ms |
6744 KB |
Output is correct |
15 |
Correct |
2 ms |
6744 KB |
Output is correct |
16 |
Correct |
2 ms |
6744 KB |
Output is correct |
17 |
Correct |
2 ms |
6744 KB |
Output is correct |
18 |
Correct |
2 ms |
7000 KB |
Output is correct |
19 |
Correct |
2 ms |
7000 KB |
Output is correct |
20 |
Correct |
2 ms |
6744 KB |
Output is correct |
21 |
Correct |
2 ms |
6744 KB |
Output is correct |
22 |
Correct |
2 ms |
6744 KB |
Output is correct |
23 |
Correct |
2 ms |
6744 KB |
Output is correct |
24 |
Correct |
2 ms |
6744 KB |
Output is correct |
25 |
Correct |
2 ms |
6744 KB |
Output is correct |
26 |
Correct |
2 ms |
6744 KB |
Output is correct |
27 |
Correct |
2 ms |
6740 KB |
Output is correct |
28 |
Correct |
2 ms |
6744 KB |
Output is correct |
29 |
Correct |
1 ms |
6744 KB |
Output is correct |
30 |
Correct |
1 ms |
6576 KB |
Output is correct |
31 |
Correct |
2 ms |
6744 KB |
Output is correct |
32 |
Correct |
2 ms |
6744 KB |
Output is correct |
33 |
Correct |
3 ms |
6988 KB |
Output is correct |
34 |
Correct |
2 ms |
6744 KB |
Output is correct |
35 |
Correct |
2 ms |
6744 KB |
Output is correct |
36 |
Correct |
2 ms |
7000 KB |
Output is correct |
37 |
Correct |
2 ms |
7000 KB |
Output is correct |
38 |
Correct |
2 ms |
7000 KB |
Output is correct |
39 |
Correct |
2 ms |
6744 KB |
Output is correct |
40 |
Correct |
2 ms |
6744 KB |
Output is correct |
41 |
Correct |
2 ms |
6744 KB |
Output is correct |
42 |
Correct |
2 ms |
6744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3038 ms |
8660 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3038 ms |
8660 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
2 ms |
6744 KB |
Output is correct |
3 |
Correct |
1 ms |
6744 KB |
Output is correct |
4 |
Correct |
2 ms |
6744 KB |
Output is correct |
5 |
Correct |
2 ms |
6744 KB |
Output is correct |
6 |
Correct |
3 ms |
6744 KB |
Output is correct |
7 |
Correct |
2 ms |
6744 KB |
Output is correct |
8 |
Correct |
2 ms |
6744 KB |
Output is correct |
9 |
Correct |
2 ms |
6744 KB |
Output is correct |
10 |
Correct |
2 ms |
7000 KB |
Output is correct |
11 |
Correct |
2 ms |
7000 KB |
Output is correct |
12 |
Correct |
2 ms |
6744 KB |
Output is correct |
13 |
Execution timed out |
3038 ms |
8660 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Correct |
2 ms |
6744 KB |
Output is correct |
4 |
Correct |
4 ms |
6576 KB |
Output is correct |
5 |
Correct |
1 ms |
6744 KB |
Output is correct |
6 |
Correct |
1 ms |
6744 KB |
Output is correct |
7 |
Correct |
2 ms |
6744 KB |
Output is correct |
8 |
Correct |
2 ms |
6744 KB |
Output is correct |
9 |
Correct |
1 ms |
6488 KB |
Output is correct |
10 |
Correct |
2 ms |
6744 KB |
Output is correct |
11 |
Correct |
1 ms |
6744 KB |
Output is correct |
12 |
Correct |
2 ms |
6744 KB |
Output is correct |
13 |
Correct |
2 ms |
6744 KB |
Output is correct |
14 |
Correct |
3 ms |
6744 KB |
Output is correct |
15 |
Correct |
2 ms |
6744 KB |
Output is correct |
16 |
Correct |
2 ms |
6744 KB |
Output is correct |
17 |
Correct |
2 ms |
6744 KB |
Output is correct |
18 |
Correct |
2 ms |
7000 KB |
Output is correct |
19 |
Correct |
2 ms |
7000 KB |
Output is correct |
20 |
Correct |
2 ms |
6744 KB |
Output is correct |
21 |
Correct |
2 ms |
6744 KB |
Output is correct |
22 |
Correct |
2 ms |
6744 KB |
Output is correct |
23 |
Correct |
2 ms |
6744 KB |
Output is correct |
24 |
Correct |
2 ms |
6744 KB |
Output is correct |
25 |
Correct |
2 ms |
6744 KB |
Output is correct |
26 |
Correct |
2 ms |
6744 KB |
Output is correct |
27 |
Correct |
2 ms |
6740 KB |
Output is correct |
28 |
Correct |
2 ms |
6744 KB |
Output is correct |
29 |
Correct |
1 ms |
6744 KB |
Output is correct |
30 |
Correct |
1 ms |
6576 KB |
Output is correct |
31 |
Correct |
2 ms |
6744 KB |
Output is correct |
32 |
Correct |
2 ms |
6744 KB |
Output is correct |
33 |
Correct |
3 ms |
6988 KB |
Output is correct |
34 |
Correct |
2 ms |
6744 KB |
Output is correct |
35 |
Correct |
2 ms |
6744 KB |
Output is correct |
36 |
Correct |
2 ms |
7000 KB |
Output is correct |
37 |
Correct |
2 ms |
7000 KB |
Output is correct |
38 |
Correct |
2 ms |
7000 KB |
Output is correct |
39 |
Correct |
2 ms |
6744 KB |
Output is correct |
40 |
Correct |
2 ms |
6744 KB |
Output is correct |
41 |
Correct |
2 ms |
6744 KB |
Output is correct |
42 |
Correct |
2 ms |
6744 KB |
Output is correct |
43 |
Correct |
862 ms |
6744 KB |
Output is correct |
44 |
Correct |
1197 ms |
6744 KB |
Output is correct |
45 |
Correct |
1267 ms |
6840 KB |
Output is correct |
46 |
Correct |
1519 ms |
7000 KB |
Output is correct |
47 |
Correct |
2072 ms |
7000 KB |
Output is correct |
48 |
Correct |
2082 ms |
7000 KB |
Output is correct |
49 |
Correct |
2104 ms |
7000 KB |
Output is correct |
50 |
Correct |
1550 ms |
7000 KB |
Output is correct |
51 |
Correct |
2328 ms |
6940 KB |
Output is correct |
52 |
Correct |
2070 ms |
6944 KB |
Output is correct |
53 |
Correct |
522 ms |
7768 KB |
Output is correct |
54 |
Correct |
2051 ms |
7000 KB |
Output is correct |
55 |
Correct |
2082 ms |
6744 KB |
Output is correct |
56 |
Correct |
2013 ms |
6744 KB |
Output is correct |
57 |
Correct |
2000 ms |
6744 KB |
Output is correct |
58 |
Correct |
2076 ms |
8024 KB |
Output is correct |
59 |
Correct |
2053 ms |
8024 KB |
Output is correct |
60 |
Correct |
2248 ms |
8208 KB |
Output is correct |
61 |
Correct |
1060 ms |
7000 KB |
Output is correct |
62 |
Correct |
1458 ms |
6744 KB |
Output is correct |
63 |
Correct |
1493 ms |
6744 KB |
Output is correct |
64 |
Correct |
2047 ms |
6740 KB |
Output is correct |
65 |
Correct |
513 ms |
6744 KB |
Output is correct |
66 |
Correct |
1646 ms |
7000 KB |
Output is correct |
67 |
Correct |
1698 ms |
7000 KB |
Output is correct |
68 |
Correct |
1651 ms |
7000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Correct |
2 ms |
6744 KB |
Output is correct |
4 |
Correct |
4 ms |
6576 KB |
Output is correct |
5 |
Correct |
1 ms |
6744 KB |
Output is correct |
6 |
Correct |
1 ms |
6744 KB |
Output is correct |
7 |
Correct |
2 ms |
6744 KB |
Output is correct |
8 |
Correct |
2 ms |
6744 KB |
Output is correct |
9 |
Correct |
1 ms |
6488 KB |
Output is correct |
10 |
Correct |
2 ms |
6744 KB |
Output is correct |
11 |
Correct |
1 ms |
6744 KB |
Output is correct |
12 |
Correct |
2 ms |
6744 KB |
Output is correct |
13 |
Correct |
2 ms |
6744 KB |
Output is correct |
14 |
Correct |
3 ms |
6744 KB |
Output is correct |
15 |
Correct |
2 ms |
6744 KB |
Output is correct |
16 |
Correct |
2 ms |
6744 KB |
Output is correct |
17 |
Correct |
2 ms |
6744 KB |
Output is correct |
18 |
Correct |
2 ms |
7000 KB |
Output is correct |
19 |
Correct |
2 ms |
7000 KB |
Output is correct |
20 |
Correct |
2 ms |
6744 KB |
Output is correct |
21 |
Correct |
2 ms |
6744 KB |
Output is correct |
22 |
Correct |
2 ms |
6744 KB |
Output is correct |
23 |
Correct |
2 ms |
6744 KB |
Output is correct |
24 |
Correct |
2 ms |
6744 KB |
Output is correct |
25 |
Correct |
2 ms |
6744 KB |
Output is correct |
26 |
Correct |
2 ms |
6744 KB |
Output is correct |
27 |
Correct |
2 ms |
6740 KB |
Output is correct |
28 |
Correct |
2 ms |
6744 KB |
Output is correct |
29 |
Correct |
1 ms |
6744 KB |
Output is correct |
30 |
Correct |
1 ms |
6576 KB |
Output is correct |
31 |
Correct |
2 ms |
6744 KB |
Output is correct |
32 |
Correct |
2 ms |
6744 KB |
Output is correct |
33 |
Correct |
3 ms |
6988 KB |
Output is correct |
34 |
Correct |
2 ms |
6744 KB |
Output is correct |
35 |
Correct |
2 ms |
6744 KB |
Output is correct |
36 |
Correct |
2 ms |
7000 KB |
Output is correct |
37 |
Correct |
2 ms |
7000 KB |
Output is correct |
38 |
Correct |
2 ms |
7000 KB |
Output is correct |
39 |
Correct |
2 ms |
6744 KB |
Output is correct |
40 |
Correct |
2 ms |
6744 KB |
Output is correct |
41 |
Correct |
2 ms |
6744 KB |
Output is correct |
42 |
Correct |
2 ms |
6744 KB |
Output is correct |
43 |
Execution timed out |
3038 ms |
8660 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |