#include <bits/stdc++.h>
#define ll long long
#define vc vector
using namespace std;
const ll mod=1000002022, mn=200100;
ll koef[mn], tr[4*mn][2], state[4*mn];
ll N, M;
void update(ll ql, ll qr, ll l, ll r, ll no){
if(ql==l && qr==r){state[no]=!state[no];}
else{
ll mid=(l+r)/2;
state[no*2]^=state[no];state[no*2+1]^=state[no];
state[no]=0;
ll ret=0;
if(qr<=mid) update(ql, qr, l, mid, no*2);
else if(mid<=ql) update(ql, qr, mid, r, no*2+1);
else update(ql, mid, l, mid, no*2), update(mid, qr, mid, r, no*2+1);
for(ll i=0;i<2;++i)
tr[no][i]=(tr[no*2][state[no*2]^i]+tr[no*2+1][state[no*2+1]^i])%mod;
}
}
int count_ways(int l, int r){
update(l-N, r-N+1, 0, M, 1);
return tr[1][state[1]];
}
void build(ll l, ll r, const vc<int>& a, ll no){
if(l+1==r) tr[no][!a[l]]=koef[l], state[no]=0;
else{
ll mid=(l+r)/2;
build(l, mid, a, no*2);
build(mid, r, a, no*2+1);
for(ll i=0;i<2;++i) tr[no][i]=(tr[no*2][i]+tr[no*2+1][i])%mod;
state[no]=0;
}
}
void init(int n, int m, vc<int> p, vc<int> a){
N=n, M=m;
vc<vc<ll>> edg(n+m);
for(ll i=n+m-1;i>0;--i)edg[p[i]].push_back(i);
vc<ll> pr(n+m), vse(n+m);
function<void (ll)> getpros=[&](ll u){
pr[u]=vse[u]=1;
if(u>=n);
else{
for(auto v: edg[u]){
getpros(v);
pr[u]=pr[u]*vse[v]%mod;
}
vse[u]=pr[u]*edg[u].size()%mod;
}
};
getpros(0);
function<void (ll, ll)> getkoef=[&](ll u, ll val){
if(u>=n) koef[u-n]=val;
else{
assert(edg[u].size());
vc<ll> nv(edg[u].size(),1);
for(ll i=0,c=1;i<edg[u].size();++i)
nv[i]=nv[i]*c%mod, c=c*vse[edg[u][i]]%mod;
for(ll i=(ll)edg[u].size()-1,c=1;i>=0;--i)
nv[i]=nv[i]*c%mod, c=c*vse[edg[u][i]]%mod;
//for(ll i=0,c=1;i<edg[u].size();++i)cout<<nv[i]<<" ";cout<<endl;
for(ll i=0,c=1;i<edg[u].size();++i)
getkoef(edg[u][i], val*nv[i]%mod);
}
};
getkoef(0, 1);
//for(ll i=0;i<m;++i)cout<<koef[i]<<" ";cout<<endl;
build(0, M, a, 1);
}
Compilation message
circuit.cpp: In function 'void update(long long int, long long int, long long int, long long int, long long int)':
circuit.cpp:18:12: warning: unused variable 'ret' [-Wunused-variable]
18 | ll ret=0;
| ^~~
circuit.cpp: In lambda function:
circuit.cpp:69:29: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
69 | for(ll i=0,c=1;i<edg[u].size();++i)
| ~^~~~~~~~~~~~~~
circuit.cpp:74:29: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
74 | for(ll i=0,c=1;i<edg[u].size();++i)
| ~^~~~~~~~~~~~~~
circuit.cpp:74:24: warning: unused variable 'c' [-Wunused-variable]
74 | for(ll i=0,c=1;i<edg[u].size();++i)
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2648 KB |
Output is correct |
8 |
Correct |
1 ms |
2648 KB |
Output is correct |
9 |
Correct |
1 ms |
2648 KB |
Output is correct |
10 |
Correct |
1 ms |
2648 KB |
Output is correct |
11 |
Correct |
1 ms |
2648 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2648 KB |
Output is correct |
16 |
Correct |
1 ms |
2648 KB |
Output is correct |
17 |
Correct |
1 ms |
2648 KB |
Output is correct |
18 |
Correct |
1 ms |
2648 KB |
Output is correct |
19 |
Correct |
1 ms |
2648 KB |
Output is correct |
20 |
Correct |
1 ms |
2392 KB |
Output is correct |
21 |
Correct |
1 ms |
2392 KB |
Output is correct |
22 |
Correct |
1 ms |
2392 KB |
Output is correct |
23 |
Correct |
1 ms |
2392 KB |
Output is correct |
24 |
Correct |
1 ms |
2648 KB |
Output is correct |
25 |
Correct |
1 ms |
2648 KB |
Output is correct |
26 |
Correct |
1 ms |
2648 KB |
Output is correct |
27 |
Correct |
1 ms |
2648 KB |
Output is correct |
28 |
Correct |
1 ms |
2648 KB |
Output is correct |
29 |
Correct |
1 ms |
2392 KB |
Output is correct |
30 |
Correct |
1 ms |
2392 KB |
Output is correct |
31 |
Correct |
1 ms |
2648 KB |
Output is correct |
32 |
Correct |
1 ms |
2488 KB |
Output is correct |
33 |
Correct |
1 ms |
2392 KB |
Output is correct |
34 |
Correct |
1 ms |
2392 KB |
Output is correct |
35 |
Correct |
1 ms |
2392 KB |
Output is correct |
36 |
Correct |
1 ms |
2760 KB |
Output is correct |
37 |
Correct |
1 ms |
2648 KB |
Output is correct |
38 |
Correct |
1 ms |
2648 KB |
Output is correct |
39 |
Correct |
1 ms |
2392 KB |
Output is correct |
40 |
Correct |
1 ms |
2392 KB |
Output is correct |
41 |
Correct |
1 ms |
2392 KB |
Output is correct |
42 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
430 ms |
11328 KB |
Output is correct |
2 |
Correct |
565 ms |
15820 KB |
Output is correct |
3 |
Correct |
539 ms |
15952 KB |
Output is correct |
4 |
Correct |
574 ms |
15816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
430 ms |
11328 KB |
Output is correct |
2 |
Correct |
565 ms |
15820 KB |
Output is correct |
3 |
Correct |
539 ms |
15952 KB |
Output is correct |
4 |
Correct |
574 ms |
15816 KB |
Output is correct |
5 |
Correct |
460 ms |
11340 KB |
Output is correct |
6 |
Correct |
626 ms |
15804 KB |
Output is correct |
7 |
Correct |
575 ms |
15812 KB |
Output is correct |
8 |
Correct |
546 ms |
15800 KB |
Output is correct |
9 |
Correct |
286 ms |
2648 KB |
Output is correct |
10 |
Correct |
526 ms |
4952 KB |
Output is correct |
11 |
Correct |
572 ms |
4952 KB |
Output is correct |
12 |
Correct |
538 ms |
4952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2648 KB |
Output is correct |
8 |
Correct |
1 ms |
2648 KB |
Output is correct |
9 |
Correct |
1 ms |
2648 KB |
Output is correct |
10 |
Correct |
1 ms |
2648 KB |
Output is correct |
11 |
Correct |
1 ms |
2648 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
430 ms |
11328 KB |
Output is correct |
14 |
Correct |
565 ms |
15820 KB |
Output is correct |
15 |
Correct |
539 ms |
15952 KB |
Output is correct |
16 |
Correct |
574 ms |
15816 KB |
Output is correct |
17 |
Correct |
460 ms |
11340 KB |
Output is correct |
18 |
Correct |
626 ms |
15804 KB |
Output is correct |
19 |
Correct |
575 ms |
15812 KB |
Output is correct |
20 |
Correct |
546 ms |
15800 KB |
Output is correct |
21 |
Correct |
286 ms |
2648 KB |
Output is correct |
22 |
Correct |
526 ms |
4952 KB |
Output is correct |
23 |
Correct |
572 ms |
4952 KB |
Output is correct |
24 |
Correct |
538 ms |
4952 KB |
Output is correct |
25 |
Correct |
678 ms |
22588 KB |
Output is correct |
26 |
Correct |
635 ms |
22668 KB |
Output is correct |
27 |
Correct |
640 ms |
22844 KB |
Output is correct |
28 |
Correct |
479 ms |
22864 KB |
Output is correct |
29 |
Correct |
636 ms |
35908 KB |
Output is correct |
30 |
Correct |
579 ms |
35384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2648 KB |
Output is correct |
16 |
Correct |
1 ms |
2648 KB |
Output is correct |
17 |
Correct |
1 ms |
2648 KB |
Output is correct |
18 |
Correct |
1 ms |
2648 KB |
Output is correct |
19 |
Correct |
1 ms |
2648 KB |
Output is correct |
20 |
Correct |
1 ms |
2392 KB |
Output is correct |
21 |
Correct |
1 ms |
2392 KB |
Output is correct |
22 |
Correct |
1 ms |
2392 KB |
Output is correct |
23 |
Correct |
1 ms |
2392 KB |
Output is correct |
24 |
Correct |
1 ms |
2648 KB |
Output is correct |
25 |
Correct |
1 ms |
2648 KB |
Output is correct |
26 |
Correct |
1 ms |
2648 KB |
Output is correct |
27 |
Correct |
1 ms |
2648 KB |
Output is correct |
28 |
Correct |
1 ms |
2648 KB |
Output is correct |
29 |
Correct |
1 ms |
2392 KB |
Output is correct |
30 |
Correct |
1 ms |
2392 KB |
Output is correct |
31 |
Correct |
1 ms |
2648 KB |
Output is correct |
32 |
Correct |
1 ms |
2488 KB |
Output is correct |
33 |
Correct |
1 ms |
2392 KB |
Output is correct |
34 |
Correct |
1 ms |
2392 KB |
Output is correct |
35 |
Correct |
1 ms |
2392 KB |
Output is correct |
36 |
Correct |
1 ms |
2760 KB |
Output is correct |
37 |
Correct |
1 ms |
2648 KB |
Output is correct |
38 |
Correct |
1 ms |
2648 KB |
Output is correct |
39 |
Correct |
1 ms |
2392 KB |
Output is correct |
40 |
Correct |
1 ms |
2392 KB |
Output is correct |
41 |
Correct |
1 ms |
2392 KB |
Output is correct |
42 |
Correct |
1 ms |
2392 KB |
Output is correct |
43 |
Correct |
379 ms |
4952 KB |
Output is correct |
44 |
Correct |
528 ms |
4952 KB |
Output is correct |
45 |
Correct |
547 ms |
4952 KB |
Output is correct |
46 |
Correct |
516 ms |
5208 KB |
Output is correct |
47 |
Correct |
530 ms |
5208 KB |
Output is correct |
48 |
Correct |
526 ms |
5208 KB |
Output is correct |
49 |
Correct |
564 ms |
5208 KB |
Output is correct |
50 |
Correct |
542 ms |
5208 KB |
Output is correct |
51 |
Correct |
519 ms |
4952 KB |
Output is correct |
52 |
Correct |
534 ms |
4952 KB |
Output is correct |
53 |
Correct |
482 ms |
3416 KB |
Output is correct |
54 |
Correct |
584 ms |
5208 KB |
Output is correct |
55 |
Correct |
559 ms |
5208 KB |
Output is correct |
56 |
Correct |
598 ms |
4952 KB |
Output is correct |
57 |
Correct |
585 ms |
4952 KB |
Output is correct |
58 |
Correct |
544 ms |
5976 KB |
Output is correct |
59 |
Correct |
517 ms |
5872 KB |
Output is correct |
60 |
Correct |
497 ms |
5976 KB |
Output is correct |
61 |
Correct |
510 ms |
5208 KB |
Output is correct |
62 |
Correct |
509 ms |
4948 KB |
Output is correct |
63 |
Correct |
599 ms |
4952 KB |
Output is correct |
64 |
Correct |
562 ms |
4948 KB |
Output is correct |
65 |
Correct |
265 ms |
2648 KB |
Output is correct |
66 |
Correct |
600 ms |
4952 KB |
Output is correct |
67 |
Correct |
569 ms |
4952 KB |
Output is correct |
68 |
Correct |
571 ms |
4952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2648 KB |
Output is correct |
16 |
Correct |
1 ms |
2648 KB |
Output is correct |
17 |
Correct |
1 ms |
2648 KB |
Output is correct |
18 |
Correct |
1 ms |
2648 KB |
Output is correct |
19 |
Correct |
1 ms |
2648 KB |
Output is correct |
20 |
Correct |
1 ms |
2392 KB |
Output is correct |
21 |
Correct |
1 ms |
2392 KB |
Output is correct |
22 |
Correct |
1 ms |
2392 KB |
Output is correct |
23 |
Correct |
1 ms |
2392 KB |
Output is correct |
24 |
Correct |
1 ms |
2648 KB |
Output is correct |
25 |
Correct |
1 ms |
2648 KB |
Output is correct |
26 |
Correct |
1 ms |
2648 KB |
Output is correct |
27 |
Correct |
1 ms |
2648 KB |
Output is correct |
28 |
Correct |
1 ms |
2648 KB |
Output is correct |
29 |
Correct |
1 ms |
2392 KB |
Output is correct |
30 |
Correct |
1 ms |
2392 KB |
Output is correct |
31 |
Correct |
1 ms |
2648 KB |
Output is correct |
32 |
Correct |
1 ms |
2488 KB |
Output is correct |
33 |
Correct |
1 ms |
2392 KB |
Output is correct |
34 |
Correct |
1 ms |
2392 KB |
Output is correct |
35 |
Correct |
1 ms |
2392 KB |
Output is correct |
36 |
Correct |
1 ms |
2760 KB |
Output is correct |
37 |
Correct |
1 ms |
2648 KB |
Output is correct |
38 |
Correct |
1 ms |
2648 KB |
Output is correct |
39 |
Correct |
1 ms |
2392 KB |
Output is correct |
40 |
Correct |
1 ms |
2392 KB |
Output is correct |
41 |
Correct |
1 ms |
2392 KB |
Output is correct |
42 |
Correct |
1 ms |
2392 KB |
Output is correct |
43 |
Correct |
430 ms |
11328 KB |
Output is correct |
44 |
Correct |
565 ms |
15820 KB |
Output is correct |
45 |
Correct |
539 ms |
15952 KB |
Output is correct |
46 |
Correct |
574 ms |
15816 KB |
Output is correct |
47 |
Correct |
460 ms |
11340 KB |
Output is correct |
48 |
Correct |
626 ms |
15804 KB |
Output is correct |
49 |
Correct |
575 ms |
15812 KB |
Output is correct |
50 |
Correct |
546 ms |
15800 KB |
Output is correct |
51 |
Correct |
286 ms |
2648 KB |
Output is correct |
52 |
Correct |
526 ms |
4952 KB |
Output is correct |
53 |
Correct |
572 ms |
4952 KB |
Output is correct |
54 |
Correct |
538 ms |
4952 KB |
Output is correct |
55 |
Correct |
678 ms |
22588 KB |
Output is correct |
56 |
Correct |
635 ms |
22668 KB |
Output is correct |
57 |
Correct |
640 ms |
22844 KB |
Output is correct |
58 |
Correct |
479 ms |
22864 KB |
Output is correct |
59 |
Correct |
636 ms |
35908 KB |
Output is correct |
60 |
Correct |
579 ms |
35384 KB |
Output is correct |
61 |
Correct |
379 ms |
4952 KB |
Output is correct |
62 |
Correct |
528 ms |
4952 KB |
Output is correct |
63 |
Correct |
547 ms |
4952 KB |
Output is correct |
64 |
Correct |
516 ms |
5208 KB |
Output is correct |
65 |
Correct |
530 ms |
5208 KB |
Output is correct |
66 |
Correct |
526 ms |
5208 KB |
Output is correct |
67 |
Correct |
564 ms |
5208 KB |
Output is correct |
68 |
Correct |
542 ms |
5208 KB |
Output is correct |
69 |
Correct |
519 ms |
4952 KB |
Output is correct |
70 |
Correct |
534 ms |
4952 KB |
Output is correct |
71 |
Correct |
482 ms |
3416 KB |
Output is correct |
72 |
Correct |
584 ms |
5208 KB |
Output is correct |
73 |
Correct |
559 ms |
5208 KB |
Output is correct |
74 |
Correct |
598 ms |
4952 KB |
Output is correct |
75 |
Correct |
585 ms |
4952 KB |
Output is correct |
76 |
Correct |
544 ms |
5976 KB |
Output is correct |
77 |
Correct |
517 ms |
5872 KB |
Output is correct |
78 |
Correct |
497 ms |
5976 KB |
Output is correct |
79 |
Correct |
510 ms |
5208 KB |
Output is correct |
80 |
Correct |
509 ms |
4948 KB |
Output is correct |
81 |
Correct |
599 ms |
4952 KB |
Output is correct |
82 |
Correct |
562 ms |
4948 KB |
Output is correct |
83 |
Correct |
265 ms |
2648 KB |
Output is correct |
84 |
Correct |
600 ms |
4952 KB |
Output is correct |
85 |
Correct |
569 ms |
4952 KB |
Output is correct |
86 |
Correct |
571 ms |
4952 KB |
Output is correct |
87 |
Correct |
0 ms |
2392 KB |
Output is correct |
88 |
Correct |
377 ms |
21912 KB |
Output is correct |
89 |
Correct |
566 ms |
15948 KB |
Output is correct |
90 |
Correct |
647 ms |
16008 KB |
Output is correct |
91 |
Correct |
588 ms |
23380 KB |
Output is correct |
92 |
Correct |
694 ms |
23384 KB |
Output is correct |
93 |
Correct |
627 ms |
23380 KB |
Output is correct |
94 |
Correct |
639 ms |
23524 KB |
Output is correct |
95 |
Correct |
586 ms |
23544 KB |
Output is correct |
96 |
Correct |
538 ms |
15992 KB |
Output is correct |
97 |
Correct |
614 ms |
15804 KB |
Output is correct |
98 |
Correct |
562 ms |
22856 KB |
Output is correct |
99 |
Correct |
719 ms |
22852 KB |
Output is correct |
100 |
Correct |
678 ms |
19860 KB |
Output is correct |
101 |
Correct |
678 ms |
18208 KB |
Output is correct |
102 |
Correct |
619 ms |
16076 KB |
Output is correct |
103 |
Correct |
682 ms |
35400 KB |
Output is correct |
104 |
Correct |
659 ms |
35968 KB |
Output is correct |
105 |
Correct |
623 ms |
36028 KB |
Output is correct |
106 |
Correct |
594 ms |
18156 KB |
Output is correct |
107 |
Correct |
633 ms |
16492 KB |
Output is correct |
108 |
Correct |
674 ms |
16776 KB |
Output is correct |
109 |
Correct |
604 ms |
16208 KB |
Output is correct |