#include "circuit.h"
#include <bits/stdc++.h>
#define fs first
#define sc second
using namespace std;
const int mod=1000002022;
void add(int& x,int y){
x+=y;
x-=mod*(x>=mod);
}
int mul(int x,int y){
return 1ll*x*y%mod;
}
int po(int x,int y){
int z=1;
while(y){
if(y&1){
z=mul(z,x);
}
x=mul(x,x);
y>>=1;
}
return z;
}
int inv(int x){
return po(x,222*2242156-1);
}
vector<int> g,a;
struct ST{
struct no{
int sum=0,ans=0,tag=0;
};
vector<no> st;
void init(int x){
st.resize(4*x);
}
void upd(int v){
st[v].ans=(st[v].sum-st[v].ans+mod)%mod;
st[v].tag^=1;
}
void pudo(int v){
if(st[v].tag){
upd(2*v+1);
upd(2*v+2);
st[v].tag=0;
}
}
void pull(int v){
st[v].ans=(st[2*v+1].ans+st[2*v+2].ans)%mod;
}
void build(int v,int L,int R){
if(L==R){
st[v].sum=g[L];
st[v].ans=st[v].sum*a[L];
return;
}
int m=(L+R)/2;
build(2*v+1,L,m);
build(2*v+2,m+1,R);
pull(v);
st[v].sum=(st[2*v+1].sum+st[2*v+2].sum)%mod;
}
void toggle(int v,int L,int R,int l,int r){
if(L==l && r==R){
upd(v);
return;
}
pudo(v);
int m=(L+R)/2;
if(r<=m){
toggle(2*v+1,L,m,l,r);
}
else if(l>m){
toggle(2*v+2,m+1,R,l,r);
}
else{
toggle(2*v+1,L,m,l,m);
toggle(2*v+2,m+1,R,m+1,r);
}
pull(v);
}
int query(){
return st[0].ans;
}
}st;
const int x[2]={2,223};
int cnt[2]={0};
int pe=1;
int n,m;
struct tn{
vector<int> ch;
int deg=0;
int cs[2]={0};
int dx=1;
};
vector<tn> v;
void dfs(int r,int a,int b,int c){
if(r>=n){
int z=mul(pe,inv(c));
z=mul(z,po(2,cnt[0]-a));
z=mul(z,po(223,cnt[1]-b));
g[r-n]=z;
return;
}
for(auto h:v[r].ch){
dfs(h,a+v[r].cs[0],b+v[r].cs[1],mul(c,v[r].dx));
}
}
void init(int N, int M, vector<int> p, vector<int> A) {
n=N;
m=M;
a=A;
st.init(m);
g.resize(m);
v.resize(n+m);
for(int i=1;i<n+m;i++){
v[p[i]].ch.push_back(i);
v[p[i]].deg++;
}
for(int i=0;i<n;i++){
int s=v[i].deg;
while(s%2==0){
s/=2;
v[i].cs[0]++;
cnt[0]++;
}
while(s%223==0){
s/=223;
v[i].cs[1]++;
cnt[1]++;
}
v[i].dx=s;
pe=mul(pe,s);
}
dfs(0,0,0,1);
st.build(0,0,m-1);
}
int count_ways(int L, int R) {
st.toggle(0,0,m-1,L-n,R-n);
return st.query();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
464 KB |
Output is correct |
8 |
Correct |
1 ms |
464 KB |
Output is correct |
9 |
Correct |
1 ms |
464 KB |
Output is correct |
10 |
Correct |
1 ms |
464 KB |
Output is correct |
11 |
Correct |
1 ms |
464 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
0 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
464 KB |
Output is correct |
16 |
Correct |
1 ms |
464 KB |
Output is correct |
17 |
Correct |
1 ms |
464 KB |
Output is correct |
18 |
Correct |
1 ms |
464 KB |
Output is correct |
19 |
Correct |
1 ms |
464 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
464 KB |
Output is correct |
25 |
Correct |
1 ms |
464 KB |
Output is correct |
26 |
Correct |
1 ms |
464 KB |
Output is correct |
27 |
Correct |
1 ms |
464 KB |
Output is correct |
28 |
Correct |
1 ms |
464 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
0 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
464 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
1 ms |
336 KB |
Output is correct |
36 |
Correct |
1 ms |
464 KB |
Output is correct |
37 |
Correct |
1 ms |
464 KB |
Output is correct |
38 |
Correct |
1 ms |
464 KB |
Output is correct |
39 |
Correct |
1 ms |
336 KB |
Output is correct |
40 |
Correct |
1 ms |
336 KB |
Output is correct |
41 |
Correct |
1 ms |
336 KB |
Output is correct |
42 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
649 ms |
6484 KB |
Output is correct |
2 |
Correct |
780 ms |
12596 KB |
Output is correct |
3 |
Correct |
668 ms |
12600 KB |
Output is correct |
4 |
Correct |
750 ms |
12624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
649 ms |
6484 KB |
Output is correct |
2 |
Correct |
780 ms |
12596 KB |
Output is correct |
3 |
Correct |
668 ms |
12600 KB |
Output is correct |
4 |
Correct |
750 ms |
12624 KB |
Output is correct |
5 |
Correct |
572 ms |
6480 KB |
Output is correct |
6 |
Correct |
811 ms |
12576 KB |
Output is correct |
7 |
Correct |
721 ms |
12620 KB |
Output is correct |
8 |
Correct |
638 ms |
12624 KB |
Output is correct |
9 |
Correct |
318 ms |
592 KB |
Output is correct |
10 |
Correct |
599 ms |
1060 KB |
Output is correct |
11 |
Correct |
883 ms |
1056 KB |
Output is correct |
12 |
Correct |
714 ms |
1060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
464 KB |
Output is correct |
8 |
Correct |
1 ms |
464 KB |
Output is correct |
9 |
Correct |
1 ms |
464 KB |
Output is correct |
10 |
Correct |
1 ms |
464 KB |
Output is correct |
11 |
Correct |
1 ms |
464 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
649 ms |
6484 KB |
Output is correct |
14 |
Correct |
780 ms |
12596 KB |
Output is correct |
15 |
Correct |
668 ms |
12600 KB |
Output is correct |
16 |
Correct |
750 ms |
12624 KB |
Output is correct |
17 |
Correct |
572 ms |
6480 KB |
Output is correct |
18 |
Correct |
811 ms |
12576 KB |
Output is correct |
19 |
Correct |
721 ms |
12620 KB |
Output is correct |
20 |
Correct |
638 ms |
12624 KB |
Output is correct |
21 |
Correct |
318 ms |
592 KB |
Output is correct |
22 |
Correct |
599 ms |
1060 KB |
Output is correct |
23 |
Correct |
883 ms |
1056 KB |
Output is correct |
24 |
Correct |
714 ms |
1060 KB |
Output is correct |
25 |
Correct |
904 ms |
18748 KB |
Output is correct |
26 |
Correct |
949 ms |
19080 KB |
Output is correct |
27 |
Correct |
777 ms |
18996 KB |
Output is correct |
28 |
Correct |
624 ms |
18976 KB |
Output is correct |
29 |
Correct |
806 ms |
26892 KB |
Output is correct |
30 |
Correct |
802 ms |
26808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
0 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
464 KB |
Output is correct |
16 |
Correct |
1 ms |
464 KB |
Output is correct |
17 |
Correct |
1 ms |
464 KB |
Output is correct |
18 |
Correct |
1 ms |
464 KB |
Output is correct |
19 |
Correct |
1 ms |
464 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
464 KB |
Output is correct |
25 |
Correct |
1 ms |
464 KB |
Output is correct |
26 |
Correct |
1 ms |
464 KB |
Output is correct |
27 |
Correct |
1 ms |
464 KB |
Output is correct |
28 |
Correct |
1 ms |
464 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
0 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
464 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
1 ms |
336 KB |
Output is correct |
36 |
Correct |
1 ms |
464 KB |
Output is correct |
37 |
Correct |
1 ms |
464 KB |
Output is correct |
38 |
Correct |
1 ms |
464 KB |
Output is correct |
39 |
Correct |
1 ms |
336 KB |
Output is correct |
40 |
Correct |
1 ms |
336 KB |
Output is correct |
41 |
Correct |
1 ms |
336 KB |
Output is correct |
42 |
Correct |
1 ms |
336 KB |
Output is correct |
43 |
Correct |
634 ms |
720 KB |
Output is correct |
44 |
Correct |
753 ms |
848 KB |
Output is correct |
45 |
Correct |
883 ms |
868 KB |
Output is correct |
46 |
Correct |
709 ms |
1236 KB |
Output is correct |
47 |
Correct |
829 ms |
1232 KB |
Output is correct |
48 |
Correct |
716 ms |
1236 KB |
Output is correct |
49 |
Correct |
537 ms |
1236 KB |
Output is correct |
50 |
Correct |
844 ms |
1232 KB |
Output is correct |
51 |
Correct |
658 ms |
896 KB |
Output is correct |
52 |
Correct |
722 ms |
896 KB |
Output is correct |
53 |
Correct |
569 ms |
976 KB |
Output is correct |
54 |
Correct |
712 ms |
1232 KB |
Output is correct |
55 |
Correct |
667 ms |
1040 KB |
Output is correct |
56 |
Correct |
718 ms |
976 KB |
Output is correct |
57 |
Correct |
675 ms |
856 KB |
Output is correct |
58 |
Correct |
624 ms |
1616 KB |
Output is correct |
59 |
Correct |
641 ms |
1672 KB |
Output is correct |
60 |
Correct |
795 ms |
1688 KB |
Output is correct |
61 |
Correct |
465 ms |
848 KB |
Output is correct |
62 |
Correct |
680 ms |
848 KB |
Output is correct |
63 |
Correct |
592 ms |
824 KB |
Output is correct |
64 |
Correct |
750 ms |
876 KB |
Output is correct |
65 |
Correct |
273 ms |
592 KB |
Output is correct |
66 |
Correct |
586 ms |
1060 KB |
Output is correct |
67 |
Correct |
584 ms |
1064 KB |
Output is correct |
68 |
Correct |
694 ms |
1060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
0 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
464 KB |
Output is correct |
16 |
Correct |
1 ms |
464 KB |
Output is correct |
17 |
Correct |
1 ms |
464 KB |
Output is correct |
18 |
Correct |
1 ms |
464 KB |
Output is correct |
19 |
Correct |
1 ms |
464 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
336 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
464 KB |
Output is correct |
25 |
Correct |
1 ms |
464 KB |
Output is correct |
26 |
Correct |
1 ms |
464 KB |
Output is correct |
27 |
Correct |
1 ms |
464 KB |
Output is correct |
28 |
Correct |
1 ms |
464 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
0 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
464 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
1 ms |
336 KB |
Output is correct |
36 |
Correct |
1 ms |
464 KB |
Output is correct |
37 |
Correct |
1 ms |
464 KB |
Output is correct |
38 |
Correct |
1 ms |
464 KB |
Output is correct |
39 |
Correct |
1 ms |
336 KB |
Output is correct |
40 |
Correct |
1 ms |
336 KB |
Output is correct |
41 |
Correct |
1 ms |
336 KB |
Output is correct |
42 |
Correct |
1 ms |
336 KB |
Output is correct |
43 |
Correct |
649 ms |
6484 KB |
Output is correct |
44 |
Correct |
780 ms |
12596 KB |
Output is correct |
45 |
Correct |
668 ms |
12600 KB |
Output is correct |
46 |
Correct |
750 ms |
12624 KB |
Output is correct |
47 |
Correct |
572 ms |
6480 KB |
Output is correct |
48 |
Correct |
811 ms |
12576 KB |
Output is correct |
49 |
Correct |
721 ms |
12620 KB |
Output is correct |
50 |
Correct |
638 ms |
12624 KB |
Output is correct |
51 |
Correct |
318 ms |
592 KB |
Output is correct |
52 |
Correct |
599 ms |
1060 KB |
Output is correct |
53 |
Correct |
883 ms |
1056 KB |
Output is correct |
54 |
Correct |
714 ms |
1060 KB |
Output is correct |
55 |
Correct |
904 ms |
18748 KB |
Output is correct |
56 |
Correct |
949 ms |
19080 KB |
Output is correct |
57 |
Correct |
777 ms |
18996 KB |
Output is correct |
58 |
Correct |
624 ms |
18976 KB |
Output is correct |
59 |
Correct |
806 ms |
26892 KB |
Output is correct |
60 |
Correct |
802 ms |
26808 KB |
Output is correct |
61 |
Correct |
634 ms |
720 KB |
Output is correct |
62 |
Correct |
753 ms |
848 KB |
Output is correct |
63 |
Correct |
883 ms |
868 KB |
Output is correct |
64 |
Correct |
709 ms |
1236 KB |
Output is correct |
65 |
Correct |
829 ms |
1232 KB |
Output is correct |
66 |
Correct |
716 ms |
1236 KB |
Output is correct |
67 |
Correct |
537 ms |
1236 KB |
Output is correct |
68 |
Correct |
844 ms |
1232 KB |
Output is correct |
69 |
Correct |
658 ms |
896 KB |
Output is correct |
70 |
Correct |
722 ms |
896 KB |
Output is correct |
71 |
Correct |
569 ms |
976 KB |
Output is correct |
72 |
Correct |
712 ms |
1232 KB |
Output is correct |
73 |
Correct |
667 ms |
1040 KB |
Output is correct |
74 |
Correct |
718 ms |
976 KB |
Output is correct |
75 |
Correct |
675 ms |
856 KB |
Output is correct |
76 |
Correct |
624 ms |
1616 KB |
Output is correct |
77 |
Correct |
641 ms |
1672 KB |
Output is correct |
78 |
Correct |
795 ms |
1688 KB |
Output is correct |
79 |
Correct |
465 ms |
848 KB |
Output is correct |
80 |
Correct |
680 ms |
848 KB |
Output is correct |
81 |
Correct |
592 ms |
824 KB |
Output is correct |
82 |
Correct |
750 ms |
876 KB |
Output is correct |
83 |
Correct |
273 ms |
592 KB |
Output is correct |
84 |
Correct |
586 ms |
1060 KB |
Output is correct |
85 |
Correct |
584 ms |
1064 KB |
Output is correct |
86 |
Correct |
694 ms |
1060 KB |
Output is correct |
87 |
Correct |
3 ms |
208 KB |
Output is correct |
88 |
Correct |
486 ms |
16700 KB |
Output is correct |
89 |
Correct |
734 ms |
11844 KB |
Output is correct |
90 |
Correct |
709 ms |
11848 KB |
Output is correct |
91 |
Correct |
700 ms |
19104 KB |
Output is correct |
92 |
Correct |
802 ms |
19200 KB |
Output is correct |
93 |
Correct |
884 ms |
19152 KB |
Output is correct |
94 |
Correct |
681 ms |
19200 KB |
Output is correct |
95 |
Correct |
873 ms |
19232 KB |
Output is correct |
96 |
Correct |
731 ms |
11980 KB |
Output is correct |
97 |
Correct |
812 ms |
11820 KB |
Output is correct |
98 |
Correct |
746 ms |
15952 KB |
Output is correct |
99 |
Correct |
743 ms |
19084 KB |
Output is correct |
100 |
Correct |
808 ms |
15168 KB |
Output is correct |
101 |
Correct |
857 ms |
13716 KB |
Output is correct |
102 |
Correct |
900 ms |
11764 KB |
Output is correct |
103 |
Correct |
789 ms |
26860 KB |
Output is correct |
104 |
Correct |
916 ms |
27420 KB |
Output is correct |
105 |
Correct |
747 ms |
27340 KB |
Output is correct |
106 |
Correct |
882 ms |
12572 KB |
Output is correct |
107 |
Correct |
703 ms |
10696 KB |
Output is correct |
108 |
Correct |
712 ms |
11288 KB |
Output is correct |
109 |
Correct |
828 ms |
11728 KB |
Output is correct |