#include "circuit.h"
#include <bits/stdc++.h>
#include <vector>
#define MAXN 200007
#define MOD 1000002022
using namespace std;
vector<int> g[MAXN];
long long a[MAXN],t[MAXN],seg[2][4*MAXN];
int n,m,p[MAXN],st[MAXN],bag[4*MAXN];
void dfst(int s)
{
for(int i=0;i<g[s].size();i++) dfst(g[s][i]);
if(g[s].size()==0) t[s]=1;
else t[s]=g[s].size();
for(int i=0;i<g[s].size();i++) t[s]=(t[s]*t[g[s][i]])%MOD;
}
void dfs(int s,long long p)
{
if(s>=n) {a[s-n]=p%MOD; return;}
vector<long long> lv(g[s].size()+7),ds(g[s].size()+7);
ds[0]=1; lv[g[s].size()+1]=1;
for(int i=0;i<g[s].size();i++) ds[i+1]=(ds[i]*t[g[s][i]])%MOD;
for(int i=g[s].size()-1;i>=0;i--) lv[i+1]=(lv[i+2]*t[g[s][i]])%MOD;
for(int i=0;i<g[s].size();i++) dfs(g[s][i],(p*((ds[i]*lv[i+2])%MOD))%MOD);
}
void build(int l,int r,int ind)
{
if(l==r) {seg[st[l]][ind]=a[l]; return;}
int s=(l+r)/2;
build(l,s,2*ind);
build(s+1,r,2*ind+1);
for(int k=0;k<2;k++) seg[k][ind]=(seg[k][2*ind]+seg[k][2*ind+1])%MOD;
}
void relax(int ind)
{
bag[2*ind]^=bag[ind]; bag[2*ind+1]^=bag[ind];
bag[ind]=0;
}
void upd(int lt,int rt,int l,int r,int ind)
{
if(r<lt || l>rt) return;
if(l>=lt && r<=rt) {bag[ind]^=1; return;}
relax(ind);
int s=(l+r)/2;
upd(lt,rt,l,s,2*ind);
upd(lt,rt,s+1,r,2*ind+1);
for(int k=0;k<2;k++) seg[k][ind]=(seg[k^bag[2*ind]][2*ind]+seg[k^bag[2*ind+1]][2*ind+1])%MOD;
}
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
n=N; m=M;
for(int i=1;i<N+M;i++) g[P[i]].push_back(i);
for(int i=0;i<M;i++) st[i]=A[i];
dfst(0); dfs(0,1);
build(0,m-1,1);
}
int count_ways(int L, int R) {
upd(L-n,R-n,0,m-1,1);
return seg[1^bag[1]][1];
}
Compilation message
circuit.cpp: In function 'void dfst(int)':
circuit.cpp:12:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
12 | for(int i=0;i<g[s].size();i++) dfst(g[s][i]);
| ~^~~~~~~~~~~~
circuit.cpp:15:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
15 | for(int i=0;i<g[s].size();i++) t[s]=(t[s]*t[g[s][i]])%MOD;
| ~^~~~~~~~~~~~
circuit.cpp: In function 'void dfs(int, long long int)':
circuit.cpp:22:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | for(int i=0;i<g[s].size();i++) ds[i+1]=(ds[i]*t[g[s][i]])%MOD;
| ~^~~~~~~~~~~~
circuit.cpp:24:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | for(int i=0;i<g[s].size();i++) dfs(g[s][i],(p*((ds[i]*lv[i+2])%MOD))%MOD);
| ~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5072 KB |
Output is correct |
2 |
Correct |
3 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 |
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 |
3 ms |
4944 KB |
Output is correct |
2 |
Correct |
3 ms |
4944 KB |
Output is correct |
3 |
Correct |
3 ms |
5072 KB |
Output is correct |
4 |
Correct |
3 ms |
5096 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 |
5108 KB |
Output is correct |
9 |
Correct |
3 ms |
5104 KB |
Output is correct |
10 |
Correct |
4 ms |
5328 KB |
Output is correct |
11 |
Correct |
3 ms |
5328 KB |
Output is correct |
12 |
Correct |
3 ms |
5072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5072 KB |
Output is correct |
2 |
Correct |
3 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 |
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 |
3 ms |
4944 KB |
Output is correct |
10 |
Correct |
3 ms |
4944 KB |
Output is correct |
11 |
Correct |
3 ms |
5072 KB |
Output is correct |
12 |
Correct |
3 ms |
5096 KB |
Output is correct |
13 |
Correct |
3 ms |
5072 KB |
Output is correct |
14 |
Correct |
3 ms |
5072 KB |
Output is correct |
15 |
Correct |
3 ms |
5072 KB |
Output is correct |
16 |
Correct |
3 ms |
5108 KB |
Output is correct |
17 |
Correct |
3 ms |
5104 KB |
Output is correct |
18 |
Correct |
4 ms |
5328 KB |
Output is correct |
19 |
Correct |
3 ms |
5328 KB |
Output is correct |
20 |
Correct |
3 ms |
5072 KB |
Output is correct |
21 |
Correct |
3 ms |
5072 KB |
Output is correct |
22 |
Correct |
3 ms |
5072 KB |
Output is correct |
23 |
Correct |
3 ms |
5072 KB |
Output is correct |
24 |
Correct |
3 ms |
5072 KB |
Output is correct |
25 |
Correct |
5 ms |
5144 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 |
4 ms |
5072 KB |
Output is correct |
30 |
Correct |
3 ms |
5072 KB |
Output is correct |
31 |
Correct |
3 ms |
5328 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 |
5072 KB |
Output is correct |
35 |
Correct |
3 ms |
5072 KB |
Output is correct |
36 |
Correct |
3 ms |
5328 KB |
Output is correct |
37 |
Correct |
3 ms |
5328 KB |
Output is correct |
38 |
Correct |
3 ms |
5328 KB |
Output is correct |
39 |
Correct |
3 ms |
5072 KB |
Output is correct |
40 |
Correct |
3 ms |
5024 KB |
Output is correct |
41 |
Correct |
3 ms |
5120 KB |
Output is correct |
42 |
Correct |
3 ms |
5124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
493 ms |
8712 KB |
Output is correct |
2 |
Correct |
847 ms |
12416 KB |
Output is correct |
3 |
Correct |
809 ms |
11848 KB |
Output is correct |
4 |
Correct |
894 ms |
11848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
493 ms |
8712 KB |
Output is correct |
2 |
Correct |
847 ms |
12416 KB |
Output is correct |
3 |
Correct |
809 ms |
11848 KB |
Output is correct |
4 |
Correct |
894 ms |
11848 KB |
Output is correct |
5 |
Correct |
747 ms |
8712 KB |
Output is correct |
6 |
Correct |
712 ms |
12360 KB |
Output is correct |
7 |
Correct |
808 ms |
12624 KB |
Output is correct |
8 |
Correct |
716 ms |
12364 KB |
Output is correct |
9 |
Correct |
391 ms |
5200 KB |
Output is correct |
10 |
Correct |
818 ms |
5456 KB |
Output is correct |
11 |
Correct |
822 ms |
5456 KB |
Output is correct |
12 |
Correct |
738 ms |
5456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4944 KB |
Output is correct |
2 |
Correct |
3 ms |
4944 KB |
Output is correct |
3 |
Correct |
3 ms |
5072 KB |
Output is correct |
4 |
Correct |
3 ms |
5096 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 |
5108 KB |
Output is correct |
9 |
Correct |
3 ms |
5104 KB |
Output is correct |
10 |
Correct |
4 ms |
5328 KB |
Output is correct |
11 |
Correct |
3 ms |
5328 KB |
Output is correct |
12 |
Correct |
3 ms |
5072 KB |
Output is correct |
13 |
Correct |
493 ms |
8712 KB |
Output is correct |
14 |
Correct |
847 ms |
12416 KB |
Output is correct |
15 |
Correct |
809 ms |
11848 KB |
Output is correct |
16 |
Correct |
894 ms |
11848 KB |
Output is correct |
17 |
Correct |
747 ms |
8712 KB |
Output is correct |
18 |
Correct |
712 ms |
12360 KB |
Output is correct |
19 |
Correct |
808 ms |
12624 KB |
Output is correct |
20 |
Correct |
716 ms |
12364 KB |
Output is correct |
21 |
Correct |
391 ms |
5200 KB |
Output is correct |
22 |
Correct |
818 ms |
5456 KB |
Output is correct |
23 |
Correct |
822 ms |
5456 KB |
Output is correct |
24 |
Correct |
738 ms |
5456 KB |
Output is correct |
25 |
Correct |
834 ms |
17188 KB |
Output is correct |
26 |
Correct |
1000 ms |
17340 KB |
Output is correct |
27 |
Correct |
946 ms |
17308 KB |
Output is correct |
28 |
Correct |
764 ms |
17324 KB |
Output is correct |
29 |
Correct |
992 ms |
45512 KB |
Output is correct |
30 |
Correct |
728 ms |
45468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5072 KB |
Output is correct |
2 |
Correct |
3 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 |
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 |
3 ms |
4944 KB |
Output is correct |
10 |
Correct |
3 ms |
4944 KB |
Output is correct |
11 |
Correct |
3 ms |
5072 KB |
Output is correct |
12 |
Correct |
3 ms |
5096 KB |
Output is correct |
13 |
Correct |
3 ms |
5072 KB |
Output is correct |
14 |
Correct |
3 ms |
5072 KB |
Output is correct |
15 |
Correct |
3 ms |
5072 KB |
Output is correct |
16 |
Correct |
3 ms |
5108 KB |
Output is correct |
17 |
Correct |
3 ms |
5104 KB |
Output is correct |
18 |
Correct |
4 ms |
5328 KB |
Output is correct |
19 |
Correct |
3 ms |
5328 KB |
Output is correct |
20 |
Correct |
3 ms |
5072 KB |
Output is correct |
21 |
Correct |
3 ms |
5072 KB |
Output is correct |
22 |
Correct |
3 ms |
5072 KB |
Output is correct |
23 |
Correct |
3 ms |
5072 KB |
Output is correct |
24 |
Correct |
3 ms |
5072 KB |
Output is correct |
25 |
Correct |
5 ms |
5144 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 |
4 ms |
5072 KB |
Output is correct |
30 |
Correct |
3 ms |
5072 KB |
Output is correct |
31 |
Correct |
3 ms |
5328 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 |
5072 KB |
Output is correct |
35 |
Correct |
3 ms |
5072 KB |
Output is correct |
36 |
Correct |
3 ms |
5328 KB |
Output is correct |
37 |
Correct |
3 ms |
5328 KB |
Output is correct |
38 |
Correct |
3 ms |
5328 KB |
Output is correct |
39 |
Correct |
3 ms |
5072 KB |
Output is correct |
40 |
Correct |
3 ms |
5024 KB |
Output is correct |
41 |
Correct |
3 ms |
5120 KB |
Output is correct |
42 |
Correct |
3 ms |
5124 KB |
Output is correct |
43 |
Correct |
571 ms |
5328 KB |
Output is correct |
44 |
Correct |
812 ms |
5456 KB |
Output is correct |
45 |
Correct |
888 ms |
5456 KB |
Output is correct |
46 |
Correct |
707 ms |
5696 KB |
Output is correct |
47 |
Correct |
901 ms |
5712 KB |
Output is correct |
48 |
Correct |
908 ms |
5584 KB |
Output is correct |
49 |
Correct |
879 ms |
5712 KB |
Output is correct |
50 |
Correct |
862 ms |
5712 KB |
Output is correct |
51 |
Correct |
785 ms |
5600 KB |
Output is correct |
52 |
Correct |
751 ms |
5704 KB |
Output is correct |
53 |
Correct |
679 ms |
6608 KB |
Output is correct |
54 |
Correct |
842 ms |
5712 KB |
Output is correct |
55 |
Correct |
870 ms |
5584 KB |
Output is correct |
56 |
Correct |
926 ms |
5584 KB |
Output is correct |
57 |
Correct |
835 ms |
5564 KB |
Output is correct |
58 |
Correct |
840 ms |
7120 KB |
Output is correct |
59 |
Correct |
790 ms |
7240 KB |
Output is correct |
60 |
Correct |
875 ms |
7216 KB |
Output is correct |
61 |
Correct |
888 ms |
5712 KB |
Output is correct |
62 |
Correct |
729 ms |
5396 KB |
Output is correct |
63 |
Correct |
905 ms |
5328 KB |
Output is correct |
64 |
Correct |
654 ms |
5584 KB |
Output is correct |
65 |
Correct |
407 ms |
5200 KB |
Output is correct |
66 |
Correct |
872 ms |
5456 KB |
Output is correct |
67 |
Correct |
867 ms |
5456 KB |
Output is correct |
68 |
Correct |
786 ms |
5456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5072 KB |
Output is correct |
2 |
Correct |
3 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 |
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 |
3 ms |
4944 KB |
Output is correct |
10 |
Correct |
3 ms |
4944 KB |
Output is correct |
11 |
Correct |
3 ms |
5072 KB |
Output is correct |
12 |
Correct |
3 ms |
5096 KB |
Output is correct |
13 |
Correct |
3 ms |
5072 KB |
Output is correct |
14 |
Correct |
3 ms |
5072 KB |
Output is correct |
15 |
Correct |
3 ms |
5072 KB |
Output is correct |
16 |
Correct |
3 ms |
5108 KB |
Output is correct |
17 |
Correct |
3 ms |
5104 KB |
Output is correct |
18 |
Correct |
4 ms |
5328 KB |
Output is correct |
19 |
Correct |
3 ms |
5328 KB |
Output is correct |
20 |
Correct |
3 ms |
5072 KB |
Output is correct |
21 |
Correct |
3 ms |
5072 KB |
Output is correct |
22 |
Correct |
3 ms |
5072 KB |
Output is correct |
23 |
Correct |
3 ms |
5072 KB |
Output is correct |
24 |
Correct |
3 ms |
5072 KB |
Output is correct |
25 |
Correct |
5 ms |
5144 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 |
4 ms |
5072 KB |
Output is correct |
30 |
Correct |
3 ms |
5072 KB |
Output is correct |
31 |
Correct |
3 ms |
5328 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 |
5072 KB |
Output is correct |
35 |
Correct |
3 ms |
5072 KB |
Output is correct |
36 |
Correct |
3 ms |
5328 KB |
Output is correct |
37 |
Correct |
3 ms |
5328 KB |
Output is correct |
38 |
Correct |
3 ms |
5328 KB |
Output is correct |
39 |
Correct |
3 ms |
5072 KB |
Output is correct |
40 |
Correct |
3 ms |
5024 KB |
Output is correct |
41 |
Correct |
3 ms |
5120 KB |
Output is correct |
42 |
Correct |
3 ms |
5124 KB |
Output is correct |
43 |
Correct |
493 ms |
8712 KB |
Output is correct |
44 |
Correct |
847 ms |
12416 KB |
Output is correct |
45 |
Correct |
809 ms |
11848 KB |
Output is correct |
46 |
Correct |
894 ms |
11848 KB |
Output is correct |
47 |
Correct |
747 ms |
8712 KB |
Output is correct |
48 |
Correct |
712 ms |
12360 KB |
Output is correct |
49 |
Correct |
808 ms |
12624 KB |
Output is correct |
50 |
Correct |
716 ms |
12364 KB |
Output is correct |
51 |
Correct |
391 ms |
5200 KB |
Output is correct |
52 |
Correct |
818 ms |
5456 KB |
Output is correct |
53 |
Correct |
822 ms |
5456 KB |
Output is correct |
54 |
Correct |
738 ms |
5456 KB |
Output is correct |
55 |
Correct |
834 ms |
17188 KB |
Output is correct |
56 |
Correct |
1000 ms |
17340 KB |
Output is correct |
57 |
Correct |
946 ms |
17308 KB |
Output is correct |
58 |
Correct |
764 ms |
17324 KB |
Output is correct |
59 |
Correct |
992 ms |
45512 KB |
Output is correct |
60 |
Correct |
728 ms |
45468 KB |
Output is correct |
61 |
Correct |
571 ms |
5328 KB |
Output is correct |
62 |
Correct |
812 ms |
5456 KB |
Output is correct |
63 |
Correct |
888 ms |
5456 KB |
Output is correct |
64 |
Correct |
707 ms |
5696 KB |
Output is correct |
65 |
Correct |
901 ms |
5712 KB |
Output is correct |
66 |
Correct |
908 ms |
5584 KB |
Output is correct |
67 |
Correct |
879 ms |
5712 KB |
Output is correct |
68 |
Correct |
862 ms |
5712 KB |
Output is correct |
69 |
Correct |
785 ms |
5600 KB |
Output is correct |
70 |
Correct |
751 ms |
5704 KB |
Output is correct |
71 |
Correct |
679 ms |
6608 KB |
Output is correct |
72 |
Correct |
842 ms |
5712 KB |
Output is correct |
73 |
Correct |
870 ms |
5584 KB |
Output is correct |
74 |
Correct |
926 ms |
5584 KB |
Output is correct |
75 |
Correct |
835 ms |
5564 KB |
Output is correct |
76 |
Correct |
840 ms |
7120 KB |
Output is correct |
77 |
Correct |
790 ms |
7240 KB |
Output is correct |
78 |
Correct |
875 ms |
7216 KB |
Output is correct |
79 |
Correct |
888 ms |
5712 KB |
Output is correct |
80 |
Correct |
729 ms |
5396 KB |
Output is correct |
81 |
Correct |
905 ms |
5328 KB |
Output is correct |
82 |
Correct |
654 ms |
5584 KB |
Output is correct |
83 |
Correct |
407 ms |
5200 KB |
Output is correct |
84 |
Correct |
872 ms |
5456 KB |
Output is correct |
85 |
Correct |
867 ms |
5456 KB |
Output is correct |
86 |
Correct |
786 ms |
5456 KB |
Output is correct |
87 |
Correct |
3 ms |
4944 KB |
Output is correct |
88 |
Correct |
613 ms |
16536 KB |
Output is correct |
89 |
Correct |
906 ms |
12488 KB |
Output is correct |
90 |
Correct |
944 ms |
12232 KB |
Output is correct |
91 |
Correct |
860 ms |
17448 KB |
Output is correct |
92 |
Correct |
1077 ms |
16344 KB |
Output is correct |
93 |
Correct |
950 ms |
16424 KB |
Output is correct |
94 |
Correct |
903 ms |
17436 KB |
Output is correct |
95 |
Correct |
1047 ms |
17444 KB |
Output is correct |
96 |
Correct |
599 ms |
13144 KB |
Output is correct |
97 |
Correct |
1002 ms |
13556 KB |
Output is correct |
98 |
Correct |
748 ms |
37888 KB |
Output is correct |
99 |
Correct |
968 ms |
17276 KB |
Output is correct |
100 |
Correct |
950 ms |
15060 KB |
Output is correct |
101 |
Correct |
830 ms |
14492 KB |
Output is correct |
102 |
Correct |
1004 ms |
13440 KB |
Output is correct |
103 |
Correct |
1040 ms |
45460 KB |
Output is correct |
104 |
Correct |
1008 ms |
45952 KB |
Output is correct |
105 |
Correct |
999 ms |
45812 KB |
Output is correct |
106 |
Correct |
968 ms |
18376 KB |
Output is correct |
107 |
Correct |
758 ms |
13768 KB |
Output is correct |
108 |
Correct |
938 ms |
13704 KB |
Output is correct |
109 |
Correct |
1050 ms |
13584 KB |
Output is correct |