#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define int ll
#include "circuit.h"
ll n,m,mod=1000002022;
vector<ll> roads[200005];
ll comb[200005],val[200005],pref[200005],suff[200005];
map<ll,ll> todfs[200005];
ll sumi[800005],segtree[800005];
ll lazy[800005];
void build(ll node, ll l, ll r){
if(l==r){
sumi[node] = val[l];
}
else{
ll mid = (l+r)/2;
build(node*2,l,mid);
build(node*2+1,mid+1,r);
sumi[node] = sumi[node*2]+sumi[node*2+1];
sumi[node] %= mod;
}
}
void pushdown(ll node, ll l, ll r){
if(lazy[node]){
segtree[node] = sumi[node]-segtree[node];
segtree[node] += mod;
segtree[node] %= mod;
if(l!=r){
lazy[node*2] ^= 1;
lazy[node*2+1] ^= 1;
}
lazy[node] = 0;
}
}
void update(ll node, ll l, ll r, ll needl, ll needr){
pushdown(node,l,r);
if(l>needr or r<needl){
return;
}
else if(l>=needl and r<=needr){
lazy[node] ^= 1;
pushdown(node,l,r);
}
else{
ll mid = (l+r)/2;
update(node*2,l,mid,needl,needr);
update(node*2+1,mid+1,r,needl,needr);
pushdown(node*2,l,mid);
pushdown(node*2+1,mid+1,r);
segtree[node] = segtree[node*2]+segtree[node*2+1];
segtree[node] %= mod;
}
}
void dfs1(ll x){
comb[x] = 1;
if(x>=n){
return;
}
for(ll i:roads[x]){
dfs1(i);
comb[x] *= comb[i];
comb[x] %= mod;
}
comb[x] *= roads[x].size();
comb[x] %= mod;
}
void dfs2(ll x, ll c){
if(x>=n){
val[x] = c;
return;
}
pref[0] = 1;
for(ll i=1;i<=roads[x].size();i++){
pref[i] = comb[roads[x][i-1]]*pref[i-1];
pref[i] %= mod;
}
suff[roads[x].size()+1] = 1;
for(ll i=roads[x].size();i>=1;i--){
suff[i] = comb[roads[x][i-1]]*suff[i+1];
suff[i] %= mod;
}
for(ll i=1;i<=roads[x].size();i++){
todfs[x][roads[x][i-1]] = (((pref[i-1]*suff[i+1])%mod)*c)%mod;
}
for(ll i:roads[x]){
dfs2(i,todfs[x][i]);
}
}
void init(int N, int M, vector<int> p, vector<int> a){
n = N;
m = M;
for(ll i=1;i<=n+m-1;i++){
roads[p[i]].push_back(i);
}
dfs1(0);
dfs2(0,1);
build(1,0,n+m-1);
for(ll i=0;i<a.size();i++){
if(a[i]){
update(1,0,n+m-1,i+n,i+n);
}
}
}
int count_ways(int l, int r){
update(1,0,n+m-1,l,r);
return segtree[1];
}
Compilation message
circuit.cpp: In function 'void dfs2(ll, ll)':
circuit.cpp:81:17: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
81 | for(ll i=1;i<=roads[x].size();i++){
| ~^~~~~~~~~~~~~~~~~
circuit.cpp:90:17: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
90 | for(ll i=1;i<=roads[x].size();i++){
| ~^~~~~~~~~~~~~~~~~
circuit.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>)':
circuit.cpp:107:17: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
107 | for(ll i=0;i<a.size();i++){
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
14416 KB |
Output is correct |
2 |
Correct |
7 ms |
14416 KB |
Output is correct |
3 |
Correct |
8 ms |
14576 KB |
Output is correct |
4 |
Correct |
8 ms |
14544 KB |
Output is correct |
5 |
Correct |
8 ms |
14544 KB |
Output is correct |
6 |
Correct |
8 ms |
14544 KB |
Output is correct |
7 |
Correct |
7 ms |
14544 KB |
Output is correct |
8 |
Correct |
8 ms |
14544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14416 KB |
Output is correct |
2 |
Correct |
9 ms |
14416 KB |
Output is correct |
3 |
Correct |
10 ms |
14544 KB |
Output is correct |
4 |
Correct |
8 ms |
14544 KB |
Output is correct |
5 |
Correct |
8 ms |
14544 KB |
Output is correct |
6 |
Correct |
7 ms |
14672 KB |
Output is correct |
7 |
Correct |
8 ms |
14672 KB |
Output is correct |
8 |
Correct |
8 ms |
14608 KB |
Output is correct |
9 |
Correct |
8 ms |
14672 KB |
Output is correct |
10 |
Correct |
8 ms |
14800 KB |
Output is correct |
11 |
Correct |
8 ms |
14800 KB |
Output is correct |
12 |
Correct |
8 ms |
14672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
14416 KB |
Output is correct |
2 |
Correct |
7 ms |
14416 KB |
Output is correct |
3 |
Correct |
8 ms |
14576 KB |
Output is correct |
4 |
Correct |
8 ms |
14544 KB |
Output is correct |
5 |
Correct |
8 ms |
14544 KB |
Output is correct |
6 |
Correct |
8 ms |
14544 KB |
Output is correct |
7 |
Correct |
7 ms |
14544 KB |
Output is correct |
8 |
Correct |
8 ms |
14544 KB |
Output is correct |
9 |
Correct |
7 ms |
14416 KB |
Output is correct |
10 |
Correct |
9 ms |
14416 KB |
Output is correct |
11 |
Correct |
10 ms |
14544 KB |
Output is correct |
12 |
Correct |
8 ms |
14544 KB |
Output is correct |
13 |
Correct |
8 ms |
14544 KB |
Output is correct |
14 |
Correct |
7 ms |
14672 KB |
Output is correct |
15 |
Correct |
8 ms |
14672 KB |
Output is correct |
16 |
Correct |
8 ms |
14608 KB |
Output is correct |
17 |
Correct |
8 ms |
14672 KB |
Output is correct |
18 |
Correct |
8 ms |
14800 KB |
Output is correct |
19 |
Correct |
8 ms |
14800 KB |
Output is correct |
20 |
Correct |
8 ms |
14672 KB |
Output is correct |
21 |
Correct |
9 ms |
14600 KB |
Output is correct |
22 |
Correct |
8 ms |
14544 KB |
Output is correct |
23 |
Correct |
9 ms |
14608 KB |
Output is correct |
24 |
Correct |
10 ms |
14672 KB |
Output is correct |
25 |
Correct |
9 ms |
14660 KB |
Output is correct |
26 |
Correct |
9 ms |
14620 KB |
Output is correct |
27 |
Correct |
8 ms |
14672 KB |
Output is correct |
28 |
Correct |
9 ms |
14672 KB |
Output is correct |
29 |
Correct |
8 ms |
14544 KB |
Output is correct |
30 |
Correct |
9 ms |
14544 KB |
Output is correct |
31 |
Correct |
7 ms |
14672 KB |
Output is correct |
32 |
Correct |
9 ms |
14720 KB |
Output is correct |
33 |
Correct |
9 ms |
14672 KB |
Output is correct |
34 |
Correct |
8 ms |
14544 KB |
Output is correct |
35 |
Correct |
7 ms |
14544 KB |
Output is correct |
36 |
Correct |
8 ms |
14800 KB |
Output is correct |
37 |
Correct |
7 ms |
14800 KB |
Output is correct |
38 |
Correct |
8 ms |
14800 KB |
Output is correct |
39 |
Correct |
8 ms |
14576 KB |
Output is correct |
40 |
Correct |
8 ms |
14544 KB |
Output is correct |
41 |
Correct |
9 ms |
14544 KB |
Output is correct |
42 |
Correct |
9 ms |
14544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
562 ms |
22864 KB |
Output is correct |
2 |
Correct |
701 ms |
31296 KB |
Output is correct |
3 |
Correct |
1018 ms |
31292 KB |
Output is correct |
4 |
Correct |
1078 ms |
30648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
562 ms |
22864 KB |
Output is correct |
2 |
Correct |
701 ms |
31296 KB |
Output is correct |
3 |
Correct |
1018 ms |
31292 KB |
Output is correct |
4 |
Correct |
1078 ms |
30648 KB |
Output is correct |
5 |
Correct |
871 ms |
22840 KB |
Output is correct |
6 |
Correct |
1037 ms |
31280 KB |
Output is correct |
7 |
Correct |
1125 ms |
31296 KB |
Output is correct |
8 |
Correct |
972 ms |
31396 KB |
Output is correct |
9 |
Correct |
594 ms |
14964 KB |
Output is correct |
10 |
Correct |
954 ms |
15440 KB |
Output is correct |
11 |
Correct |
768 ms |
15540 KB |
Output is correct |
12 |
Correct |
862 ms |
15440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14416 KB |
Output is correct |
2 |
Correct |
9 ms |
14416 KB |
Output is correct |
3 |
Correct |
10 ms |
14544 KB |
Output is correct |
4 |
Correct |
8 ms |
14544 KB |
Output is correct |
5 |
Correct |
8 ms |
14544 KB |
Output is correct |
6 |
Correct |
7 ms |
14672 KB |
Output is correct |
7 |
Correct |
8 ms |
14672 KB |
Output is correct |
8 |
Correct |
8 ms |
14608 KB |
Output is correct |
9 |
Correct |
8 ms |
14672 KB |
Output is correct |
10 |
Correct |
8 ms |
14800 KB |
Output is correct |
11 |
Correct |
8 ms |
14800 KB |
Output is correct |
12 |
Correct |
8 ms |
14672 KB |
Output is correct |
13 |
Correct |
562 ms |
22864 KB |
Output is correct |
14 |
Correct |
701 ms |
31296 KB |
Output is correct |
15 |
Correct |
1018 ms |
31292 KB |
Output is correct |
16 |
Correct |
1078 ms |
30648 KB |
Output is correct |
17 |
Correct |
871 ms |
22840 KB |
Output is correct |
18 |
Correct |
1037 ms |
31280 KB |
Output is correct |
19 |
Correct |
1125 ms |
31296 KB |
Output is correct |
20 |
Correct |
972 ms |
31396 KB |
Output is correct |
21 |
Correct |
594 ms |
14964 KB |
Output is correct |
22 |
Correct |
954 ms |
15440 KB |
Output is correct |
23 |
Correct |
768 ms |
15540 KB |
Output is correct |
24 |
Correct |
862 ms |
15440 KB |
Output is correct |
25 |
Correct |
1039 ms |
42148 KB |
Output is correct |
26 |
Correct |
1034 ms |
42420 KB |
Output is correct |
27 |
Correct |
820 ms |
42416 KB |
Output is correct |
28 |
Correct |
929 ms |
42436 KB |
Output is correct |
29 |
Correct |
953 ms |
54984 KB |
Output is correct |
30 |
Correct |
980 ms |
54924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
14416 KB |
Output is correct |
2 |
Correct |
7 ms |
14416 KB |
Output is correct |
3 |
Correct |
8 ms |
14576 KB |
Output is correct |
4 |
Correct |
8 ms |
14544 KB |
Output is correct |
5 |
Correct |
8 ms |
14544 KB |
Output is correct |
6 |
Correct |
8 ms |
14544 KB |
Output is correct |
7 |
Correct |
7 ms |
14544 KB |
Output is correct |
8 |
Correct |
8 ms |
14544 KB |
Output is correct |
9 |
Correct |
7 ms |
14416 KB |
Output is correct |
10 |
Correct |
9 ms |
14416 KB |
Output is correct |
11 |
Correct |
10 ms |
14544 KB |
Output is correct |
12 |
Correct |
8 ms |
14544 KB |
Output is correct |
13 |
Correct |
8 ms |
14544 KB |
Output is correct |
14 |
Correct |
7 ms |
14672 KB |
Output is correct |
15 |
Correct |
8 ms |
14672 KB |
Output is correct |
16 |
Correct |
8 ms |
14608 KB |
Output is correct |
17 |
Correct |
8 ms |
14672 KB |
Output is correct |
18 |
Correct |
8 ms |
14800 KB |
Output is correct |
19 |
Correct |
8 ms |
14800 KB |
Output is correct |
20 |
Correct |
8 ms |
14672 KB |
Output is correct |
21 |
Correct |
9 ms |
14600 KB |
Output is correct |
22 |
Correct |
8 ms |
14544 KB |
Output is correct |
23 |
Correct |
9 ms |
14608 KB |
Output is correct |
24 |
Correct |
10 ms |
14672 KB |
Output is correct |
25 |
Correct |
9 ms |
14660 KB |
Output is correct |
26 |
Correct |
9 ms |
14620 KB |
Output is correct |
27 |
Correct |
8 ms |
14672 KB |
Output is correct |
28 |
Correct |
9 ms |
14672 KB |
Output is correct |
29 |
Correct |
8 ms |
14544 KB |
Output is correct |
30 |
Correct |
9 ms |
14544 KB |
Output is correct |
31 |
Correct |
7 ms |
14672 KB |
Output is correct |
32 |
Correct |
9 ms |
14720 KB |
Output is correct |
33 |
Correct |
9 ms |
14672 KB |
Output is correct |
34 |
Correct |
8 ms |
14544 KB |
Output is correct |
35 |
Correct |
7 ms |
14544 KB |
Output is correct |
36 |
Correct |
8 ms |
14800 KB |
Output is correct |
37 |
Correct |
7 ms |
14800 KB |
Output is correct |
38 |
Correct |
8 ms |
14800 KB |
Output is correct |
39 |
Correct |
8 ms |
14576 KB |
Output is correct |
40 |
Correct |
8 ms |
14544 KB |
Output is correct |
41 |
Correct |
9 ms |
14544 KB |
Output is correct |
42 |
Correct |
9 ms |
14544 KB |
Output is correct |
43 |
Correct |
396 ms |
15288 KB |
Output is correct |
44 |
Correct |
888 ms |
15312 KB |
Output is correct |
45 |
Correct |
870 ms |
15368 KB |
Output is correct |
46 |
Correct |
796 ms |
15892 KB |
Output is correct |
47 |
Correct |
959 ms |
15952 KB |
Output is correct |
48 |
Correct |
791 ms |
15952 KB |
Output is correct |
49 |
Correct |
997 ms |
15952 KB |
Output is correct |
50 |
Correct |
941 ms |
15908 KB |
Output is correct |
51 |
Correct |
867 ms |
15320 KB |
Output is correct |
52 |
Correct |
854 ms |
15412 KB |
Output is correct |
53 |
Correct |
777 ms |
15696 KB |
Output is correct |
54 |
Correct |
1014 ms |
15952 KB |
Output is correct |
55 |
Correct |
882 ms |
15440 KB |
Output is correct |
56 |
Correct |
861 ms |
15440 KB |
Output is correct |
57 |
Correct |
989 ms |
15312 KB |
Output is correct |
58 |
Correct |
870 ms |
16592 KB |
Output is correct |
59 |
Correct |
931 ms |
16720 KB |
Output is correct |
60 |
Correct |
709 ms |
16636 KB |
Output is correct |
61 |
Correct |
1127 ms |
15424 KB |
Output is correct |
62 |
Correct |
995 ms |
15208 KB |
Output is correct |
63 |
Correct |
870 ms |
15312 KB |
Output is correct |
64 |
Correct |
861 ms |
15352 KB |
Output is correct |
65 |
Correct |
465 ms |
14928 KB |
Output is correct |
66 |
Correct |
985 ms |
15660 KB |
Output is correct |
67 |
Correct |
946 ms |
15464 KB |
Output is correct |
68 |
Correct |
901 ms |
15440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
14416 KB |
Output is correct |
2 |
Correct |
7 ms |
14416 KB |
Output is correct |
3 |
Correct |
8 ms |
14576 KB |
Output is correct |
4 |
Correct |
8 ms |
14544 KB |
Output is correct |
5 |
Correct |
8 ms |
14544 KB |
Output is correct |
6 |
Correct |
8 ms |
14544 KB |
Output is correct |
7 |
Correct |
7 ms |
14544 KB |
Output is correct |
8 |
Correct |
8 ms |
14544 KB |
Output is correct |
9 |
Correct |
7 ms |
14416 KB |
Output is correct |
10 |
Correct |
9 ms |
14416 KB |
Output is correct |
11 |
Correct |
10 ms |
14544 KB |
Output is correct |
12 |
Correct |
8 ms |
14544 KB |
Output is correct |
13 |
Correct |
8 ms |
14544 KB |
Output is correct |
14 |
Correct |
7 ms |
14672 KB |
Output is correct |
15 |
Correct |
8 ms |
14672 KB |
Output is correct |
16 |
Correct |
8 ms |
14608 KB |
Output is correct |
17 |
Correct |
8 ms |
14672 KB |
Output is correct |
18 |
Correct |
8 ms |
14800 KB |
Output is correct |
19 |
Correct |
8 ms |
14800 KB |
Output is correct |
20 |
Correct |
8 ms |
14672 KB |
Output is correct |
21 |
Correct |
9 ms |
14600 KB |
Output is correct |
22 |
Correct |
8 ms |
14544 KB |
Output is correct |
23 |
Correct |
9 ms |
14608 KB |
Output is correct |
24 |
Correct |
10 ms |
14672 KB |
Output is correct |
25 |
Correct |
9 ms |
14660 KB |
Output is correct |
26 |
Correct |
9 ms |
14620 KB |
Output is correct |
27 |
Correct |
8 ms |
14672 KB |
Output is correct |
28 |
Correct |
9 ms |
14672 KB |
Output is correct |
29 |
Correct |
8 ms |
14544 KB |
Output is correct |
30 |
Correct |
9 ms |
14544 KB |
Output is correct |
31 |
Correct |
7 ms |
14672 KB |
Output is correct |
32 |
Correct |
9 ms |
14720 KB |
Output is correct |
33 |
Correct |
9 ms |
14672 KB |
Output is correct |
34 |
Correct |
8 ms |
14544 KB |
Output is correct |
35 |
Correct |
7 ms |
14544 KB |
Output is correct |
36 |
Correct |
8 ms |
14800 KB |
Output is correct |
37 |
Correct |
7 ms |
14800 KB |
Output is correct |
38 |
Correct |
8 ms |
14800 KB |
Output is correct |
39 |
Correct |
8 ms |
14576 KB |
Output is correct |
40 |
Correct |
8 ms |
14544 KB |
Output is correct |
41 |
Correct |
9 ms |
14544 KB |
Output is correct |
42 |
Correct |
9 ms |
14544 KB |
Output is correct |
43 |
Correct |
562 ms |
22864 KB |
Output is correct |
44 |
Correct |
701 ms |
31296 KB |
Output is correct |
45 |
Correct |
1018 ms |
31292 KB |
Output is correct |
46 |
Correct |
1078 ms |
30648 KB |
Output is correct |
47 |
Correct |
871 ms |
22840 KB |
Output is correct |
48 |
Correct |
1037 ms |
31280 KB |
Output is correct |
49 |
Correct |
1125 ms |
31296 KB |
Output is correct |
50 |
Correct |
972 ms |
31396 KB |
Output is correct |
51 |
Correct |
594 ms |
14964 KB |
Output is correct |
52 |
Correct |
954 ms |
15440 KB |
Output is correct |
53 |
Correct |
768 ms |
15540 KB |
Output is correct |
54 |
Correct |
862 ms |
15440 KB |
Output is correct |
55 |
Correct |
1039 ms |
42148 KB |
Output is correct |
56 |
Correct |
1034 ms |
42420 KB |
Output is correct |
57 |
Correct |
820 ms |
42416 KB |
Output is correct |
58 |
Correct |
929 ms |
42436 KB |
Output is correct |
59 |
Correct |
953 ms |
54984 KB |
Output is correct |
60 |
Correct |
980 ms |
54924 KB |
Output is correct |
61 |
Correct |
396 ms |
15288 KB |
Output is correct |
62 |
Correct |
888 ms |
15312 KB |
Output is correct |
63 |
Correct |
870 ms |
15368 KB |
Output is correct |
64 |
Correct |
796 ms |
15892 KB |
Output is correct |
65 |
Correct |
959 ms |
15952 KB |
Output is correct |
66 |
Correct |
791 ms |
15952 KB |
Output is correct |
67 |
Correct |
997 ms |
15952 KB |
Output is correct |
68 |
Correct |
941 ms |
15908 KB |
Output is correct |
69 |
Correct |
867 ms |
15320 KB |
Output is correct |
70 |
Correct |
854 ms |
15412 KB |
Output is correct |
71 |
Correct |
777 ms |
15696 KB |
Output is correct |
72 |
Correct |
1014 ms |
15952 KB |
Output is correct |
73 |
Correct |
882 ms |
15440 KB |
Output is correct |
74 |
Correct |
861 ms |
15440 KB |
Output is correct |
75 |
Correct |
989 ms |
15312 KB |
Output is correct |
76 |
Correct |
870 ms |
16592 KB |
Output is correct |
77 |
Correct |
931 ms |
16720 KB |
Output is correct |
78 |
Correct |
709 ms |
16636 KB |
Output is correct |
79 |
Correct |
1127 ms |
15424 KB |
Output is correct |
80 |
Correct |
995 ms |
15208 KB |
Output is correct |
81 |
Correct |
870 ms |
15312 KB |
Output is correct |
82 |
Correct |
861 ms |
15352 KB |
Output is correct |
83 |
Correct |
465 ms |
14928 KB |
Output is correct |
84 |
Correct |
985 ms |
15660 KB |
Output is correct |
85 |
Correct |
946 ms |
15464 KB |
Output is correct |
86 |
Correct |
901 ms |
15440 KB |
Output is correct |
87 |
Correct |
7 ms |
14416 KB |
Output is correct |
88 |
Correct |
653 ms |
40368 KB |
Output is correct |
89 |
Correct |
1036 ms |
31160 KB |
Output is correct |
90 |
Correct |
1002 ms |
31156 KB |
Output is correct |
91 |
Correct |
1087 ms |
43064 KB |
Output is correct |
92 |
Correct |
1119 ms |
43128 KB |
Output is correct |
93 |
Correct |
990 ms |
42516 KB |
Output is correct |
94 |
Correct |
929 ms |
43052 KB |
Output is correct |
95 |
Correct |
1040 ms |
43056 KB |
Output is correct |
96 |
Correct |
999 ms |
31804 KB |
Output is correct |
97 |
Correct |
934 ms |
31804 KB |
Output is correct |
98 |
Correct |
968 ms |
39856 KB |
Output is correct |
99 |
Correct |
1070 ms |
42500 KB |
Output is correct |
100 |
Correct |
1055 ms |
39112 KB |
Output is correct |
101 |
Correct |
888 ms |
32716 KB |
Output is correct |
102 |
Correct |
923 ms |
30384 KB |
Output is correct |
103 |
Correct |
1127 ms |
55112 KB |
Output is correct |
104 |
Correct |
1178 ms |
57284 KB |
Output is correct |
105 |
Correct |
999 ms |
57560 KB |
Output is correct |
106 |
Correct |
888 ms |
32952 KB |
Output is correct |
107 |
Correct |
1020 ms |
29716 KB |
Output is correct |
108 |
Correct |
1286 ms |
30428 KB |
Output is correct |
109 |
Correct |
1135 ms |
30516 KB |
Output is correct |