#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,seg[800009],seg2[800009],JM[200009],M,l,r,z,za;
vector <long long> v[200009];
void pushdown(long long q, long long w, long long rr){
if(q!=w){
seg2[rr*2]^=seg2[rr];
seg2[rr*2+1]^=seg2[rr];
}
if(seg2[rr]!=0){
seg2[rr]=0;
seg[rr]=JM[w]-JM[q-1]-seg[rr]+mod*2;
seg[rr]%=mod;
}
}
void upd(long long q, long long w, long long rr){
pushdown(q,w,rr);
if(q>r||w<l) return;
if(q>=l&&w<=r){
seg2[rr]^=1;
pushdown(q,w,rr);
return;
}
upd(q,(q+w)/2,rr*2);
upd((q+w)/2+1,w,rr*2+1);
seg[rr]=seg[rr*2]+seg[rr*2+1];
seg[rr]%=mod;
}
void read(long long q, long long w, long long rr){
pushdown(q,w,rr);
if(q>r||w<l) return;
if(q>=l&&w<=r){
z+=seg[rr];
z%=mod;
return;
}
read(q,(q+w)/2,rr*2);
read((q+w)/2+1,w,rr*2+1);
}
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;M=MM;
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);
za=1;
while(za<a-N) za*=2;
for(i=N+1; i<=a; i++){
JM[i-N]=dp[i];
}
for(i=1; i<=M; i++){
JM[i]+=JM[i-1];JM[i]%=mod;
}
for(i=N+1; i<=a; i++){
if(f[i]==0) continue;
l=i-N;r=i-N;z=1;
upd(1,za,1);
}
/*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;
}
}*/
l=L-N;r=R-N;z=1;
upd(1,za,1);
l=1;r=a-N;z=0;
read(1,za,1);
pas=z;
return pas;
}
Compilation message
circuit.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>)':
circuit.cpp:77:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
77 | for(ii=1; ii<P.size(); ii++){
| ~~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
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 |
2 ms |
5072 KB |
Output is correct |
5 |
Correct |
3 ms |
5072 KB |
Output is correct |
6 |
Correct |
3 ms |
5072 KB |
Output is correct |
7 |
Correct |
3 ms |
5072 KB |
Output is correct |
8 |
Correct |
3 ms |
5072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
2 ms |
5072 KB |
Output is correct |
3 |
Correct |
2 ms |
5072 KB |
Output is correct |
4 |
Correct |
2 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 |
3 ms |
5200 KB |
Output is correct |
8 |
Correct |
3 ms |
5200 KB |
Output is correct |
9 |
Correct |
3 ms |
5200 KB |
Output is correct |
10 |
Correct |
3 ms |
5200 KB |
Output is correct |
11 |
Correct |
3 ms |
5200 KB |
Output is correct |
12 |
Correct |
4 ms |
5072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
2 ms |
5072 KB |
Output is correct |
5 |
Correct |
3 ms |
5072 KB |
Output is correct |
6 |
Correct |
3 ms |
5072 KB |
Output is correct |
7 |
Correct |
3 ms |
5072 KB |
Output is correct |
8 |
Correct |
3 ms |
5072 KB |
Output is correct |
9 |
Correct |
2 ms |
4944 KB |
Output is correct |
10 |
Correct |
2 ms |
5072 KB |
Output is correct |
11 |
Correct |
2 ms |
5072 KB |
Output is correct |
12 |
Correct |
2 ms |
5072 KB |
Output is correct |
13 |
Correct |
2 ms |
5072 KB |
Output is correct |
14 |
Correct |
2 ms |
5072 KB |
Output is correct |
15 |
Correct |
3 ms |
5200 KB |
Output is correct |
16 |
Correct |
3 ms |
5200 KB |
Output is correct |
17 |
Correct |
3 ms |
5200 KB |
Output is correct |
18 |
Correct |
3 ms |
5200 KB |
Output is correct |
19 |
Correct |
3 ms |
5200 KB |
Output is correct |
20 |
Correct |
4 ms |
5072 KB |
Output is correct |
21 |
Correct |
3 ms |
5200 KB |
Output is correct |
22 |
Correct |
2 ms |
5072 KB |
Output is correct |
23 |
Correct |
2 ms |
5068 KB |
Output is correct |
24 |
Correct |
3 ms |
5200 KB |
Output is correct |
25 |
Correct |
3 ms |
5200 KB |
Output is correct |
26 |
Correct |
3 ms |
5200 KB |
Output is correct |
27 |
Correct |
3 ms |
5200 KB |
Output is correct |
28 |
Correct |
3 ms |
5200 KB |
Output is correct |
29 |
Correct |
3 ms |
5072 KB |
Output is correct |
30 |
Correct |
3 ms |
5072 KB |
Output is correct |
31 |
Correct |
3 ms |
5072 KB |
Output is correct |
32 |
Correct |
3 ms |
5200 KB |
Output is correct |
33 |
Correct |
3 ms |
5072 KB |
Output is correct |
34 |
Correct |
3 ms |
5072 KB |
Output is correct |
35 |
Correct |
2 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 |
3 ms |
5200 KB |
Output is correct |
39 |
Correct |
2 ms |
5072 KB |
Output is correct |
40 |
Correct |
3 ms |
5072 KB |
Output is correct |
41 |
Correct |
3 ms |
5072 KB |
Output is correct |
42 |
Correct |
3 ms |
5072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
527 ms |
10388 KB |
Output is correct |
2 |
Correct |
700 ms |
15784 KB |
Output is correct |
3 |
Correct |
583 ms |
15748 KB |
Output is correct |
4 |
Correct |
560 ms |
15056 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
527 ms |
10388 KB |
Output is correct |
2 |
Correct |
700 ms |
15784 KB |
Output is correct |
3 |
Correct |
583 ms |
15748 KB |
Output is correct |
4 |
Correct |
560 ms |
15056 KB |
Output is correct |
5 |
Correct |
583 ms |
10396 KB |
Output is correct |
6 |
Correct |
807 ms |
15944 KB |
Output is correct |
7 |
Correct |
687 ms |
15764 KB |
Output is correct |
8 |
Correct |
901 ms |
15688 KB |
Output is correct |
9 |
Correct |
402 ms |
5328 KB |
Output is correct |
10 |
Correct |
689 ms |
5712 KB |
Output is correct |
11 |
Correct |
701 ms |
5712 KB |
Output is correct |
12 |
Correct |
698 ms |
5712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
2 ms |
5072 KB |
Output is correct |
3 |
Correct |
2 ms |
5072 KB |
Output is correct |
4 |
Correct |
2 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 |
3 ms |
5200 KB |
Output is correct |
8 |
Correct |
3 ms |
5200 KB |
Output is correct |
9 |
Correct |
3 ms |
5200 KB |
Output is correct |
10 |
Correct |
3 ms |
5200 KB |
Output is correct |
11 |
Correct |
3 ms |
5200 KB |
Output is correct |
12 |
Correct |
4 ms |
5072 KB |
Output is correct |
13 |
Correct |
527 ms |
10388 KB |
Output is correct |
14 |
Correct |
700 ms |
15784 KB |
Output is correct |
15 |
Correct |
583 ms |
15748 KB |
Output is correct |
16 |
Correct |
560 ms |
15056 KB |
Output is correct |
17 |
Correct |
583 ms |
10396 KB |
Output is correct |
18 |
Correct |
807 ms |
15944 KB |
Output is correct |
19 |
Correct |
687 ms |
15764 KB |
Output is correct |
20 |
Correct |
901 ms |
15688 KB |
Output is correct |
21 |
Correct |
402 ms |
5328 KB |
Output is correct |
22 |
Correct |
689 ms |
5712 KB |
Output is correct |
23 |
Correct |
701 ms |
5712 KB |
Output is correct |
24 |
Correct |
698 ms |
5712 KB |
Output is correct |
25 |
Correct |
944 ms |
21120 KB |
Output is correct |
26 |
Correct |
950 ms |
21448 KB |
Output is correct |
27 |
Correct |
729 ms |
21468 KB |
Output is correct |
28 |
Correct |
697 ms |
21628 KB |
Output is correct |
29 |
Correct |
799 ms |
26112 KB |
Output is correct |
30 |
Correct |
656 ms |
26108 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
2 ms |
5072 KB |
Output is correct |
5 |
Correct |
3 ms |
5072 KB |
Output is correct |
6 |
Correct |
3 ms |
5072 KB |
Output is correct |
7 |
Correct |
3 ms |
5072 KB |
Output is correct |
8 |
Correct |
3 ms |
5072 KB |
Output is correct |
9 |
Correct |
2 ms |
4944 KB |
Output is correct |
10 |
Correct |
2 ms |
5072 KB |
Output is correct |
11 |
Correct |
2 ms |
5072 KB |
Output is correct |
12 |
Correct |
2 ms |
5072 KB |
Output is correct |
13 |
Correct |
2 ms |
5072 KB |
Output is correct |
14 |
Correct |
2 ms |
5072 KB |
Output is correct |
15 |
Correct |
3 ms |
5200 KB |
Output is correct |
16 |
Correct |
3 ms |
5200 KB |
Output is correct |
17 |
Correct |
3 ms |
5200 KB |
Output is correct |
18 |
Correct |
3 ms |
5200 KB |
Output is correct |
19 |
Correct |
3 ms |
5200 KB |
Output is correct |
20 |
Correct |
4 ms |
5072 KB |
Output is correct |
21 |
Correct |
3 ms |
5200 KB |
Output is correct |
22 |
Correct |
2 ms |
5072 KB |
Output is correct |
23 |
Correct |
2 ms |
5068 KB |
Output is correct |
24 |
Correct |
3 ms |
5200 KB |
Output is correct |
25 |
Correct |
3 ms |
5200 KB |
Output is correct |
26 |
Correct |
3 ms |
5200 KB |
Output is correct |
27 |
Correct |
3 ms |
5200 KB |
Output is correct |
28 |
Correct |
3 ms |
5200 KB |
Output is correct |
29 |
Correct |
3 ms |
5072 KB |
Output is correct |
30 |
Correct |
3 ms |
5072 KB |
Output is correct |
31 |
Correct |
3 ms |
5072 KB |
Output is correct |
32 |
Correct |
3 ms |
5200 KB |
Output is correct |
33 |
Correct |
3 ms |
5072 KB |
Output is correct |
34 |
Correct |
3 ms |
5072 KB |
Output is correct |
35 |
Correct |
2 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 |
3 ms |
5200 KB |
Output is correct |
39 |
Correct |
2 ms |
5072 KB |
Output is correct |
40 |
Correct |
3 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 |
485 ms |
5456 KB |
Output is correct |
44 |
Correct |
740 ms |
5584 KB |
Output is correct |
45 |
Correct |
618 ms |
5584 KB |
Output is correct |
46 |
Correct |
541 ms |
5840 KB |
Output is correct |
47 |
Correct |
839 ms |
5840 KB |
Output is correct |
48 |
Correct |
691 ms |
5840 KB |
Output is correct |
49 |
Correct |
642 ms |
5840 KB |
Output is correct |
50 |
Correct |
757 ms |
5840 KB |
Output is correct |
51 |
Correct |
778 ms |
5648 KB |
Output is correct |
52 |
Correct |
835 ms |
5644 KB |
Output is correct |
53 |
Correct |
694 ms |
5584 KB |
Output is correct |
54 |
Correct |
654 ms |
5840 KB |
Output is correct |
55 |
Correct |
810 ms |
5784 KB |
Output is correct |
56 |
Correct |
746 ms |
5712 KB |
Output is correct |
57 |
Correct |
573 ms |
5584 KB |
Output is correct |
58 |
Correct |
716 ms |
6096 KB |
Output is correct |
59 |
Correct |
726 ms |
6240 KB |
Output is correct |
60 |
Correct |
812 ms |
6232 KB |
Output is correct |
61 |
Correct |
855 ms |
5584 KB |
Output is correct |
62 |
Correct |
673 ms |
5440 KB |
Output is correct |
63 |
Correct |
922 ms |
5456 KB |
Output is correct |
64 |
Correct |
563 ms |
5584 KB |
Output is correct |
65 |
Correct |
322 ms |
5328 KB |
Output is correct |
66 |
Correct |
794 ms |
5712 KB |
Output is correct |
67 |
Correct |
841 ms |
5712 KB |
Output is correct |
68 |
Correct |
855 ms |
5712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
2 ms |
5072 KB |
Output is correct |
5 |
Correct |
3 ms |
5072 KB |
Output is correct |
6 |
Correct |
3 ms |
5072 KB |
Output is correct |
7 |
Correct |
3 ms |
5072 KB |
Output is correct |
8 |
Correct |
3 ms |
5072 KB |
Output is correct |
9 |
Correct |
2 ms |
4944 KB |
Output is correct |
10 |
Correct |
2 ms |
5072 KB |
Output is correct |
11 |
Correct |
2 ms |
5072 KB |
Output is correct |
12 |
Correct |
2 ms |
5072 KB |
Output is correct |
13 |
Correct |
2 ms |
5072 KB |
Output is correct |
14 |
Correct |
2 ms |
5072 KB |
Output is correct |
15 |
Correct |
3 ms |
5200 KB |
Output is correct |
16 |
Correct |
3 ms |
5200 KB |
Output is correct |
17 |
Correct |
3 ms |
5200 KB |
Output is correct |
18 |
Correct |
3 ms |
5200 KB |
Output is correct |
19 |
Correct |
3 ms |
5200 KB |
Output is correct |
20 |
Correct |
4 ms |
5072 KB |
Output is correct |
21 |
Correct |
3 ms |
5200 KB |
Output is correct |
22 |
Correct |
2 ms |
5072 KB |
Output is correct |
23 |
Correct |
2 ms |
5068 KB |
Output is correct |
24 |
Correct |
3 ms |
5200 KB |
Output is correct |
25 |
Correct |
3 ms |
5200 KB |
Output is correct |
26 |
Correct |
3 ms |
5200 KB |
Output is correct |
27 |
Correct |
3 ms |
5200 KB |
Output is correct |
28 |
Correct |
3 ms |
5200 KB |
Output is correct |
29 |
Correct |
3 ms |
5072 KB |
Output is correct |
30 |
Correct |
3 ms |
5072 KB |
Output is correct |
31 |
Correct |
3 ms |
5072 KB |
Output is correct |
32 |
Correct |
3 ms |
5200 KB |
Output is correct |
33 |
Correct |
3 ms |
5072 KB |
Output is correct |
34 |
Correct |
3 ms |
5072 KB |
Output is correct |
35 |
Correct |
2 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 |
3 ms |
5200 KB |
Output is correct |
39 |
Correct |
2 ms |
5072 KB |
Output is correct |
40 |
Correct |
3 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 |
527 ms |
10388 KB |
Output is correct |
44 |
Correct |
700 ms |
15784 KB |
Output is correct |
45 |
Correct |
583 ms |
15748 KB |
Output is correct |
46 |
Correct |
560 ms |
15056 KB |
Output is correct |
47 |
Correct |
583 ms |
10396 KB |
Output is correct |
48 |
Correct |
807 ms |
15944 KB |
Output is correct |
49 |
Correct |
687 ms |
15764 KB |
Output is correct |
50 |
Correct |
901 ms |
15688 KB |
Output is correct |
51 |
Correct |
402 ms |
5328 KB |
Output is correct |
52 |
Correct |
689 ms |
5712 KB |
Output is correct |
53 |
Correct |
701 ms |
5712 KB |
Output is correct |
54 |
Correct |
698 ms |
5712 KB |
Output is correct |
55 |
Correct |
944 ms |
21120 KB |
Output is correct |
56 |
Correct |
950 ms |
21448 KB |
Output is correct |
57 |
Correct |
729 ms |
21468 KB |
Output is correct |
58 |
Correct |
697 ms |
21628 KB |
Output is correct |
59 |
Correct |
799 ms |
26112 KB |
Output is correct |
60 |
Correct |
656 ms |
26108 KB |
Output is correct |
61 |
Correct |
485 ms |
5456 KB |
Output is correct |
62 |
Correct |
740 ms |
5584 KB |
Output is correct |
63 |
Correct |
618 ms |
5584 KB |
Output is correct |
64 |
Correct |
541 ms |
5840 KB |
Output is correct |
65 |
Correct |
839 ms |
5840 KB |
Output is correct |
66 |
Correct |
691 ms |
5840 KB |
Output is correct |
67 |
Correct |
642 ms |
5840 KB |
Output is correct |
68 |
Correct |
757 ms |
5840 KB |
Output is correct |
69 |
Correct |
778 ms |
5648 KB |
Output is correct |
70 |
Correct |
835 ms |
5644 KB |
Output is correct |
71 |
Correct |
694 ms |
5584 KB |
Output is correct |
72 |
Correct |
654 ms |
5840 KB |
Output is correct |
73 |
Correct |
810 ms |
5784 KB |
Output is correct |
74 |
Correct |
746 ms |
5712 KB |
Output is correct |
75 |
Correct |
573 ms |
5584 KB |
Output is correct |
76 |
Correct |
716 ms |
6096 KB |
Output is correct |
77 |
Correct |
726 ms |
6240 KB |
Output is correct |
78 |
Correct |
812 ms |
6232 KB |
Output is correct |
79 |
Correct |
855 ms |
5584 KB |
Output is correct |
80 |
Correct |
673 ms |
5440 KB |
Output is correct |
81 |
Correct |
922 ms |
5456 KB |
Output is correct |
82 |
Correct |
563 ms |
5584 KB |
Output is correct |
83 |
Correct |
322 ms |
5328 KB |
Output is correct |
84 |
Correct |
794 ms |
5712 KB |
Output is correct |
85 |
Correct |
841 ms |
5712 KB |
Output is correct |
86 |
Correct |
855 ms |
5712 KB |
Output is correct |
87 |
Correct |
2 ms |
4944 KB |
Output is correct |
88 |
Correct |
600 ms |
19804 KB |
Output is correct |
89 |
Correct |
767 ms |
15196 KB |
Output is correct |
90 |
Correct |
898 ms |
15448 KB |
Output is correct |
91 |
Correct |
676 ms |
22040 KB |
Output is correct |
92 |
Correct |
1041 ms |
22068 KB |
Output is correct |
93 |
Correct |
655 ms |
20972 KB |
Output is correct |
94 |
Correct |
1058 ms |
22012 KB |
Output is correct |
95 |
Correct |
902 ms |
22036 KB |
Output is correct |
96 |
Correct |
598 ms |
15360 KB |
Output is correct |
97 |
Correct |
918 ms |
15424 KB |
Output is correct |
98 |
Correct |
811 ms |
16712 KB |
Output is correct |
99 |
Correct |
762 ms |
21396 KB |
Output is correct |
100 |
Correct |
932 ms |
19008 KB |
Output is correct |
101 |
Correct |
669 ms |
17536 KB |
Output is correct |
102 |
Correct |
723 ms |
15416 KB |
Output is correct |
103 |
Correct |
776 ms |
26104 KB |
Output is correct |
104 |
Correct |
790 ms |
27024 KB |
Output is correct |
105 |
Correct |
917 ms |
27076 KB |
Output is correct |
106 |
Correct |
866 ms |
15480 KB |
Output is correct |
107 |
Correct |
844 ms |
14464 KB |
Output is correct |
108 |
Correct |
934 ms |
15236 KB |
Output is correct |
109 |
Correct |
733 ms |
15512 KB |
Output is correct |