#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD=1000002022; //2*223*2242157
const ll mod=2242157;
const ll phi=497758632;
const int c=2e5+5;
struct num{
ll _2,_223,_rest;
};
ll power(ll a, ll b, ll m){
ll res=1;
while(b){
if(b&1){
res*=a;
res%=m;
}
a*=a; a%=m; b>>=1;
}
return res;
}
num div(num a, num b){
num res;
res._2=a._2-b._2;
res._223=a._223-b._223;
res._rest=a._rest*power(b._rest,phi-1,MOD)%MOD;
return res;
}
num mul(num a, num b){
num res;
res._2=a._2+b._2;
res._223=a._223+b._223;
res._rest=a._rest*b._rest%MOD;
return res;
}
num valt(ll a){
num res;
res._2=0;
while(a%2==0){
++res._2; a/=2;
}
res._223=0;
while(a%223==0){
++res._223; a/=223;
}
res._rest=a%MOD;
return res;
}
ll vissza(num a){
return power(2,a._2,MOD)*power(223,a._223,MOD)%MOD*a._rest%MOD;
}
int n,m;
vector<int> adj[c];
num db[c];
num arr[c];
num all;
bool szin[c];
int _N,_M;
void dfs(int v, num cur){
db[v]=cur;
cur=div(cur,arr[v]);
for(int x: adj[v]){
dfs(x,cur);
}
}
pair<ll,ll> add(pair<ll,ll> a, pair<ll,ll> b){
return make_pair((a.first+b.first)%MOD,(a.second+b.second)%MOD);
}
pair<ll,ll> tree[4*c];
bool lazy[4*c];
void build(int v, int l, int r){
if(l==r){
//cout << l << ' ' << vissza(db[l+_N-1]) << endl;
if(!szin[l+_N-1]) tree[v]=make_pair(vissza(db[l+_N-1]),0);
else tree[v]=make_pair(0,vissza(db[l+_N-1]));
return;
}
int mid=l+r>>1;
build(2*v,l,mid); build(2*v+1,mid+1,r);
tree[v]=add(tree[2*v],tree[2*v+1]);
}
void update(int v, int l, int r, int x, int y){
if(lazy[v]){
swap(tree[v].first,tree[v].second);
if(l != r){
lazy[2*v]=lazy[2*v]^1;
lazy[2*v+1]=lazy[2*v+1]^1;
}
lazy[v]=0;
}
if(l>r || l>y || x>r || x>y) return;
if(x<=l && r<=y){
swap(tree[v].first,tree[v].second);
if(l != r){
lazy[2*v]=lazy[2*v]^1;
lazy[2*v+1]=lazy[2*v+1]^1;
}
return;
}
int mid=l+r>>1;
update(2*v,l,mid,x,y); update(2*v+1,mid+1,r,x,y);
tree[v]=add(tree[2*v],tree[2*v+1]);
}
void init(int N, int M, vector<int> P, vector<int> A){
int n=N+M;
_N=N; _M=M;
all._2=0; all._223=0; all._rest=1;
for(int i=1;i<n;i++){
if(i>=N) szin[i]=A[i-N];
adj[P[i]].push_back(i);
}
for(int i=0;i<n;i++){
if(i<N){
arr[i]=valt(adj[i].size());
all=mul(all,arr[i]);
}
else arr[i]=valt(1);
}
dfs(0,all);
build(1,1,M);
}
int count_ways(int L, int R){
update(1,1,_M,L-_N+1,R-_N+1);
return tree[1].second;
}
/*int main(){
init(3,4,{-1, 0, 1, 2, 1, 1, 0},{1, 0, 1, 0});
cout << count_ways(3,4) << '\n';
cout << count_ways(4,5) << '\n';
cout << count_ways(3,6) << endl;
}*/
Compilation message
circuit.cpp: In function 'void build(int, int, int)':
circuit.cpp:90:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
90 | int mid=l+r>>1;
| ~^~
circuit.cpp: In function 'void update(int, int, int, int, int)':
circuit.cpp:116:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
116 | int mid=l+r>>1;
| ~^~
# |
결과 |
실행 시간 |
메모리 |
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 |
5072 KB |
Output is correct |
5 |
Correct |
3 ms |
5056 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 |
4980 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 |
5200 KB |
Output is correct |
8 |
Correct |
4 ms |
5200 KB |
Output is correct |
9 |
Correct |
5 ms |
5156 KB |
Output is correct |
10 |
Correct |
4 ms |
5200 KB |
Output is correct |
11 |
Correct |
4 ms |
5200 KB |
Output is correct |
12 |
Correct |
4 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 |
5072 KB |
Output is correct |
5 |
Correct |
3 ms |
5056 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 |
4980 KB |
Output is correct |
11 |
Correct |
3 ms |
5072 KB |
Output is correct |
12 |
Correct |
3 ms |
5072 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 |
5200 KB |
Output is correct |
16 |
Correct |
4 ms |
5200 KB |
Output is correct |
17 |
Correct |
5 ms |
5156 KB |
Output is correct |
18 |
Correct |
4 ms |
5200 KB |
Output is correct |
19 |
Correct |
4 ms |
5200 KB |
Output is correct |
20 |
Correct |
4 ms |
5072 KB |
Output is correct |
21 |
Correct |
5 ms |
5312 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 |
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 |
4 ms |
5124 KB |
Output is correct |
28 |
Correct |
5 ms |
5180 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 |
4 ms |
5072 KB |
Output is correct |
34 |
Correct |
4 ms |
5072 KB |
Output is correct |
35 |
Correct |
3 ms |
5072 KB |
Output is correct |
36 |
Correct |
4 ms |
5200 KB |
Output is correct |
37 |
Correct |
4 ms |
5200 KB |
Output is correct |
38 |
Correct |
5 ms |
5300 KB |
Output is correct |
39 |
Correct |
3 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 |
741 ms |
10956 KB |
Output is correct |
2 |
Correct |
786 ms |
16808 KB |
Output is correct |
3 |
Correct |
1008 ms |
16888 KB |
Output is correct |
4 |
Correct |
908 ms |
16804 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
741 ms |
10956 KB |
Output is correct |
2 |
Correct |
786 ms |
16808 KB |
Output is correct |
3 |
Correct |
1008 ms |
16888 KB |
Output is correct |
4 |
Correct |
908 ms |
16804 KB |
Output is correct |
5 |
Correct |
740 ms |
10860 KB |
Output is correct |
6 |
Correct |
1002 ms |
16788 KB |
Output is correct |
7 |
Correct |
1006 ms |
16872 KB |
Output is correct |
8 |
Correct |
955 ms |
16772 KB |
Output is correct |
9 |
Correct |
468 ms |
5376 KB |
Output is correct |
10 |
Correct |
723 ms |
5764 KB |
Output is correct |
11 |
Correct |
881 ms |
5840 KB |
Output is correct |
12 |
Correct |
951 ms |
5660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4944 KB |
Output is correct |
2 |
Correct |
3 ms |
4980 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 |
5200 KB |
Output is correct |
8 |
Correct |
4 ms |
5200 KB |
Output is correct |
9 |
Correct |
5 ms |
5156 KB |
Output is correct |
10 |
Correct |
4 ms |
5200 KB |
Output is correct |
11 |
Correct |
4 ms |
5200 KB |
Output is correct |
12 |
Correct |
4 ms |
5072 KB |
Output is correct |
13 |
Correct |
741 ms |
10956 KB |
Output is correct |
14 |
Correct |
786 ms |
16808 KB |
Output is correct |
15 |
Correct |
1008 ms |
16888 KB |
Output is correct |
16 |
Correct |
908 ms |
16804 KB |
Output is correct |
17 |
Correct |
740 ms |
10860 KB |
Output is correct |
18 |
Correct |
1002 ms |
16788 KB |
Output is correct |
19 |
Correct |
1006 ms |
16872 KB |
Output is correct |
20 |
Correct |
955 ms |
16772 KB |
Output is correct |
21 |
Correct |
468 ms |
5376 KB |
Output is correct |
22 |
Correct |
723 ms |
5764 KB |
Output is correct |
23 |
Correct |
881 ms |
5840 KB |
Output is correct |
24 |
Correct |
951 ms |
5660 KB |
Output is correct |
25 |
Correct |
1060 ms |
23812 KB |
Output is correct |
26 |
Correct |
948 ms |
23956 KB |
Output is correct |
27 |
Correct |
1075 ms |
24076 KB |
Output is correct |
28 |
Correct |
917 ms |
24016 KB |
Output is correct |
29 |
Correct |
1079 ms |
31896 KB |
Output is correct |
30 |
Correct |
963 ms |
31808 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 |
5072 KB |
Output is correct |
5 |
Correct |
3 ms |
5056 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 |
4980 KB |
Output is correct |
11 |
Correct |
3 ms |
5072 KB |
Output is correct |
12 |
Correct |
3 ms |
5072 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 |
5200 KB |
Output is correct |
16 |
Correct |
4 ms |
5200 KB |
Output is correct |
17 |
Correct |
5 ms |
5156 KB |
Output is correct |
18 |
Correct |
4 ms |
5200 KB |
Output is correct |
19 |
Correct |
4 ms |
5200 KB |
Output is correct |
20 |
Correct |
4 ms |
5072 KB |
Output is correct |
21 |
Correct |
5 ms |
5312 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 |
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 |
4 ms |
5124 KB |
Output is correct |
28 |
Correct |
5 ms |
5180 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 |
4 ms |
5072 KB |
Output is correct |
34 |
Correct |
4 ms |
5072 KB |
Output is correct |
35 |
Correct |
3 ms |
5072 KB |
Output is correct |
36 |
Correct |
4 ms |
5200 KB |
Output is correct |
37 |
Correct |
4 ms |
5200 KB |
Output is correct |
38 |
Correct |
5 ms |
5300 KB |
Output is correct |
39 |
Correct |
3 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 |
579 ms |
5600 KB |
Output is correct |
44 |
Correct |
787 ms |
5584 KB |
Output is correct |
45 |
Correct |
962 ms |
5636 KB |
Output is correct |
46 |
Correct |
862 ms |
5968 KB |
Output is correct |
47 |
Correct |
783 ms |
5956 KB |
Output is correct |
48 |
Correct |
650 ms |
6060 KB |
Output is correct |
49 |
Correct |
833 ms |
5968 KB |
Output is correct |
50 |
Correct |
829 ms |
5968 KB |
Output is correct |
51 |
Correct |
836 ms |
5584 KB |
Output is correct |
52 |
Correct |
923 ms |
5584 KB |
Output is correct |
53 |
Correct |
914 ms |
5712 KB |
Output is correct |
54 |
Correct |
841 ms |
5968 KB |
Output is correct |
55 |
Correct |
571 ms |
5712 KB |
Output is correct |
56 |
Correct |
918 ms |
5712 KB |
Output is correct |
57 |
Correct |
772 ms |
5584 KB |
Output is correct |
58 |
Correct |
864 ms |
6352 KB |
Output is correct |
59 |
Correct |
729 ms |
6480 KB |
Output is correct |
60 |
Correct |
795 ms |
6480 KB |
Output is correct |
61 |
Correct |
903 ms |
5744 KB |
Output is correct |
62 |
Correct |
815 ms |
5456 KB |
Output is correct |
63 |
Correct |
872 ms |
5536 KB |
Output is correct |
64 |
Correct |
844 ms |
5584 KB |
Output is correct |
65 |
Correct |
409 ms |
5328 KB |
Output is correct |
66 |
Correct |
936 ms |
5712 KB |
Output is correct |
67 |
Correct |
868 ms |
5712 KB |
Output is correct |
68 |
Correct |
1008 ms |
5764 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 |
5072 KB |
Output is correct |
5 |
Correct |
3 ms |
5056 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 |
4980 KB |
Output is correct |
11 |
Correct |
3 ms |
5072 KB |
Output is correct |
12 |
Correct |
3 ms |
5072 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 |
5200 KB |
Output is correct |
16 |
Correct |
4 ms |
5200 KB |
Output is correct |
17 |
Correct |
5 ms |
5156 KB |
Output is correct |
18 |
Correct |
4 ms |
5200 KB |
Output is correct |
19 |
Correct |
4 ms |
5200 KB |
Output is correct |
20 |
Correct |
4 ms |
5072 KB |
Output is correct |
21 |
Correct |
5 ms |
5312 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 |
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 |
4 ms |
5124 KB |
Output is correct |
28 |
Correct |
5 ms |
5180 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 |
4 ms |
5072 KB |
Output is correct |
34 |
Correct |
4 ms |
5072 KB |
Output is correct |
35 |
Correct |
3 ms |
5072 KB |
Output is correct |
36 |
Correct |
4 ms |
5200 KB |
Output is correct |
37 |
Correct |
4 ms |
5200 KB |
Output is correct |
38 |
Correct |
5 ms |
5300 KB |
Output is correct |
39 |
Correct |
3 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 |
741 ms |
10956 KB |
Output is correct |
44 |
Correct |
786 ms |
16808 KB |
Output is correct |
45 |
Correct |
1008 ms |
16888 KB |
Output is correct |
46 |
Correct |
908 ms |
16804 KB |
Output is correct |
47 |
Correct |
740 ms |
10860 KB |
Output is correct |
48 |
Correct |
1002 ms |
16788 KB |
Output is correct |
49 |
Correct |
1006 ms |
16872 KB |
Output is correct |
50 |
Correct |
955 ms |
16772 KB |
Output is correct |
51 |
Correct |
468 ms |
5376 KB |
Output is correct |
52 |
Correct |
723 ms |
5764 KB |
Output is correct |
53 |
Correct |
881 ms |
5840 KB |
Output is correct |
54 |
Correct |
951 ms |
5660 KB |
Output is correct |
55 |
Correct |
1060 ms |
23812 KB |
Output is correct |
56 |
Correct |
948 ms |
23956 KB |
Output is correct |
57 |
Correct |
1075 ms |
24076 KB |
Output is correct |
58 |
Correct |
917 ms |
24016 KB |
Output is correct |
59 |
Correct |
1079 ms |
31896 KB |
Output is correct |
60 |
Correct |
963 ms |
31808 KB |
Output is correct |
61 |
Correct |
579 ms |
5600 KB |
Output is correct |
62 |
Correct |
787 ms |
5584 KB |
Output is correct |
63 |
Correct |
962 ms |
5636 KB |
Output is correct |
64 |
Correct |
862 ms |
5968 KB |
Output is correct |
65 |
Correct |
783 ms |
5956 KB |
Output is correct |
66 |
Correct |
650 ms |
6060 KB |
Output is correct |
67 |
Correct |
833 ms |
5968 KB |
Output is correct |
68 |
Correct |
829 ms |
5968 KB |
Output is correct |
69 |
Correct |
836 ms |
5584 KB |
Output is correct |
70 |
Correct |
923 ms |
5584 KB |
Output is correct |
71 |
Correct |
914 ms |
5712 KB |
Output is correct |
72 |
Correct |
841 ms |
5968 KB |
Output is correct |
73 |
Correct |
571 ms |
5712 KB |
Output is correct |
74 |
Correct |
918 ms |
5712 KB |
Output is correct |
75 |
Correct |
772 ms |
5584 KB |
Output is correct |
76 |
Correct |
864 ms |
6352 KB |
Output is correct |
77 |
Correct |
729 ms |
6480 KB |
Output is correct |
78 |
Correct |
795 ms |
6480 KB |
Output is correct |
79 |
Correct |
903 ms |
5744 KB |
Output is correct |
80 |
Correct |
815 ms |
5456 KB |
Output is correct |
81 |
Correct |
872 ms |
5536 KB |
Output is correct |
82 |
Correct |
844 ms |
5584 KB |
Output is correct |
83 |
Correct |
409 ms |
5328 KB |
Output is correct |
84 |
Correct |
936 ms |
5712 KB |
Output is correct |
85 |
Correct |
868 ms |
5712 KB |
Output is correct |
86 |
Correct |
1008 ms |
5764 KB |
Output is correct |
87 |
Correct |
2 ms |
4944 KB |
Output is correct |
88 |
Correct |
563 ms |
22508 KB |
Output is correct |
89 |
Correct |
1134 ms |
16892 KB |
Output is correct |
90 |
Correct |
868 ms |
16484 KB |
Output is correct |
91 |
Correct |
1004 ms |
24188 KB |
Output is correct |
92 |
Correct |
872 ms |
24176 KB |
Output is correct |
93 |
Correct |
1105 ms |
24188 KB |
Output is correct |
94 |
Correct |
971 ms |
24176 KB |
Output is correct |
95 |
Correct |
915 ms |
24184 KB |
Output is correct |
96 |
Correct |
812 ms |
15936 KB |
Output is correct |
97 |
Correct |
907 ms |
15892 KB |
Output is correct |
98 |
Correct |
859 ms |
21448 KB |
Output is correct |
99 |
Correct |
1112 ms |
24076 KB |
Output is correct |
100 |
Correct |
1053 ms |
19712 KB |
Output is correct |
101 |
Correct |
978 ms |
18032 KB |
Output is correct |
102 |
Correct |
822 ms |
15980 KB |
Output is correct |
103 |
Correct |
1047 ms |
31868 KB |
Output is correct |
104 |
Correct |
1149 ms |
32460 KB |
Output is correct |
105 |
Correct |
1372 ms |
32324 KB |
Output is correct |
106 |
Correct |
889 ms |
18040 KB |
Output is correct |
107 |
Correct |
920 ms |
16840 KB |
Output is correct |
108 |
Correct |
1029 ms |
16812 KB |
Output is correct |
109 |
Correct |
955 ms |
15944 KB |
Output is correct |