#include "circuit.h"
#include <bits/stdc++.h>
#define ll long long
#define sz(s) (int)s.size()
#define pb push_back
using namespace std;
const int MAX=2e5+10;
const int mod=1000002022;
int n,m;
vector<int> a;
vector<int> g[MAX];
int dp[MAX],s[MAX];
void dfs(int v){
if(g[v].empty()){
dp[v]=a[v-n];
s[v]=1;
return;
}
s[v]=sz(g[v]);
for(auto to:g[v]){
dfs(to);
s[v]=s[v]*1ll*s[to]%mod;
}
vector<int> d(n+m,0);
d[0]=1;
for(int i=0;i<sz(g[v]);i++){
int to=g[v][i];
for(int j=i+1;j>=0;j--){
int p=d[j];
d[j]=d[j]*1ll*(s[to]-dp[to]+mod)%mod;
if(j-1>=0)d[j]+=d[j-1]*1ll*dp[to]%mod;
d[j]%=mod;
}
}
for(int i=1;i<=sz(g[v]);i++){
dp[v]+=i*1ll*d[i]%mod;
dp[v]%=mod;
}
}
void init(int N, int M,vector<int> P,vector<int> A) {
n=N;
m=M;
a=A;
for(int i=1;i<N+M;i++){
g[P[i]].pb(i);
}
}
int count_ways(int L, int R) {
for(int i=0;i<n+m;i++)dp[i]=0;
for(int i=L;i<=R;i++)a[i-n]^=1;
dfs(0);
// for(int i=0;i<n;i++)cout<<dp[i]<<" "<<(s[i]-dp[i])<<"\n";
// cout<<"\n";
return dp[0];
}
Compilation message
circuit.cpp: In function 'void dfs(int)':
circuit.cpp:34:17: warning: unused variable 'p' [-Wunused-variable]
34 | int p=d[j];
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
Output is correct |
2 |
Correct |
2 ms |
6372 KB |
Output is correct |
3 |
Correct |
12 ms |
6488 KB |
Output is correct |
4 |
Correct |
13 ms |
6488 KB |
Output is correct |
5 |
Correct |
15 ms |
6488 KB |
Output is correct |
6 |
Correct |
12 ms |
6488 KB |
Output is correct |
7 |
Correct |
12 ms |
6488 KB |
Output is correct |
8 |
Correct |
13 ms |
6488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
Output is correct |
2 |
Correct |
2 ms |
6488 KB |
Output is correct |
3 |
Correct |
2 ms |
6488 KB |
Output is correct |
4 |
Correct |
2 ms |
6488 KB |
Output is correct |
5 |
Correct |
2 ms |
6488 KB |
Output is correct |
6 |
Correct |
2 ms |
6488 KB |
Output is correct |
7 |
Correct |
3 ms |
6488 KB |
Output is correct |
8 |
Correct |
3 ms |
6488 KB |
Output is correct |
9 |
Correct |
3 ms |
6500 KB |
Output is correct |
10 |
Correct |
3 ms |
6488 KB |
Output is correct |
11 |
Correct |
3 ms |
6488 KB |
Output is correct |
12 |
Correct |
3 ms |
6488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
Output is correct |
2 |
Correct |
2 ms |
6372 KB |
Output is correct |
3 |
Correct |
12 ms |
6488 KB |
Output is correct |
4 |
Correct |
13 ms |
6488 KB |
Output is correct |
5 |
Correct |
15 ms |
6488 KB |
Output is correct |
6 |
Correct |
12 ms |
6488 KB |
Output is correct |
7 |
Correct |
12 ms |
6488 KB |
Output is correct |
8 |
Correct |
13 ms |
6488 KB |
Output is correct |
9 |
Correct |
2 ms |
6488 KB |
Output is correct |
10 |
Correct |
2 ms |
6488 KB |
Output is correct |
11 |
Correct |
2 ms |
6488 KB |
Output is correct |
12 |
Correct |
2 ms |
6488 KB |
Output is correct |
13 |
Correct |
2 ms |
6488 KB |
Output is correct |
14 |
Correct |
2 ms |
6488 KB |
Output is correct |
15 |
Correct |
3 ms |
6488 KB |
Output is correct |
16 |
Correct |
3 ms |
6488 KB |
Output is correct |
17 |
Correct |
3 ms |
6500 KB |
Output is correct |
18 |
Correct |
3 ms |
6488 KB |
Output is correct |
19 |
Correct |
3 ms |
6488 KB |
Output is correct |
20 |
Correct |
3 ms |
6488 KB |
Output is correct |
21 |
Correct |
3 ms |
6488 KB |
Output is correct |
22 |
Correct |
2 ms |
6488 KB |
Output is correct |
23 |
Correct |
2 ms |
6488 KB |
Output is correct |
24 |
Correct |
3 ms |
6488 KB |
Output is correct |
25 |
Correct |
3 ms |
6488 KB |
Output is correct |
26 |
Correct |
3 ms |
6488 KB |
Output is correct |
27 |
Correct |
4 ms |
6488 KB |
Output is correct |
28 |
Correct |
3 ms |
6488 KB |
Output is correct |
29 |
Correct |
14 ms |
6488 KB |
Output is correct |
30 |
Correct |
12 ms |
6488 KB |
Output is correct |
31 |
Correct |
3 ms |
6488 KB |
Output is correct |
32 |
Correct |
3 ms |
6488 KB |
Output is correct |
33 |
Correct |
2 ms |
6488 KB |
Output is correct |
34 |
Correct |
2 ms |
6488 KB |
Output is correct |
35 |
Correct |
4 ms |
6488 KB |
Output is correct |
36 |
Correct |
3 ms |
6488 KB |
Output is correct |
37 |
Correct |
14 ms |
6488 KB |
Output is correct |
38 |
Correct |
13 ms |
6488 KB |
Output is correct |
39 |
Correct |
3 ms |
6488 KB |
Output is correct |
40 |
Correct |
3 ms |
6488 KB |
Output is correct |
41 |
Correct |
2 ms |
6488 KB |
Output is correct |
42 |
Correct |
2 ms |
6488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3065 ms |
8460 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3065 ms |
8460 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
Output is correct |
2 |
Correct |
2 ms |
6488 KB |
Output is correct |
3 |
Correct |
2 ms |
6488 KB |
Output is correct |
4 |
Correct |
2 ms |
6488 KB |
Output is correct |
5 |
Correct |
2 ms |
6488 KB |
Output is correct |
6 |
Correct |
2 ms |
6488 KB |
Output is correct |
7 |
Correct |
3 ms |
6488 KB |
Output is correct |
8 |
Correct |
3 ms |
6488 KB |
Output is correct |
9 |
Correct |
3 ms |
6500 KB |
Output is correct |
10 |
Correct |
3 ms |
6488 KB |
Output is correct |
11 |
Correct |
3 ms |
6488 KB |
Output is correct |
12 |
Correct |
3 ms |
6488 KB |
Output is correct |
13 |
Execution timed out |
3065 ms |
8460 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
Output is correct |
2 |
Correct |
2 ms |
6372 KB |
Output is correct |
3 |
Correct |
12 ms |
6488 KB |
Output is correct |
4 |
Correct |
13 ms |
6488 KB |
Output is correct |
5 |
Correct |
15 ms |
6488 KB |
Output is correct |
6 |
Correct |
12 ms |
6488 KB |
Output is correct |
7 |
Correct |
12 ms |
6488 KB |
Output is correct |
8 |
Correct |
13 ms |
6488 KB |
Output is correct |
9 |
Correct |
2 ms |
6488 KB |
Output is correct |
10 |
Correct |
2 ms |
6488 KB |
Output is correct |
11 |
Correct |
2 ms |
6488 KB |
Output is correct |
12 |
Correct |
2 ms |
6488 KB |
Output is correct |
13 |
Correct |
2 ms |
6488 KB |
Output is correct |
14 |
Correct |
2 ms |
6488 KB |
Output is correct |
15 |
Correct |
3 ms |
6488 KB |
Output is correct |
16 |
Correct |
3 ms |
6488 KB |
Output is correct |
17 |
Correct |
3 ms |
6500 KB |
Output is correct |
18 |
Correct |
3 ms |
6488 KB |
Output is correct |
19 |
Correct |
3 ms |
6488 KB |
Output is correct |
20 |
Correct |
3 ms |
6488 KB |
Output is correct |
21 |
Correct |
3 ms |
6488 KB |
Output is correct |
22 |
Correct |
2 ms |
6488 KB |
Output is correct |
23 |
Correct |
2 ms |
6488 KB |
Output is correct |
24 |
Correct |
3 ms |
6488 KB |
Output is correct |
25 |
Correct |
3 ms |
6488 KB |
Output is correct |
26 |
Correct |
3 ms |
6488 KB |
Output is correct |
27 |
Correct |
4 ms |
6488 KB |
Output is correct |
28 |
Correct |
3 ms |
6488 KB |
Output is correct |
29 |
Correct |
14 ms |
6488 KB |
Output is correct |
30 |
Correct |
12 ms |
6488 KB |
Output is correct |
31 |
Correct |
3 ms |
6488 KB |
Output is correct |
32 |
Correct |
3 ms |
6488 KB |
Output is correct |
33 |
Correct |
2 ms |
6488 KB |
Output is correct |
34 |
Correct |
2 ms |
6488 KB |
Output is correct |
35 |
Correct |
4 ms |
6488 KB |
Output is correct |
36 |
Correct |
3 ms |
6488 KB |
Output is correct |
37 |
Correct |
14 ms |
6488 KB |
Output is correct |
38 |
Correct |
13 ms |
6488 KB |
Output is correct |
39 |
Correct |
3 ms |
6488 KB |
Output is correct |
40 |
Correct |
3 ms |
6488 KB |
Output is correct |
41 |
Correct |
2 ms |
6488 KB |
Output is correct |
42 |
Correct |
2 ms |
6488 KB |
Output is correct |
43 |
Execution timed out |
3001 ms |
6488 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
Output is correct |
2 |
Correct |
2 ms |
6372 KB |
Output is correct |
3 |
Correct |
12 ms |
6488 KB |
Output is correct |
4 |
Correct |
13 ms |
6488 KB |
Output is correct |
5 |
Correct |
15 ms |
6488 KB |
Output is correct |
6 |
Correct |
12 ms |
6488 KB |
Output is correct |
7 |
Correct |
12 ms |
6488 KB |
Output is correct |
8 |
Correct |
13 ms |
6488 KB |
Output is correct |
9 |
Correct |
2 ms |
6488 KB |
Output is correct |
10 |
Correct |
2 ms |
6488 KB |
Output is correct |
11 |
Correct |
2 ms |
6488 KB |
Output is correct |
12 |
Correct |
2 ms |
6488 KB |
Output is correct |
13 |
Correct |
2 ms |
6488 KB |
Output is correct |
14 |
Correct |
2 ms |
6488 KB |
Output is correct |
15 |
Correct |
3 ms |
6488 KB |
Output is correct |
16 |
Correct |
3 ms |
6488 KB |
Output is correct |
17 |
Correct |
3 ms |
6500 KB |
Output is correct |
18 |
Correct |
3 ms |
6488 KB |
Output is correct |
19 |
Correct |
3 ms |
6488 KB |
Output is correct |
20 |
Correct |
3 ms |
6488 KB |
Output is correct |
21 |
Correct |
3 ms |
6488 KB |
Output is correct |
22 |
Correct |
2 ms |
6488 KB |
Output is correct |
23 |
Correct |
2 ms |
6488 KB |
Output is correct |
24 |
Correct |
3 ms |
6488 KB |
Output is correct |
25 |
Correct |
3 ms |
6488 KB |
Output is correct |
26 |
Correct |
3 ms |
6488 KB |
Output is correct |
27 |
Correct |
4 ms |
6488 KB |
Output is correct |
28 |
Correct |
3 ms |
6488 KB |
Output is correct |
29 |
Correct |
14 ms |
6488 KB |
Output is correct |
30 |
Correct |
12 ms |
6488 KB |
Output is correct |
31 |
Correct |
3 ms |
6488 KB |
Output is correct |
32 |
Correct |
3 ms |
6488 KB |
Output is correct |
33 |
Correct |
2 ms |
6488 KB |
Output is correct |
34 |
Correct |
2 ms |
6488 KB |
Output is correct |
35 |
Correct |
4 ms |
6488 KB |
Output is correct |
36 |
Correct |
3 ms |
6488 KB |
Output is correct |
37 |
Correct |
14 ms |
6488 KB |
Output is correct |
38 |
Correct |
13 ms |
6488 KB |
Output is correct |
39 |
Correct |
3 ms |
6488 KB |
Output is correct |
40 |
Correct |
3 ms |
6488 KB |
Output is correct |
41 |
Correct |
2 ms |
6488 KB |
Output is correct |
42 |
Correct |
2 ms |
6488 KB |
Output is correct |
43 |
Execution timed out |
3065 ms |
8460 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |