#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) begin(a), end(a)
using vi = vector<int>;
using ll = long long;
using ar2 = array<ll,2>;
const int mxN = (int)5e3+10;
const int MOD = 1000002022;
int n, m;
vi a, p;
vi adj[mxN*2];
vector<ll> dp[mxN][2];
ar2 dfs(int s, int p){
if(sz(adj[s])==0){
if(a[s-n]==1) return {0,1};
return {1,0};
}
vector<ar2> v; v.clear();
for(auto u : adj[s]){
if(u==p) continue;
v.pb(dfs(u,s));
}
int k = sz(v);
dp[s][0].clear(), dp[s][1].clear();
dp[s][0].resize(k+1,0);
dp[s][1].resize(k+1,0);
vector<vector<ll>> num(k+1,vector<ll>(k+1,0));
num[0][0] = 1;
for(int i = 1; i <= k; i++){
for(int j = 0; j <= k; j++){
num[i][j]+=(num[i-1][j]*v[i-1][0])%MOD, num[i][j]%=MOD;
if(j) num[i][j]+=(num[i-1][j-1]*v[i-1][1])%MOD, num[i][j]%=MOD;
}
}
for(int i = 1; i <= k; i++)
num[k][i]+=num[k][i-1];
for(int i = 1; i <= k; i++){
dp[s][0][i]+=num[k][i-1];
dp[s][1][i]+=num[k][k]-num[k][i-1];
for(int j:{0,1}) dp[s][j][i]%=MOD;
}
int num0 = 0, num1 = 0;
for(int i = 1; i <= k; i++){
num0+=dp[s][0][i], num1+=dp[s][1][i];
num0%=MOD, num1%=MOD;
}
return {num0, num1};
}
void init(int N, int M, vi P, vi A) {
n = N, m = M;
for(auto u : P) p.pb(u);
for(auto u : A) a.pb(u);
for(int i = 1; i < n+m; i++)
adj[p[i]].pb(i);
}
int count_ways(int L, int R) {
for(int i = L; i <= R; i++) a[i-n]^=1;
return dfs(0,-1)[1];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
856 KB |
Output is correct |
2 |
Correct |
0 ms |
856 KB |
Output is correct |
3 |
Correct |
32 ms |
8436 KB |
Output is correct |
4 |
Correct |
58 ms |
8848 KB |
Output is correct |
5 |
Correct |
34 ms |
8804 KB |
Output is correct |
6 |
Correct |
37 ms |
8808 KB |
Output is correct |
7 |
Correct |
36 ms |
8872 KB |
Output is correct |
8 |
Correct |
35 ms |
8804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
856 KB |
Output is correct |
2 |
Correct |
0 ms |
856 KB |
Output is correct |
3 |
Correct |
1 ms |
852 KB |
Output is correct |
4 |
Correct |
1 ms |
856 KB |
Output is correct |
5 |
Correct |
1 ms |
856 KB |
Output is correct |
6 |
Correct |
1 ms |
856 KB |
Output is correct |
7 |
Correct |
2 ms |
856 KB |
Output is correct |
8 |
Correct |
2 ms |
856 KB |
Output is correct |
9 |
Correct |
1 ms |
856 KB |
Output is correct |
10 |
Correct |
3 ms |
1112 KB |
Output is correct |
11 |
Correct |
3 ms |
1112 KB |
Output is correct |
12 |
Correct |
1 ms |
856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
856 KB |
Output is correct |
2 |
Correct |
0 ms |
856 KB |
Output is correct |
3 |
Correct |
32 ms |
8436 KB |
Output is correct |
4 |
Correct |
58 ms |
8848 KB |
Output is correct |
5 |
Correct |
34 ms |
8804 KB |
Output is correct |
6 |
Correct |
37 ms |
8808 KB |
Output is correct |
7 |
Correct |
36 ms |
8872 KB |
Output is correct |
8 |
Correct |
35 ms |
8804 KB |
Output is correct |
9 |
Correct |
0 ms |
856 KB |
Output is correct |
10 |
Correct |
0 ms |
856 KB |
Output is correct |
11 |
Correct |
1 ms |
852 KB |
Output is correct |
12 |
Correct |
1 ms |
856 KB |
Output is correct |
13 |
Correct |
1 ms |
856 KB |
Output is correct |
14 |
Correct |
1 ms |
856 KB |
Output is correct |
15 |
Correct |
2 ms |
856 KB |
Output is correct |
16 |
Correct |
2 ms |
856 KB |
Output is correct |
17 |
Correct |
1 ms |
856 KB |
Output is correct |
18 |
Correct |
3 ms |
1112 KB |
Output is correct |
19 |
Correct |
3 ms |
1112 KB |
Output is correct |
20 |
Correct |
1 ms |
856 KB |
Output is correct |
21 |
Correct |
2 ms |
856 KB |
Output is correct |
22 |
Correct |
1 ms |
856 KB |
Output is correct |
23 |
Correct |
1 ms |
856 KB |
Output is correct |
24 |
Correct |
3 ms |
856 KB |
Output is correct |
25 |
Correct |
2 ms |
856 KB |
Output is correct |
26 |
Correct |
2 ms |
856 KB |
Output is correct |
27 |
Correct |
2 ms |
856 KB |
Output is correct |
28 |
Correct |
2 ms |
856 KB |
Output is correct |
29 |
Correct |
35 ms |
8804 KB |
Output is correct |
30 |
Correct |
59 ms |
8804 KB |
Output is correct |
31 |
Correct |
1 ms |
1112 KB |
Output is correct |
32 |
Correct |
2 ms |
856 KB |
Output is correct |
33 |
Correct |
2 ms |
856 KB |
Output is correct |
34 |
Correct |
1 ms |
856 KB |
Output is correct |
35 |
Correct |
7 ms |
1348 KB |
Output is correct |
36 |
Correct |
2 ms |
1112 KB |
Output is correct |
37 |
Correct |
39 ms |
9160 KB |
Output is correct |
38 |
Correct |
34 ms |
9140 KB |
Output is correct |
39 |
Correct |
1 ms |
856 KB |
Output is correct |
40 |
Correct |
2 ms |
856 KB |
Output is correct |
41 |
Correct |
1 ms |
856 KB |
Output is correct |
42 |
Correct |
2 ms |
856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
9 ms |
4352 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
9 ms |
4352 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
856 KB |
Output is correct |
2 |
Correct |
0 ms |
856 KB |
Output is correct |
3 |
Correct |
1 ms |
852 KB |
Output is correct |
4 |
Correct |
1 ms |
856 KB |
Output is correct |
5 |
Correct |
1 ms |
856 KB |
Output is correct |
6 |
Correct |
1 ms |
856 KB |
Output is correct |
7 |
Correct |
2 ms |
856 KB |
Output is correct |
8 |
Correct |
2 ms |
856 KB |
Output is correct |
9 |
Correct |
1 ms |
856 KB |
Output is correct |
10 |
Correct |
3 ms |
1112 KB |
Output is correct |
11 |
Correct |
3 ms |
1112 KB |
Output is correct |
12 |
Correct |
1 ms |
856 KB |
Output is correct |
13 |
Runtime error |
9 ms |
4352 KB |
Execution killed with signal 11 |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
856 KB |
Output is correct |
2 |
Correct |
0 ms |
856 KB |
Output is correct |
3 |
Correct |
32 ms |
8436 KB |
Output is correct |
4 |
Correct |
58 ms |
8848 KB |
Output is correct |
5 |
Correct |
34 ms |
8804 KB |
Output is correct |
6 |
Correct |
37 ms |
8808 KB |
Output is correct |
7 |
Correct |
36 ms |
8872 KB |
Output is correct |
8 |
Correct |
35 ms |
8804 KB |
Output is correct |
9 |
Correct |
0 ms |
856 KB |
Output is correct |
10 |
Correct |
0 ms |
856 KB |
Output is correct |
11 |
Correct |
1 ms |
852 KB |
Output is correct |
12 |
Correct |
1 ms |
856 KB |
Output is correct |
13 |
Correct |
1 ms |
856 KB |
Output is correct |
14 |
Correct |
1 ms |
856 KB |
Output is correct |
15 |
Correct |
2 ms |
856 KB |
Output is correct |
16 |
Correct |
2 ms |
856 KB |
Output is correct |
17 |
Correct |
1 ms |
856 KB |
Output is correct |
18 |
Correct |
3 ms |
1112 KB |
Output is correct |
19 |
Correct |
3 ms |
1112 KB |
Output is correct |
20 |
Correct |
1 ms |
856 KB |
Output is correct |
21 |
Correct |
2 ms |
856 KB |
Output is correct |
22 |
Correct |
1 ms |
856 KB |
Output is correct |
23 |
Correct |
1 ms |
856 KB |
Output is correct |
24 |
Correct |
3 ms |
856 KB |
Output is correct |
25 |
Correct |
2 ms |
856 KB |
Output is correct |
26 |
Correct |
2 ms |
856 KB |
Output is correct |
27 |
Correct |
2 ms |
856 KB |
Output is correct |
28 |
Correct |
2 ms |
856 KB |
Output is correct |
29 |
Correct |
35 ms |
8804 KB |
Output is correct |
30 |
Correct |
59 ms |
8804 KB |
Output is correct |
31 |
Correct |
1 ms |
1112 KB |
Output is correct |
32 |
Correct |
2 ms |
856 KB |
Output is correct |
33 |
Correct |
2 ms |
856 KB |
Output is correct |
34 |
Correct |
1 ms |
856 KB |
Output is correct |
35 |
Correct |
7 ms |
1348 KB |
Output is correct |
36 |
Correct |
2 ms |
1112 KB |
Output is correct |
37 |
Correct |
39 ms |
9160 KB |
Output is correct |
38 |
Correct |
34 ms |
9140 KB |
Output is correct |
39 |
Correct |
1 ms |
856 KB |
Output is correct |
40 |
Correct |
2 ms |
856 KB |
Output is correct |
41 |
Correct |
1 ms |
856 KB |
Output is correct |
42 |
Correct |
2 ms |
856 KB |
Output is correct |
43 |
Execution timed out |
3069 ms |
1112 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
856 KB |
Output is correct |
2 |
Correct |
0 ms |
856 KB |
Output is correct |
3 |
Correct |
32 ms |
8436 KB |
Output is correct |
4 |
Correct |
58 ms |
8848 KB |
Output is correct |
5 |
Correct |
34 ms |
8804 KB |
Output is correct |
6 |
Correct |
37 ms |
8808 KB |
Output is correct |
7 |
Correct |
36 ms |
8872 KB |
Output is correct |
8 |
Correct |
35 ms |
8804 KB |
Output is correct |
9 |
Correct |
0 ms |
856 KB |
Output is correct |
10 |
Correct |
0 ms |
856 KB |
Output is correct |
11 |
Correct |
1 ms |
852 KB |
Output is correct |
12 |
Correct |
1 ms |
856 KB |
Output is correct |
13 |
Correct |
1 ms |
856 KB |
Output is correct |
14 |
Correct |
1 ms |
856 KB |
Output is correct |
15 |
Correct |
2 ms |
856 KB |
Output is correct |
16 |
Correct |
2 ms |
856 KB |
Output is correct |
17 |
Correct |
1 ms |
856 KB |
Output is correct |
18 |
Correct |
3 ms |
1112 KB |
Output is correct |
19 |
Correct |
3 ms |
1112 KB |
Output is correct |
20 |
Correct |
1 ms |
856 KB |
Output is correct |
21 |
Correct |
2 ms |
856 KB |
Output is correct |
22 |
Correct |
1 ms |
856 KB |
Output is correct |
23 |
Correct |
1 ms |
856 KB |
Output is correct |
24 |
Correct |
3 ms |
856 KB |
Output is correct |
25 |
Correct |
2 ms |
856 KB |
Output is correct |
26 |
Correct |
2 ms |
856 KB |
Output is correct |
27 |
Correct |
2 ms |
856 KB |
Output is correct |
28 |
Correct |
2 ms |
856 KB |
Output is correct |
29 |
Correct |
35 ms |
8804 KB |
Output is correct |
30 |
Correct |
59 ms |
8804 KB |
Output is correct |
31 |
Correct |
1 ms |
1112 KB |
Output is correct |
32 |
Correct |
2 ms |
856 KB |
Output is correct |
33 |
Correct |
2 ms |
856 KB |
Output is correct |
34 |
Correct |
1 ms |
856 KB |
Output is correct |
35 |
Correct |
7 ms |
1348 KB |
Output is correct |
36 |
Correct |
2 ms |
1112 KB |
Output is correct |
37 |
Correct |
39 ms |
9160 KB |
Output is correct |
38 |
Correct |
34 ms |
9140 KB |
Output is correct |
39 |
Correct |
1 ms |
856 KB |
Output is correct |
40 |
Correct |
2 ms |
856 KB |
Output is correct |
41 |
Correct |
1 ms |
856 KB |
Output is correct |
42 |
Correct |
2 ms |
856 KB |
Output is correct |
43 |
Runtime error |
9 ms |
4352 KB |
Execution killed with signal 11 |
44 |
Halted |
0 ms |
0 KB |
- |