#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
const int N=100'000,mod=1e9+2022;
int add(int x,int y)
{
return (x+y)%mod;
}
void add_self(int& x,int y)
{
x+=y;
if(x>=mod)
{
x-=mod;
}
if(x<0)
{
x+=mod;
}
}
int prod(int x,int y)
{
return (1LL*x*y)%mod;
}
int n,m;
vector<int>g[2*N],a;
int dp[2*N][2];
void init(int nn, int mm, std::vector<int> pp, std::vector<int> init_a)
{
n=nn;
m=mm;
for(int i=1;i<n+m;i++)
{
g[pp[i]].push_back(i);
}
a=init_a;
}
void dfs(int nod)
{
for(auto &c:g[nod])
{
dfs(c);
}
int sz=(int)g[nod].size();
if(g[nod].empty())
{
dp[nod][0]=(a[nod-n]==0);
dp[nod][1]=(a[nod-n]==1);
return;
}
vector<int>choose(sz+1,0);
choose[0]=1;
for(auto &c:g[nod])
{
for(int i=sz;i>=0;i--)
{
choose[i]=prod(choose[i] , dp[c][0]);
if(i>0)
{
add_self(choose[i] , prod(choose[i-1] , dp[c][1]));
}
}
}
dp[nod][0]=dp[nod][1]=0;
for(int i=1;i<=sz;i++)
{
add_self(dp[nod][0] , prod(choose[i],sz-i));
add_self(dp[nod][1] , prod(choose[i],i));
}
add_self(dp[nod][0],prod(choose[0],sz));
}
int count_ways(int l, int r)
{
l-=n;
r-=n;
for(int i=l;i<=r;i++)
{
a[i]^=1;
}
for(auto &c:a)
{
//cout<<c<<' ';
}
dfs(0);
return dp[0][1];
}
Compilation message
circuit.cpp: In function 'int count_ways(int, int)':
circuit.cpp:82:15: warning: unused variable 'c' [-Wunused-variable]
82 | for(auto &c:a)
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6480 KB |
Output is correct |
2 |
Correct |
3 ms |
6480 KB |
Output is correct |
3 |
Correct |
18 ms |
6480 KB |
Output is correct |
4 |
Correct |
20 ms |
6480 KB |
Output is correct |
5 |
Correct |
20 ms |
6480 KB |
Output is correct |
6 |
Correct |
19 ms |
6480 KB |
Output is correct |
7 |
Correct |
19 ms |
6480 KB |
Output is correct |
8 |
Correct |
19 ms |
6480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6480 KB |
Output is correct |
2 |
Correct |
3 ms |
6480 KB |
Output is correct |
3 |
Correct |
3 ms |
6480 KB |
Output is correct |
4 |
Correct |
3 ms |
6372 KB |
Output is correct |
5 |
Correct |
3 ms |
6480 KB |
Output is correct |
6 |
Correct |
4 ms |
6480 KB |
Output is correct |
7 |
Correct |
3 ms |
6480 KB |
Output is correct |
8 |
Correct |
4 ms |
6480 KB |
Output is correct |
9 |
Correct |
3 ms |
6480 KB |
Output is correct |
10 |
Correct |
3 ms |
6480 KB |
Output is correct |
11 |
Correct |
3 ms |
6480 KB |
Output is correct |
12 |
Correct |
3 ms |
6480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6480 KB |
Output is correct |
2 |
Correct |
3 ms |
6480 KB |
Output is correct |
3 |
Correct |
18 ms |
6480 KB |
Output is correct |
4 |
Correct |
20 ms |
6480 KB |
Output is correct |
5 |
Correct |
20 ms |
6480 KB |
Output is correct |
6 |
Correct |
19 ms |
6480 KB |
Output is correct |
7 |
Correct |
19 ms |
6480 KB |
Output is correct |
8 |
Correct |
19 ms |
6480 KB |
Output is correct |
9 |
Correct |
3 ms |
6480 KB |
Output is correct |
10 |
Correct |
3 ms |
6480 KB |
Output is correct |
11 |
Correct |
3 ms |
6480 KB |
Output is correct |
12 |
Correct |
3 ms |
6372 KB |
Output is correct |
13 |
Correct |
3 ms |
6480 KB |
Output is correct |
14 |
Correct |
4 ms |
6480 KB |
Output is correct |
15 |
Correct |
3 ms |
6480 KB |
Output is correct |
16 |
Correct |
4 ms |
6480 KB |
Output is correct |
17 |
Correct |
3 ms |
6480 KB |
Output is correct |
18 |
Correct |
3 ms |
6480 KB |
Output is correct |
19 |
Correct |
3 ms |
6480 KB |
Output is correct |
20 |
Correct |
3 ms |
6480 KB |
Output is correct |
21 |
Correct |
3 ms |
6480 KB |
Output is correct |
22 |
Correct |
4 ms |
6480 KB |
Output is correct |
23 |
Correct |
4 ms |
6480 KB |
Output is correct |
24 |
Correct |
4 ms |
6480 KB |
Output is correct |
25 |
Correct |
3 ms |
6480 KB |
Output is correct |
26 |
Correct |
3 ms |
6480 KB |
Output is correct |
27 |
Correct |
5 ms |
6480 KB |
Output is correct |
28 |
Correct |
3 ms |
6480 KB |
Output is correct |
29 |
Correct |
20 ms |
6480 KB |
Output is correct |
30 |
Correct |
20 ms |
6480 KB |
Output is correct |
31 |
Correct |
4 ms |
6480 KB |
Output is correct |
32 |
Correct |
3 ms |
6480 KB |
Output is correct |
33 |
Correct |
3 ms |
6480 KB |
Output is correct |
34 |
Correct |
3 ms |
6480 KB |
Output is correct |
35 |
Correct |
7 ms |
6480 KB |
Output is correct |
36 |
Correct |
3 ms |
6480 KB |
Output is correct |
37 |
Correct |
20 ms |
6672 KB |
Output is correct |
38 |
Correct |
21 ms |
6480 KB |
Output is correct |
39 |
Correct |
3 ms |
6480 KB |
Output is correct |
40 |
Correct |
3 ms |
6480 KB |
Output is correct |
41 |
Correct |
3 ms |
6480 KB |
Output is correct |
42 |
Correct |
4 ms |
6480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3015 ms |
8272 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3015 ms |
8272 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6480 KB |
Output is correct |
2 |
Correct |
3 ms |
6480 KB |
Output is correct |
3 |
Correct |
3 ms |
6480 KB |
Output is correct |
4 |
Correct |
3 ms |
6372 KB |
Output is correct |
5 |
Correct |
3 ms |
6480 KB |
Output is correct |
6 |
Correct |
4 ms |
6480 KB |
Output is correct |
7 |
Correct |
3 ms |
6480 KB |
Output is correct |
8 |
Correct |
4 ms |
6480 KB |
Output is correct |
9 |
Correct |
3 ms |
6480 KB |
Output is correct |
10 |
Correct |
3 ms |
6480 KB |
Output is correct |
11 |
Correct |
3 ms |
6480 KB |
Output is correct |
12 |
Correct |
3 ms |
6480 KB |
Output is correct |
13 |
Execution timed out |
3015 ms |
8272 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6480 KB |
Output is correct |
2 |
Correct |
3 ms |
6480 KB |
Output is correct |
3 |
Correct |
18 ms |
6480 KB |
Output is correct |
4 |
Correct |
20 ms |
6480 KB |
Output is correct |
5 |
Correct |
20 ms |
6480 KB |
Output is correct |
6 |
Correct |
19 ms |
6480 KB |
Output is correct |
7 |
Correct |
19 ms |
6480 KB |
Output is correct |
8 |
Correct |
19 ms |
6480 KB |
Output is correct |
9 |
Correct |
3 ms |
6480 KB |
Output is correct |
10 |
Correct |
3 ms |
6480 KB |
Output is correct |
11 |
Correct |
3 ms |
6480 KB |
Output is correct |
12 |
Correct |
3 ms |
6372 KB |
Output is correct |
13 |
Correct |
3 ms |
6480 KB |
Output is correct |
14 |
Correct |
4 ms |
6480 KB |
Output is correct |
15 |
Correct |
3 ms |
6480 KB |
Output is correct |
16 |
Correct |
4 ms |
6480 KB |
Output is correct |
17 |
Correct |
3 ms |
6480 KB |
Output is correct |
18 |
Correct |
3 ms |
6480 KB |
Output is correct |
19 |
Correct |
3 ms |
6480 KB |
Output is correct |
20 |
Correct |
3 ms |
6480 KB |
Output is correct |
21 |
Correct |
3 ms |
6480 KB |
Output is correct |
22 |
Correct |
4 ms |
6480 KB |
Output is correct |
23 |
Correct |
4 ms |
6480 KB |
Output is correct |
24 |
Correct |
4 ms |
6480 KB |
Output is correct |
25 |
Correct |
3 ms |
6480 KB |
Output is correct |
26 |
Correct |
3 ms |
6480 KB |
Output is correct |
27 |
Correct |
5 ms |
6480 KB |
Output is correct |
28 |
Correct |
3 ms |
6480 KB |
Output is correct |
29 |
Correct |
20 ms |
6480 KB |
Output is correct |
30 |
Correct |
20 ms |
6480 KB |
Output is correct |
31 |
Correct |
4 ms |
6480 KB |
Output is correct |
32 |
Correct |
3 ms |
6480 KB |
Output is correct |
33 |
Correct |
3 ms |
6480 KB |
Output is correct |
34 |
Correct |
3 ms |
6480 KB |
Output is correct |
35 |
Correct |
7 ms |
6480 KB |
Output is correct |
36 |
Correct |
3 ms |
6480 KB |
Output is correct |
37 |
Correct |
20 ms |
6672 KB |
Output is correct |
38 |
Correct |
21 ms |
6480 KB |
Output is correct |
39 |
Correct |
3 ms |
6480 KB |
Output is correct |
40 |
Correct |
3 ms |
6480 KB |
Output is correct |
41 |
Correct |
3 ms |
6480 KB |
Output is correct |
42 |
Correct |
4 ms |
6480 KB |
Output is correct |
43 |
Execution timed out |
3025 ms |
6736 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
6480 KB |
Output is correct |
2 |
Correct |
3 ms |
6480 KB |
Output is correct |
3 |
Correct |
18 ms |
6480 KB |
Output is correct |
4 |
Correct |
20 ms |
6480 KB |
Output is correct |
5 |
Correct |
20 ms |
6480 KB |
Output is correct |
6 |
Correct |
19 ms |
6480 KB |
Output is correct |
7 |
Correct |
19 ms |
6480 KB |
Output is correct |
8 |
Correct |
19 ms |
6480 KB |
Output is correct |
9 |
Correct |
3 ms |
6480 KB |
Output is correct |
10 |
Correct |
3 ms |
6480 KB |
Output is correct |
11 |
Correct |
3 ms |
6480 KB |
Output is correct |
12 |
Correct |
3 ms |
6372 KB |
Output is correct |
13 |
Correct |
3 ms |
6480 KB |
Output is correct |
14 |
Correct |
4 ms |
6480 KB |
Output is correct |
15 |
Correct |
3 ms |
6480 KB |
Output is correct |
16 |
Correct |
4 ms |
6480 KB |
Output is correct |
17 |
Correct |
3 ms |
6480 KB |
Output is correct |
18 |
Correct |
3 ms |
6480 KB |
Output is correct |
19 |
Correct |
3 ms |
6480 KB |
Output is correct |
20 |
Correct |
3 ms |
6480 KB |
Output is correct |
21 |
Correct |
3 ms |
6480 KB |
Output is correct |
22 |
Correct |
4 ms |
6480 KB |
Output is correct |
23 |
Correct |
4 ms |
6480 KB |
Output is correct |
24 |
Correct |
4 ms |
6480 KB |
Output is correct |
25 |
Correct |
3 ms |
6480 KB |
Output is correct |
26 |
Correct |
3 ms |
6480 KB |
Output is correct |
27 |
Correct |
5 ms |
6480 KB |
Output is correct |
28 |
Correct |
3 ms |
6480 KB |
Output is correct |
29 |
Correct |
20 ms |
6480 KB |
Output is correct |
30 |
Correct |
20 ms |
6480 KB |
Output is correct |
31 |
Correct |
4 ms |
6480 KB |
Output is correct |
32 |
Correct |
3 ms |
6480 KB |
Output is correct |
33 |
Correct |
3 ms |
6480 KB |
Output is correct |
34 |
Correct |
3 ms |
6480 KB |
Output is correct |
35 |
Correct |
7 ms |
6480 KB |
Output is correct |
36 |
Correct |
3 ms |
6480 KB |
Output is correct |
37 |
Correct |
20 ms |
6672 KB |
Output is correct |
38 |
Correct |
21 ms |
6480 KB |
Output is correct |
39 |
Correct |
3 ms |
6480 KB |
Output is correct |
40 |
Correct |
3 ms |
6480 KB |
Output is correct |
41 |
Correct |
3 ms |
6480 KB |
Output is correct |
42 |
Correct |
4 ms |
6480 KB |
Output is correct |
43 |
Execution timed out |
3015 ms |
8272 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |