#include<bits/stdc++.h>
#include "circuit.h"
using namespace std;
long long a,b,c,d,e,i,j,ii,jj,zx,xc,msh[100009],f[100009],K[100009],mod=1000002022LL,pas,DP[100009],DP2[100009],DP3[100009];
vector <long long> v[100009];
void dfs(long long q, long long w){
if(v[q].size()==0){
DP[q]=1;
return;
}
DP[q]=v[q].size();
for(vector <long long>::iterator it=v[q].begin(); it!=v[q].end(); it++){
dfs((*it),q);
DP[q]*=DP[(*it)];DP[q]%=mod;
}
zx=1;
for(vector <long long>::iterator it=v[q].begin(); it!=v[q].end(); it++){
DP2[(*it)]=zx;
zx*=DP[(*it)];zx%=mod;
}
vector <long long>::iterator it=v[q].end();it--;
zx=1;
while(1){
DP2[(*it)]*=zx;DP2[(*it)]%=mod;
zx*=DP[(*it)];zx%=mod;
if(it==v[q].begin()) break;
it--;
}
}
void dfs2(int q, int w){
DP3[q]*=DP2[q];DP3[q]%=mod;
for(vector <long long>::iterator it=v[q].begin(); it!=v[q].end(); it++){
DP3[(*it)]=DP3[q];
dfs2((*it),q);
}
}
void init(int NN, int MM, std::vector<int> PP, std::vector<int> AA) {
a=NN+MM;
for(i=1; i<a; i++){
msh[i+1]=PP[i]+1;
v[msh[i+1]].push_back(i+1);
}
for(i=NN+1; i<=a; i++){
f[i]=AA[i-NN-1];
}
DP2[1]=1;DP3[1]=1;
dfs(1,0);
dfs2(1,0);
for(i=NN+1; i<=a; i++){
K[i]=DP3[i];
}
}
int count_ways(int L, int R) {
L++;R++;pas=0;
for(i=L; i<=R; i++){
if(f[i]==0) f[i]=1; else f[i]=0;
}
for(i=1; i<=a; i++){
if(f[i]==1){
pas+=K[i];
if(pas>=mod) pas-=mod;
}
}
return pas;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2640 KB |
Output is correct |
2 |
Correct |
2 ms |
2640 KB |
Output is correct |
3 |
Correct |
2 ms |
2640 KB |
Output is correct |
4 |
Correct |
2 ms |
2640 KB |
Output is correct |
5 |
Correct |
3 ms |
2660 KB |
Output is correct |
6 |
Correct |
2 ms |
2640 KB |
Output is correct |
7 |
Correct |
2 ms |
2640 KB |
Output is correct |
8 |
Correct |
3 ms |
2640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2640 KB |
Output is correct |
2 |
Correct |
2 ms |
2640 KB |
Output is correct |
3 |
Correct |
2 ms |
2640 KB |
Output is correct |
4 |
Correct |
2 ms |
2640 KB |
Output is correct |
5 |
Correct |
2 ms |
2640 KB |
Output is correct |
6 |
Correct |
2 ms |
2748 KB |
Output is correct |
7 |
Correct |
2 ms |
2732 KB |
Output is correct |
8 |
Correct |
2 ms |
2768 KB |
Output is correct |
9 |
Correct |
2 ms |
2768 KB |
Output is correct |
10 |
Correct |
3 ms |
2768 KB |
Output is correct |
11 |
Correct |
2 ms |
2768 KB |
Output is correct |
12 |
Correct |
3 ms |
2768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2640 KB |
Output is correct |
2 |
Correct |
2 ms |
2640 KB |
Output is correct |
3 |
Correct |
2 ms |
2640 KB |
Output is correct |
4 |
Correct |
2 ms |
2640 KB |
Output is correct |
5 |
Correct |
3 ms |
2660 KB |
Output is correct |
6 |
Correct |
2 ms |
2640 KB |
Output is correct |
7 |
Correct |
2 ms |
2640 KB |
Output is correct |
8 |
Correct |
3 ms |
2640 KB |
Output is correct |
9 |
Correct |
2 ms |
2640 KB |
Output is correct |
10 |
Correct |
2 ms |
2640 KB |
Output is correct |
11 |
Correct |
2 ms |
2640 KB |
Output is correct |
12 |
Correct |
2 ms |
2640 KB |
Output is correct |
13 |
Correct |
2 ms |
2640 KB |
Output is correct |
14 |
Correct |
2 ms |
2748 KB |
Output is correct |
15 |
Correct |
2 ms |
2732 KB |
Output is correct |
16 |
Correct |
2 ms |
2768 KB |
Output is correct |
17 |
Correct |
2 ms |
2768 KB |
Output is correct |
18 |
Correct |
3 ms |
2768 KB |
Output is correct |
19 |
Correct |
2 ms |
2768 KB |
Output is correct |
20 |
Correct |
3 ms |
2768 KB |
Output is correct |
21 |
Correct |
3 ms |
2768 KB |
Output is correct |
22 |
Correct |
2 ms |
2640 KB |
Output is correct |
23 |
Correct |
2 ms |
2640 KB |
Output is correct |
24 |
Correct |
2 ms |
2768 KB |
Output is correct |
25 |
Correct |
2 ms |
2812 KB |
Output is correct |
26 |
Correct |
3 ms |
2768 KB |
Output is correct |
27 |
Correct |
2 ms |
2768 KB |
Output is correct |
28 |
Correct |
3 ms |
2768 KB |
Output is correct |
29 |
Correct |
3 ms |
2640 KB |
Output is correct |
30 |
Correct |
3 ms |
2640 KB |
Output is correct |
31 |
Correct |
2 ms |
2700 KB |
Output is correct |
32 |
Correct |
3 ms |
2768 KB |
Output is correct |
33 |
Correct |
4 ms |
2708 KB |
Output is correct |
34 |
Correct |
3 ms |
2768 KB |
Output is correct |
35 |
Correct |
2 ms |
2640 KB |
Output is correct |
36 |
Correct |
2 ms |
2768 KB |
Output is correct |
37 |
Correct |
2 ms |
2768 KB |
Output is correct |
38 |
Correct |
2 ms |
2768 KB |
Output is correct |
39 |
Correct |
2 ms |
2640 KB |
Output is correct |
40 |
Correct |
3 ms |
2768 KB |
Output is correct |
41 |
Correct |
3 ms |
2768 KB |
Output is correct |
42 |
Correct |
2 ms |
2640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3031 ms |
7024 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3031 ms |
7024 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2640 KB |
Output is correct |
2 |
Correct |
2 ms |
2640 KB |
Output is correct |
3 |
Correct |
2 ms |
2640 KB |
Output is correct |
4 |
Correct |
2 ms |
2640 KB |
Output is correct |
5 |
Correct |
2 ms |
2640 KB |
Output is correct |
6 |
Correct |
2 ms |
2748 KB |
Output is correct |
7 |
Correct |
2 ms |
2732 KB |
Output is correct |
8 |
Correct |
2 ms |
2768 KB |
Output is correct |
9 |
Correct |
2 ms |
2768 KB |
Output is correct |
10 |
Correct |
3 ms |
2768 KB |
Output is correct |
11 |
Correct |
2 ms |
2768 KB |
Output is correct |
12 |
Correct |
3 ms |
2768 KB |
Output is correct |
13 |
Execution timed out |
3031 ms |
7024 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2640 KB |
Output is correct |
2 |
Correct |
2 ms |
2640 KB |
Output is correct |
3 |
Correct |
2 ms |
2640 KB |
Output is correct |
4 |
Correct |
2 ms |
2640 KB |
Output is correct |
5 |
Correct |
3 ms |
2660 KB |
Output is correct |
6 |
Correct |
2 ms |
2640 KB |
Output is correct |
7 |
Correct |
2 ms |
2640 KB |
Output is correct |
8 |
Correct |
3 ms |
2640 KB |
Output is correct |
9 |
Correct |
2 ms |
2640 KB |
Output is correct |
10 |
Correct |
2 ms |
2640 KB |
Output is correct |
11 |
Correct |
2 ms |
2640 KB |
Output is correct |
12 |
Correct |
2 ms |
2640 KB |
Output is correct |
13 |
Correct |
2 ms |
2640 KB |
Output is correct |
14 |
Correct |
2 ms |
2748 KB |
Output is correct |
15 |
Correct |
2 ms |
2732 KB |
Output is correct |
16 |
Correct |
2 ms |
2768 KB |
Output is correct |
17 |
Correct |
2 ms |
2768 KB |
Output is correct |
18 |
Correct |
3 ms |
2768 KB |
Output is correct |
19 |
Correct |
2 ms |
2768 KB |
Output is correct |
20 |
Correct |
3 ms |
2768 KB |
Output is correct |
21 |
Correct |
3 ms |
2768 KB |
Output is correct |
22 |
Correct |
2 ms |
2640 KB |
Output is correct |
23 |
Correct |
2 ms |
2640 KB |
Output is correct |
24 |
Correct |
2 ms |
2768 KB |
Output is correct |
25 |
Correct |
2 ms |
2812 KB |
Output is correct |
26 |
Correct |
3 ms |
2768 KB |
Output is correct |
27 |
Correct |
2 ms |
2768 KB |
Output is correct |
28 |
Correct |
3 ms |
2768 KB |
Output is correct |
29 |
Correct |
3 ms |
2640 KB |
Output is correct |
30 |
Correct |
3 ms |
2640 KB |
Output is correct |
31 |
Correct |
2 ms |
2700 KB |
Output is correct |
32 |
Correct |
3 ms |
2768 KB |
Output is correct |
33 |
Correct |
4 ms |
2708 KB |
Output is correct |
34 |
Correct |
3 ms |
2768 KB |
Output is correct |
35 |
Correct |
2 ms |
2640 KB |
Output is correct |
36 |
Correct |
2 ms |
2768 KB |
Output is correct |
37 |
Correct |
2 ms |
2768 KB |
Output is correct |
38 |
Correct |
2 ms |
2768 KB |
Output is correct |
39 |
Correct |
2 ms |
2640 KB |
Output is correct |
40 |
Correct |
3 ms |
2768 KB |
Output is correct |
41 |
Correct |
3 ms |
2768 KB |
Output is correct |
42 |
Correct |
2 ms |
2640 KB |
Output is correct |
43 |
Correct |
1754 ms |
3024 KB |
Output is correct |
44 |
Correct |
2513 ms |
3036 KB |
Output is correct |
45 |
Correct |
2397 ms |
3036 KB |
Output is correct |
46 |
Execution timed out |
3021 ms |
3280 KB |
Time limit exceeded |
47 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2640 KB |
Output is correct |
2 |
Correct |
2 ms |
2640 KB |
Output is correct |
3 |
Correct |
2 ms |
2640 KB |
Output is correct |
4 |
Correct |
2 ms |
2640 KB |
Output is correct |
5 |
Correct |
3 ms |
2660 KB |
Output is correct |
6 |
Correct |
2 ms |
2640 KB |
Output is correct |
7 |
Correct |
2 ms |
2640 KB |
Output is correct |
8 |
Correct |
3 ms |
2640 KB |
Output is correct |
9 |
Correct |
2 ms |
2640 KB |
Output is correct |
10 |
Correct |
2 ms |
2640 KB |
Output is correct |
11 |
Correct |
2 ms |
2640 KB |
Output is correct |
12 |
Correct |
2 ms |
2640 KB |
Output is correct |
13 |
Correct |
2 ms |
2640 KB |
Output is correct |
14 |
Correct |
2 ms |
2748 KB |
Output is correct |
15 |
Correct |
2 ms |
2732 KB |
Output is correct |
16 |
Correct |
2 ms |
2768 KB |
Output is correct |
17 |
Correct |
2 ms |
2768 KB |
Output is correct |
18 |
Correct |
3 ms |
2768 KB |
Output is correct |
19 |
Correct |
2 ms |
2768 KB |
Output is correct |
20 |
Correct |
3 ms |
2768 KB |
Output is correct |
21 |
Correct |
3 ms |
2768 KB |
Output is correct |
22 |
Correct |
2 ms |
2640 KB |
Output is correct |
23 |
Correct |
2 ms |
2640 KB |
Output is correct |
24 |
Correct |
2 ms |
2768 KB |
Output is correct |
25 |
Correct |
2 ms |
2812 KB |
Output is correct |
26 |
Correct |
3 ms |
2768 KB |
Output is correct |
27 |
Correct |
2 ms |
2768 KB |
Output is correct |
28 |
Correct |
3 ms |
2768 KB |
Output is correct |
29 |
Correct |
3 ms |
2640 KB |
Output is correct |
30 |
Correct |
3 ms |
2640 KB |
Output is correct |
31 |
Correct |
2 ms |
2700 KB |
Output is correct |
32 |
Correct |
3 ms |
2768 KB |
Output is correct |
33 |
Correct |
4 ms |
2708 KB |
Output is correct |
34 |
Correct |
3 ms |
2768 KB |
Output is correct |
35 |
Correct |
2 ms |
2640 KB |
Output is correct |
36 |
Correct |
2 ms |
2768 KB |
Output is correct |
37 |
Correct |
2 ms |
2768 KB |
Output is correct |
38 |
Correct |
2 ms |
2768 KB |
Output is correct |
39 |
Correct |
2 ms |
2640 KB |
Output is correct |
40 |
Correct |
3 ms |
2768 KB |
Output is correct |
41 |
Correct |
3 ms |
2768 KB |
Output is correct |
42 |
Correct |
2 ms |
2640 KB |
Output is correct |
43 |
Execution timed out |
3031 ms |
7024 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |