#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];
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];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
32 ms |
8228 KB |
Output is correct |
4 |
Correct |
50 ms |
8676 KB |
Output is correct |
5 |
Correct |
34 ms |
8732 KB |
Output is correct |
6 |
Correct |
34 ms |
8732 KB |
Output is correct |
7 |
Correct |
32 ms |
8732 KB |
Output is correct |
8 |
Correct |
35 ms |
8748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
784 KB |
Output is correct |
4 |
Correct |
2 ms |
600 KB |
Output is correct |
5 |
Correct |
2 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
856 KB |
Output is correct |
7 |
Correct |
3 ms |
856 KB |
Output is correct |
8 |
Correct |
4 ms |
856 KB |
Output is correct |
9 |
Correct |
1 ms |
856 KB |
Output is correct |
10 |
Correct |
2 ms |
856 KB |
Output is correct |
11 |
Correct |
3 ms |
856 KB |
Output is correct |
12 |
Correct |
3 ms |
856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
32 ms |
8228 KB |
Output is correct |
4 |
Correct |
50 ms |
8676 KB |
Output is correct |
5 |
Correct |
34 ms |
8732 KB |
Output is correct |
6 |
Correct |
34 ms |
8732 KB |
Output is correct |
7 |
Correct |
32 ms |
8732 KB |
Output is correct |
8 |
Correct |
35 ms |
8748 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
784 KB |
Output is correct |
12 |
Correct |
2 ms |
600 KB |
Output is correct |
13 |
Correct |
2 ms |
600 KB |
Output is correct |
14 |
Correct |
1 ms |
856 KB |
Output is correct |
15 |
Correct |
3 ms |
856 KB |
Output is correct |
16 |
Correct |
4 ms |
856 KB |
Output is correct |
17 |
Correct |
1 ms |
856 KB |
Output is correct |
18 |
Correct |
2 ms |
856 KB |
Output is correct |
19 |
Correct |
3 ms |
856 KB |
Output is correct |
20 |
Correct |
3 ms |
856 KB |
Output is correct |
21 |
Correct |
2 ms |
1108 KB |
Output is correct |
22 |
Correct |
1 ms |
856 KB |
Output is correct |
23 |
Correct |
2 ms |
856 KB |
Output is correct |
24 |
Correct |
2 ms |
856 KB |
Output is correct |
25 |
Correct |
1 ms |
856 KB |
Output is correct |
26 |
Correct |
3 ms |
856 KB |
Output is correct |
27 |
Correct |
3 ms |
856 KB |
Output is correct |
28 |
Correct |
1 ms |
856 KB |
Output is correct |
29 |
Correct |
47 ms |
8764 KB |
Output is correct |
30 |
Correct |
41 ms |
8716 KB |
Output is correct |
31 |
Correct |
1 ms |
856 KB |
Output is correct |
32 |
Correct |
2 ms |
856 KB |
Output is correct |
33 |
Correct |
1 ms |
852 KB |
Output is correct |
34 |
Correct |
1 ms |
856 KB |
Output is correct |
35 |
Correct |
7 ms |
1216 KB |
Output is correct |
36 |
Correct |
2 ms |
856 KB |
Output is correct |
37 |
Correct |
59 ms |
8972 KB |
Output is correct |
38 |
Correct |
35 ms |
9032 KB |
Output is correct |
39 |
Correct |
1 ms |
856 KB |
Output is correct |
40 |
Correct |
2 ms |
856 KB |
Output is correct |
41 |
Correct |
2 ms |
856 KB |
Output is correct |
42 |
Correct |
1 ms |
792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
14 ms |
3792 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
14 ms |
3792 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
1 ms |
784 KB |
Output is correct |
4 |
Correct |
2 ms |
600 KB |
Output is correct |
5 |
Correct |
2 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
856 KB |
Output is correct |
7 |
Correct |
3 ms |
856 KB |
Output is correct |
8 |
Correct |
4 ms |
856 KB |
Output is correct |
9 |
Correct |
1 ms |
856 KB |
Output is correct |
10 |
Correct |
2 ms |
856 KB |
Output is correct |
11 |
Correct |
3 ms |
856 KB |
Output is correct |
12 |
Correct |
3 ms |
856 KB |
Output is correct |
13 |
Runtime error |
14 ms |
3792 KB |
Execution killed with signal 11 |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
32 ms |
8228 KB |
Output is correct |
4 |
Correct |
50 ms |
8676 KB |
Output is correct |
5 |
Correct |
34 ms |
8732 KB |
Output is correct |
6 |
Correct |
34 ms |
8732 KB |
Output is correct |
7 |
Correct |
32 ms |
8732 KB |
Output is correct |
8 |
Correct |
35 ms |
8748 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
784 KB |
Output is correct |
12 |
Correct |
2 ms |
600 KB |
Output is correct |
13 |
Correct |
2 ms |
600 KB |
Output is correct |
14 |
Correct |
1 ms |
856 KB |
Output is correct |
15 |
Correct |
3 ms |
856 KB |
Output is correct |
16 |
Correct |
4 ms |
856 KB |
Output is correct |
17 |
Correct |
1 ms |
856 KB |
Output is correct |
18 |
Correct |
2 ms |
856 KB |
Output is correct |
19 |
Correct |
3 ms |
856 KB |
Output is correct |
20 |
Correct |
3 ms |
856 KB |
Output is correct |
21 |
Correct |
2 ms |
1108 KB |
Output is correct |
22 |
Correct |
1 ms |
856 KB |
Output is correct |
23 |
Correct |
2 ms |
856 KB |
Output is correct |
24 |
Correct |
2 ms |
856 KB |
Output is correct |
25 |
Correct |
1 ms |
856 KB |
Output is correct |
26 |
Correct |
3 ms |
856 KB |
Output is correct |
27 |
Correct |
3 ms |
856 KB |
Output is correct |
28 |
Correct |
1 ms |
856 KB |
Output is correct |
29 |
Correct |
47 ms |
8764 KB |
Output is correct |
30 |
Correct |
41 ms |
8716 KB |
Output is correct |
31 |
Correct |
1 ms |
856 KB |
Output is correct |
32 |
Correct |
2 ms |
856 KB |
Output is correct |
33 |
Correct |
1 ms |
852 KB |
Output is correct |
34 |
Correct |
1 ms |
856 KB |
Output is correct |
35 |
Correct |
7 ms |
1216 KB |
Output is correct |
36 |
Correct |
2 ms |
856 KB |
Output is correct |
37 |
Correct |
59 ms |
8972 KB |
Output is correct |
38 |
Correct |
35 ms |
9032 KB |
Output is correct |
39 |
Correct |
1 ms |
856 KB |
Output is correct |
40 |
Correct |
2 ms |
856 KB |
Output is correct |
41 |
Correct |
2 ms |
856 KB |
Output is correct |
42 |
Correct |
1 ms |
792 KB |
Output is correct |
43 |
Runtime error |
2 ms |
1624 KB |
Execution killed with signal 11 |
44 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Correct |
32 ms |
8228 KB |
Output is correct |
4 |
Correct |
50 ms |
8676 KB |
Output is correct |
5 |
Correct |
34 ms |
8732 KB |
Output is correct |
6 |
Correct |
34 ms |
8732 KB |
Output is correct |
7 |
Correct |
32 ms |
8732 KB |
Output is correct |
8 |
Correct |
35 ms |
8748 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
784 KB |
Output is correct |
12 |
Correct |
2 ms |
600 KB |
Output is correct |
13 |
Correct |
2 ms |
600 KB |
Output is correct |
14 |
Correct |
1 ms |
856 KB |
Output is correct |
15 |
Correct |
3 ms |
856 KB |
Output is correct |
16 |
Correct |
4 ms |
856 KB |
Output is correct |
17 |
Correct |
1 ms |
856 KB |
Output is correct |
18 |
Correct |
2 ms |
856 KB |
Output is correct |
19 |
Correct |
3 ms |
856 KB |
Output is correct |
20 |
Correct |
3 ms |
856 KB |
Output is correct |
21 |
Correct |
2 ms |
1108 KB |
Output is correct |
22 |
Correct |
1 ms |
856 KB |
Output is correct |
23 |
Correct |
2 ms |
856 KB |
Output is correct |
24 |
Correct |
2 ms |
856 KB |
Output is correct |
25 |
Correct |
1 ms |
856 KB |
Output is correct |
26 |
Correct |
3 ms |
856 KB |
Output is correct |
27 |
Correct |
3 ms |
856 KB |
Output is correct |
28 |
Correct |
1 ms |
856 KB |
Output is correct |
29 |
Correct |
47 ms |
8764 KB |
Output is correct |
30 |
Correct |
41 ms |
8716 KB |
Output is correct |
31 |
Correct |
1 ms |
856 KB |
Output is correct |
32 |
Correct |
2 ms |
856 KB |
Output is correct |
33 |
Correct |
1 ms |
852 KB |
Output is correct |
34 |
Correct |
1 ms |
856 KB |
Output is correct |
35 |
Correct |
7 ms |
1216 KB |
Output is correct |
36 |
Correct |
2 ms |
856 KB |
Output is correct |
37 |
Correct |
59 ms |
8972 KB |
Output is correct |
38 |
Correct |
35 ms |
9032 KB |
Output is correct |
39 |
Correct |
1 ms |
856 KB |
Output is correct |
40 |
Correct |
2 ms |
856 KB |
Output is correct |
41 |
Correct |
2 ms |
856 KB |
Output is correct |
42 |
Correct |
1 ms |
792 KB |
Output is correct |
43 |
Runtime error |
14 ms |
3792 KB |
Execution killed with signal 11 |
44 |
Halted |
0 ms |
0 KB |
- |