#include<bits/stdc++.h>
#include "circuit.h"
using namespace std;
long long a,b,c,d,e,i,j,ii,jj,zx,xc,mod=1000002022LL,dp[200009],ALL[200009],f[200009],L,R,pr[200009],sf[200009],pas,N;
vector <long long> v[200009];
void dfs(int q, int w){
if(v[q].size()==0){
ALL[q]=1;
return;
}
ALL[q]=v[q].size();
for(vector <long long>::iterator it=v[q].begin(); it!=v[q].end(); it++){
dfs((*it),q);
ALL[q]*=ALL[(*it)];ALL[q]%=mod;
}
long long qw=1;
for(vector <long long>::iterator it=v[q].begin(); it!=v[q].end(); it++){
pr[(*it)]=qw;
qw*=ALL[(*it)];qw%=mod;
}
vector <long long>::iterator it=v[q].end();it--;
qw=1;
for( ; ; ){
sf[(*it)]=qw;
qw*=ALL[(*it)];qw%=mod;
if(it==v[q].begin()) break;
it--;
}
}
void dfs2(int q, int w){
dp[q]=dp[w];
dp[q]*=pr[q];dp[q]%=mod;
dp[q]*=sf[q];dp[q]%=mod;
for(vector <long long>::iterator it=v[q].begin(); it!=v[q].end(); it++){
dfs2((*it),q);
}
}
void init(int NN, int MM, std::vector<int> P, std::vector<int> A) {
a=NN+MM;N=NN;
for(ii=1; ii<P.size(); ii++){
i=ii+1;
v[P[ii]+1].push_back(i);
}
for(i=N+1; i<=a; i++){
f[i]=A[i-N-1];
}
dfs(1,0);
pr[1]=sf[1]=1;
dp[0]=1;
dfs2(1,0);
/*for(i=1; i<=a; i++){
cout<<dp[i]<<" "<<pr[i]<<" "<<sf[i]<<"\n";
}*/
}
int count_ways(int LL, int RR) {
L=LL+1;R=RR+1;
for(i=L; i<=R; i++) f[i]^=1;
pas=0;
for(i=N+1; i<=a; i++){
if(f[i]==1){
pas+=dp[i];pas%=mod;
}
}
return pas;
}
Compilation message
circuit.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>)':
circuit.cpp:42:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for(ii=1; ii<P.size(); ii++){
| ~~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
2 ms |
4944 KB |
Output is correct |
3 |
Correct |
3 ms |
5072 KB |
Output is correct |
4 |
Correct |
3 ms |
5072 KB |
Output is correct |
5 |
Correct |
2 ms |
5072 KB |
Output is correct |
6 |
Correct |
2 ms |
5072 KB |
Output is correct |
7 |
Correct |
2 ms |
5072 KB |
Output is correct |
8 |
Correct |
2 ms |
5072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4944 KB |
Output is correct |
2 |
Correct |
2 ms |
4944 KB |
Output is correct |
3 |
Correct |
3 ms |
5072 KB |
Output is correct |
4 |
Correct |
2 ms |
5072 KB |
Output is correct |
5 |
Correct |
3 ms |
5072 KB |
Output is correct |
6 |
Correct |
3 ms |
5024 KB |
Output is correct |
7 |
Correct |
2 ms |
5072 KB |
Output is correct |
8 |
Correct |
3 ms |
5072 KB |
Output is correct |
9 |
Correct |
3 ms |
5072 KB |
Output is correct |
10 |
Correct |
3 ms |
5200 KB |
Output is correct |
11 |
Correct |
3 ms |
5200 KB |
Output is correct |
12 |
Correct |
3 ms |
5072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
2 ms |
4944 KB |
Output is correct |
3 |
Correct |
3 ms |
5072 KB |
Output is correct |
4 |
Correct |
3 ms |
5072 KB |
Output is correct |
5 |
Correct |
2 ms |
5072 KB |
Output is correct |
6 |
Correct |
2 ms |
5072 KB |
Output is correct |
7 |
Correct |
2 ms |
5072 KB |
Output is correct |
8 |
Correct |
2 ms |
5072 KB |
Output is correct |
9 |
Correct |
3 ms |
4944 KB |
Output is correct |
10 |
Correct |
2 ms |
4944 KB |
Output is correct |
11 |
Correct |
3 ms |
5072 KB |
Output is correct |
12 |
Correct |
2 ms |
5072 KB |
Output is correct |
13 |
Correct |
3 ms |
5072 KB |
Output is correct |
14 |
Correct |
3 ms |
5024 KB |
Output is correct |
15 |
Correct |
2 ms |
5072 KB |
Output is correct |
16 |
Correct |
3 ms |
5072 KB |
Output is correct |
17 |
Correct |
3 ms |
5072 KB |
Output is correct |
18 |
Correct |
3 ms |
5200 KB |
Output is correct |
19 |
Correct |
3 ms |
5200 KB |
Output is correct |
20 |
Correct |
3 ms |
5072 KB |
Output is correct |
21 |
Correct |
2 ms |
5072 KB |
Output is correct |
22 |
Correct |
2 ms |
5072 KB |
Output is correct |
23 |
Correct |
2 ms |
5072 KB |
Output is correct |
24 |
Correct |
3 ms |
5072 KB |
Output is correct |
25 |
Correct |
3 ms |
5072 KB |
Output is correct |
26 |
Correct |
3 ms |
5072 KB |
Output is correct |
27 |
Correct |
3 ms |
5072 KB |
Output is correct |
28 |
Correct |
3 ms |
5072 KB |
Output is correct |
29 |
Correct |
2 ms |
5072 KB |
Output is correct |
30 |
Correct |
3 ms |
5072 KB |
Output is correct |
31 |
Correct |
2 ms |
5072 KB |
Output is correct |
32 |
Correct |
3 ms |
5072 KB |
Output is correct |
33 |
Correct |
3 ms |
5072 KB |
Output is correct |
34 |
Correct |
3 ms |
5056 KB |
Output is correct |
35 |
Correct |
3 ms |
5072 KB |
Output is correct |
36 |
Correct |
3 ms |
5200 KB |
Output is correct |
37 |
Correct |
3 ms |
5200 KB |
Output is correct |
38 |
Correct |
2 ms |
5200 KB |
Output is correct |
39 |
Correct |
3 ms |
5072 KB |
Output is correct |
40 |
Correct |
2 ms |
5072 KB |
Output is correct |
41 |
Correct |
3 ms |
5072 KB |
Output is correct |
42 |
Correct |
3 ms |
5072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3013 ms |
9112 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3013 ms |
9112 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4944 KB |
Output is correct |
2 |
Correct |
2 ms |
4944 KB |
Output is correct |
3 |
Correct |
3 ms |
5072 KB |
Output is correct |
4 |
Correct |
2 ms |
5072 KB |
Output is correct |
5 |
Correct |
3 ms |
5072 KB |
Output is correct |
6 |
Correct |
3 ms |
5024 KB |
Output is correct |
7 |
Correct |
2 ms |
5072 KB |
Output is correct |
8 |
Correct |
3 ms |
5072 KB |
Output is correct |
9 |
Correct |
3 ms |
5072 KB |
Output is correct |
10 |
Correct |
3 ms |
5200 KB |
Output is correct |
11 |
Correct |
3 ms |
5200 KB |
Output is correct |
12 |
Correct |
3 ms |
5072 KB |
Output is correct |
13 |
Execution timed out |
3013 ms |
9112 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
2 ms |
4944 KB |
Output is correct |
3 |
Correct |
3 ms |
5072 KB |
Output is correct |
4 |
Correct |
3 ms |
5072 KB |
Output is correct |
5 |
Correct |
2 ms |
5072 KB |
Output is correct |
6 |
Correct |
2 ms |
5072 KB |
Output is correct |
7 |
Correct |
2 ms |
5072 KB |
Output is correct |
8 |
Correct |
2 ms |
5072 KB |
Output is correct |
9 |
Correct |
3 ms |
4944 KB |
Output is correct |
10 |
Correct |
2 ms |
4944 KB |
Output is correct |
11 |
Correct |
3 ms |
5072 KB |
Output is correct |
12 |
Correct |
2 ms |
5072 KB |
Output is correct |
13 |
Correct |
3 ms |
5072 KB |
Output is correct |
14 |
Correct |
3 ms |
5024 KB |
Output is correct |
15 |
Correct |
2 ms |
5072 KB |
Output is correct |
16 |
Correct |
3 ms |
5072 KB |
Output is correct |
17 |
Correct |
3 ms |
5072 KB |
Output is correct |
18 |
Correct |
3 ms |
5200 KB |
Output is correct |
19 |
Correct |
3 ms |
5200 KB |
Output is correct |
20 |
Correct |
3 ms |
5072 KB |
Output is correct |
21 |
Correct |
2 ms |
5072 KB |
Output is correct |
22 |
Correct |
2 ms |
5072 KB |
Output is correct |
23 |
Correct |
2 ms |
5072 KB |
Output is correct |
24 |
Correct |
3 ms |
5072 KB |
Output is correct |
25 |
Correct |
3 ms |
5072 KB |
Output is correct |
26 |
Correct |
3 ms |
5072 KB |
Output is correct |
27 |
Correct |
3 ms |
5072 KB |
Output is correct |
28 |
Correct |
3 ms |
5072 KB |
Output is correct |
29 |
Correct |
2 ms |
5072 KB |
Output is correct |
30 |
Correct |
3 ms |
5072 KB |
Output is correct |
31 |
Correct |
2 ms |
5072 KB |
Output is correct |
32 |
Correct |
3 ms |
5072 KB |
Output is correct |
33 |
Correct |
3 ms |
5072 KB |
Output is correct |
34 |
Correct |
3 ms |
5056 KB |
Output is correct |
35 |
Correct |
3 ms |
5072 KB |
Output is correct |
36 |
Correct |
3 ms |
5200 KB |
Output is correct |
37 |
Correct |
3 ms |
5200 KB |
Output is correct |
38 |
Correct |
2 ms |
5200 KB |
Output is correct |
39 |
Correct |
3 ms |
5072 KB |
Output is correct |
40 |
Correct |
2 ms |
5072 KB |
Output is correct |
41 |
Correct |
3 ms |
5072 KB |
Output is correct |
42 |
Correct |
3 ms |
5072 KB |
Output is correct |
43 |
Correct |
979 ms |
5328 KB |
Output is correct |
44 |
Correct |
1384 ms |
5384 KB |
Output is correct |
45 |
Correct |
1494 ms |
5384 KB |
Output is correct |
46 |
Correct |
1865 ms |
5584 KB |
Output is correct |
47 |
Correct |
2243 ms |
5644 KB |
Output is correct |
48 |
Correct |
2275 ms |
5640 KB |
Output is correct |
49 |
Correct |
2300 ms |
5640 KB |
Output is correct |
50 |
Correct |
1994 ms |
5640 KB |
Output is correct |
51 |
Correct |
2349 ms |
5392 KB |
Output is correct |
52 |
Correct |
1980 ms |
5448 KB |
Output is correct |
53 |
Correct |
557 ms |
5584 KB |
Output is correct |
54 |
Correct |
2016 ms |
5644 KB |
Output is correct |
55 |
Correct |
2050 ms |
5424 KB |
Output is correct |
56 |
Correct |
2156 ms |
5376 KB |
Output is correct |
57 |
Correct |
2058 ms |
5328 KB |
Output is correct |
58 |
Correct |
2422 ms |
5768 KB |
Output is correct |
59 |
Correct |
2133 ms |
5984 KB |
Output is correct |
60 |
Correct |
2329 ms |
5984 KB |
Output is correct |
61 |
Correct |
1306 ms |
5456 KB |
Output is correct |
62 |
Correct |
1582 ms |
5328 KB |
Output is correct |
63 |
Correct |
1603 ms |
5372 KB |
Output is correct |
64 |
Correct |
2073 ms |
5248 KB |
Output is correct |
65 |
Correct |
570 ms |
5252 KB |
Output is correct |
66 |
Correct |
1618 ms |
5512 KB |
Output is correct |
67 |
Correct |
1908 ms |
5456 KB |
Output is correct |
68 |
Correct |
1977 ms |
5456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
2 ms |
4944 KB |
Output is correct |
3 |
Correct |
3 ms |
5072 KB |
Output is correct |
4 |
Correct |
3 ms |
5072 KB |
Output is correct |
5 |
Correct |
2 ms |
5072 KB |
Output is correct |
6 |
Correct |
2 ms |
5072 KB |
Output is correct |
7 |
Correct |
2 ms |
5072 KB |
Output is correct |
8 |
Correct |
2 ms |
5072 KB |
Output is correct |
9 |
Correct |
3 ms |
4944 KB |
Output is correct |
10 |
Correct |
2 ms |
4944 KB |
Output is correct |
11 |
Correct |
3 ms |
5072 KB |
Output is correct |
12 |
Correct |
2 ms |
5072 KB |
Output is correct |
13 |
Correct |
3 ms |
5072 KB |
Output is correct |
14 |
Correct |
3 ms |
5024 KB |
Output is correct |
15 |
Correct |
2 ms |
5072 KB |
Output is correct |
16 |
Correct |
3 ms |
5072 KB |
Output is correct |
17 |
Correct |
3 ms |
5072 KB |
Output is correct |
18 |
Correct |
3 ms |
5200 KB |
Output is correct |
19 |
Correct |
3 ms |
5200 KB |
Output is correct |
20 |
Correct |
3 ms |
5072 KB |
Output is correct |
21 |
Correct |
2 ms |
5072 KB |
Output is correct |
22 |
Correct |
2 ms |
5072 KB |
Output is correct |
23 |
Correct |
2 ms |
5072 KB |
Output is correct |
24 |
Correct |
3 ms |
5072 KB |
Output is correct |
25 |
Correct |
3 ms |
5072 KB |
Output is correct |
26 |
Correct |
3 ms |
5072 KB |
Output is correct |
27 |
Correct |
3 ms |
5072 KB |
Output is correct |
28 |
Correct |
3 ms |
5072 KB |
Output is correct |
29 |
Correct |
2 ms |
5072 KB |
Output is correct |
30 |
Correct |
3 ms |
5072 KB |
Output is correct |
31 |
Correct |
2 ms |
5072 KB |
Output is correct |
32 |
Correct |
3 ms |
5072 KB |
Output is correct |
33 |
Correct |
3 ms |
5072 KB |
Output is correct |
34 |
Correct |
3 ms |
5056 KB |
Output is correct |
35 |
Correct |
3 ms |
5072 KB |
Output is correct |
36 |
Correct |
3 ms |
5200 KB |
Output is correct |
37 |
Correct |
3 ms |
5200 KB |
Output is correct |
38 |
Correct |
2 ms |
5200 KB |
Output is correct |
39 |
Correct |
3 ms |
5072 KB |
Output is correct |
40 |
Correct |
2 ms |
5072 KB |
Output is correct |
41 |
Correct |
3 ms |
5072 KB |
Output is correct |
42 |
Correct |
3 ms |
5072 KB |
Output is correct |
43 |
Execution timed out |
3013 ms |
9112 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |