#include "circuit.h"
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1000002022;
struct T{
int sum,val;
}st[800001];
T operator +(T a, T b){
return {(a.sum+b.sum)%mod,(a.val+b.val)%mod};
}
int n,a[200001],b[200001],lazy[200001],c[200001];
void down(int node, int l, int r){
if (!lazy[node]||l==r)
return;
st[node<<1].val=(st[node<<1].sum-st[node<<1].val+mod)%mod;
lazy[node<<1]^=1;
st[node<<1|1].val=(st[node<<1|1].sum-st[node<<1|1].val+mod)%mod;
lazy[node<<1|1]^=1;
lazy[node]=0;
}
void build(int node, int l, int r){
if (l==r){
st[node]={b[l],a[l]*b[l]};
return;
}
int mid=(l+r)>>1;
build(node<<1,l,mid);
build(node<<1|1,mid+1,r);
st[node]=st[node<<1]+st[node<<1|1];
}
void update(int node, int l, int r, int u, int v){
if (l>v||r<u||l>r||u>v)
return;
if (l>=u&&r<=v){
lazy[node]^=1;
st[node].val=(st[node].sum-st[node].val+mod)%mod;
return;
}
down(node,l,r);
int mid=(l+r)>>1;
update(node<<1,l,mid,u,v);
update(node<<1|1,mid+1,r,u,v);
st[node]=st[node<<1]+st[node<<1|1];
}
vector <int> ke[200001];
void dfs(int u){
if (ke[u].empty()){
c[u]=1;
return;
}
c[u]=ke[u].size();
for (int v:ke[u]){
dfs(v);
c[u]=1LL*c[u]*c[v]%mod;
}
}
void dfs2(int u, int val){
if (ke[u].empty()){
b[u]=val;
return;
}
int d[ke[u].size()];
for (int i=0;i<ke[u].size();i++)
d[i]=1LL*(i?d[i-1]:1)*c[ke[u][i]]%mod;
int cur=1;
for (int i=ke[u].size()-1;i>=0;i--){
dfs2(ke[u][i],1LL*cur*(i?d[i-1]:1)%mod*val%mod);
cur=1LL*cur*c[ke[u][i]]%mod;
}
}
void init(int32_t N, int32_t M, vector <int32_t> P, vector <int32_t> A){
n=N+M;
for (int i=0;i<M;i++)
a[N+i]=A[i];
for (int i=1;i<N+M;i++)
ke[P[i]].push_back(i);
dfs(0);
dfs2(0,1);
build(1,0,n-1);
}
int32_t count_ways(int32_t L, int32_t R){
update(1,0,n-1,L,R);
return st[1].val;
}
Compilation message
circuit.cpp: In function 'void dfs2(long long int, long long int)':
circuit.cpp:64:19: 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]
64 | for (int i=0;i<ke[u].size();i++)
| ~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12888 KB |
Output is correct |
2 |
Correct |
2 ms |
12888 KB |
Output is correct |
3 |
Correct |
2 ms |
12888 KB |
Output is correct |
4 |
Correct |
2 ms |
12888 KB |
Output is correct |
5 |
Correct |
2 ms |
12928 KB |
Output is correct |
6 |
Correct |
2 ms |
12888 KB |
Output is correct |
7 |
Correct |
2 ms |
12888 KB |
Output is correct |
8 |
Correct |
2 ms |
12888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12888 KB |
Output is correct |
2 |
Correct |
2 ms |
12888 KB |
Output is correct |
3 |
Correct |
2 ms |
12888 KB |
Output is correct |
4 |
Correct |
2 ms |
12888 KB |
Output is correct |
5 |
Correct |
2 ms |
12888 KB |
Output is correct |
6 |
Correct |
2 ms |
12900 KB |
Output is correct |
7 |
Correct |
2 ms |
12888 KB |
Output is correct |
8 |
Correct |
2 ms |
12888 KB |
Output is correct |
9 |
Correct |
2 ms |
12888 KB |
Output is correct |
10 |
Correct |
2 ms |
12888 KB |
Output is correct |
11 |
Correct |
3 ms |
12888 KB |
Output is correct |
12 |
Correct |
2 ms |
12892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12888 KB |
Output is correct |
2 |
Correct |
2 ms |
12888 KB |
Output is correct |
3 |
Correct |
2 ms |
12888 KB |
Output is correct |
4 |
Correct |
2 ms |
12888 KB |
Output is correct |
5 |
Correct |
2 ms |
12928 KB |
Output is correct |
6 |
Correct |
2 ms |
12888 KB |
Output is correct |
7 |
Correct |
2 ms |
12888 KB |
Output is correct |
8 |
Correct |
2 ms |
12888 KB |
Output is correct |
9 |
Correct |
2 ms |
12888 KB |
Output is correct |
10 |
Correct |
2 ms |
12888 KB |
Output is correct |
11 |
Correct |
2 ms |
12888 KB |
Output is correct |
12 |
Correct |
2 ms |
12888 KB |
Output is correct |
13 |
Correct |
2 ms |
12888 KB |
Output is correct |
14 |
Correct |
2 ms |
12900 KB |
Output is correct |
15 |
Correct |
2 ms |
12888 KB |
Output is correct |
16 |
Correct |
2 ms |
12888 KB |
Output is correct |
17 |
Correct |
2 ms |
12888 KB |
Output is correct |
18 |
Correct |
2 ms |
12888 KB |
Output is correct |
19 |
Correct |
3 ms |
12888 KB |
Output is correct |
20 |
Correct |
2 ms |
12892 KB |
Output is correct |
21 |
Correct |
2 ms |
12888 KB |
Output is correct |
22 |
Correct |
2 ms |
12888 KB |
Output is correct |
23 |
Correct |
2 ms |
12888 KB |
Output is correct |
24 |
Correct |
2 ms |
12888 KB |
Output is correct |
25 |
Correct |
2 ms |
12888 KB |
Output is correct |
26 |
Correct |
2 ms |
12888 KB |
Output is correct |
27 |
Correct |
2 ms |
12888 KB |
Output is correct |
28 |
Correct |
2 ms |
12960 KB |
Output is correct |
29 |
Correct |
2 ms |
12888 KB |
Output is correct |
30 |
Correct |
2 ms |
12888 KB |
Output is correct |
31 |
Correct |
2 ms |
12888 KB |
Output is correct |
32 |
Correct |
2 ms |
12888 KB |
Output is correct |
33 |
Correct |
3 ms |
12888 KB |
Output is correct |
34 |
Correct |
2 ms |
12888 KB |
Output is correct |
35 |
Correct |
2 ms |
12888 KB |
Output is correct |
36 |
Correct |
2 ms |
12888 KB |
Output is correct |
37 |
Correct |
2 ms |
12888 KB |
Output is correct |
38 |
Correct |
2 ms |
12888 KB |
Output is correct |
39 |
Correct |
2 ms |
12888 KB |
Output is correct |
40 |
Correct |
2 ms |
12888 KB |
Output is correct |
41 |
Correct |
2 ms |
12888 KB |
Output is correct |
42 |
Correct |
2 ms |
12884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
384 ms |
16640 KB |
Output is correct |
2 |
Correct |
557 ms |
20604 KB |
Output is correct |
3 |
Correct |
567 ms |
20608 KB |
Output is correct |
4 |
Correct |
561 ms |
20612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
384 ms |
16640 KB |
Output is correct |
2 |
Correct |
557 ms |
20604 KB |
Output is correct |
3 |
Correct |
567 ms |
20608 KB |
Output is correct |
4 |
Correct |
561 ms |
20612 KB |
Output is correct |
5 |
Correct |
468 ms |
16640 KB |
Output is correct |
6 |
Correct |
573 ms |
20616 KB |
Output is correct |
7 |
Correct |
616 ms |
20588 KB |
Output is correct |
8 |
Correct |
586 ms |
20608 KB |
Output is correct |
9 |
Correct |
241 ms |
12888 KB |
Output is correct |
10 |
Correct |
538 ms |
13144 KB |
Output is correct |
11 |
Correct |
531 ms |
13144 KB |
Output is correct |
12 |
Correct |
531 ms |
13144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12888 KB |
Output is correct |
2 |
Correct |
2 ms |
12888 KB |
Output is correct |
3 |
Correct |
2 ms |
12888 KB |
Output is correct |
4 |
Correct |
2 ms |
12888 KB |
Output is correct |
5 |
Correct |
2 ms |
12888 KB |
Output is correct |
6 |
Correct |
2 ms |
12900 KB |
Output is correct |
7 |
Correct |
2 ms |
12888 KB |
Output is correct |
8 |
Correct |
2 ms |
12888 KB |
Output is correct |
9 |
Correct |
2 ms |
12888 KB |
Output is correct |
10 |
Correct |
2 ms |
12888 KB |
Output is correct |
11 |
Correct |
3 ms |
12888 KB |
Output is correct |
12 |
Correct |
2 ms |
12892 KB |
Output is correct |
13 |
Correct |
384 ms |
16640 KB |
Output is correct |
14 |
Correct |
557 ms |
20604 KB |
Output is correct |
15 |
Correct |
567 ms |
20608 KB |
Output is correct |
16 |
Correct |
561 ms |
20612 KB |
Output is correct |
17 |
Correct |
468 ms |
16640 KB |
Output is correct |
18 |
Correct |
573 ms |
20616 KB |
Output is correct |
19 |
Correct |
616 ms |
20588 KB |
Output is correct |
20 |
Correct |
586 ms |
20608 KB |
Output is correct |
21 |
Correct |
241 ms |
12888 KB |
Output is correct |
22 |
Correct |
538 ms |
13144 KB |
Output is correct |
23 |
Correct |
531 ms |
13144 KB |
Output is correct |
24 |
Correct |
531 ms |
13144 KB |
Output is correct |
25 |
Correct |
629 ms |
25104 KB |
Output is correct |
26 |
Correct |
627 ms |
24420 KB |
Output is correct |
27 |
Correct |
618 ms |
24648 KB |
Output is correct |
28 |
Correct |
492 ms |
24340 KB |
Output is correct |
29 |
Correct |
617 ms |
36916 KB |
Output is correct |
30 |
Correct |
573 ms |
36860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12888 KB |
Output is correct |
2 |
Correct |
2 ms |
12888 KB |
Output is correct |
3 |
Correct |
2 ms |
12888 KB |
Output is correct |
4 |
Correct |
2 ms |
12888 KB |
Output is correct |
5 |
Correct |
2 ms |
12928 KB |
Output is correct |
6 |
Correct |
2 ms |
12888 KB |
Output is correct |
7 |
Correct |
2 ms |
12888 KB |
Output is correct |
8 |
Correct |
2 ms |
12888 KB |
Output is correct |
9 |
Correct |
2 ms |
12888 KB |
Output is correct |
10 |
Correct |
2 ms |
12888 KB |
Output is correct |
11 |
Correct |
2 ms |
12888 KB |
Output is correct |
12 |
Correct |
2 ms |
12888 KB |
Output is correct |
13 |
Correct |
2 ms |
12888 KB |
Output is correct |
14 |
Correct |
2 ms |
12900 KB |
Output is correct |
15 |
Correct |
2 ms |
12888 KB |
Output is correct |
16 |
Correct |
2 ms |
12888 KB |
Output is correct |
17 |
Correct |
2 ms |
12888 KB |
Output is correct |
18 |
Correct |
2 ms |
12888 KB |
Output is correct |
19 |
Correct |
3 ms |
12888 KB |
Output is correct |
20 |
Correct |
2 ms |
12892 KB |
Output is correct |
21 |
Correct |
2 ms |
12888 KB |
Output is correct |
22 |
Correct |
2 ms |
12888 KB |
Output is correct |
23 |
Correct |
2 ms |
12888 KB |
Output is correct |
24 |
Correct |
2 ms |
12888 KB |
Output is correct |
25 |
Correct |
2 ms |
12888 KB |
Output is correct |
26 |
Correct |
2 ms |
12888 KB |
Output is correct |
27 |
Correct |
2 ms |
12888 KB |
Output is correct |
28 |
Correct |
2 ms |
12960 KB |
Output is correct |
29 |
Correct |
2 ms |
12888 KB |
Output is correct |
30 |
Correct |
2 ms |
12888 KB |
Output is correct |
31 |
Correct |
2 ms |
12888 KB |
Output is correct |
32 |
Correct |
2 ms |
12888 KB |
Output is correct |
33 |
Correct |
3 ms |
12888 KB |
Output is correct |
34 |
Correct |
2 ms |
12888 KB |
Output is correct |
35 |
Correct |
2 ms |
12888 KB |
Output is correct |
36 |
Correct |
2 ms |
12888 KB |
Output is correct |
37 |
Correct |
2 ms |
12888 KB |
Output is correct |
38 |
Correct |
2 ms |
12888 KB |
Output is correct |
39 |
Correct |
2 ms |
12888 KB |
Output is correct |
40 |
Correct |
2 ms |
12888 KB |
Output is correct |
41 |
Correct |
2 ms |
12888 KB |
Output is correct |
42 |
Correct |
2 ms |
12884 KB |
Output is correct |
43 |
Correct |
356 ms |
12888 KB |
Output is correct |
44 |
Correct |
509 ms |
12888 KB |
Output is correct |
45 |
Correct |
520 ms |
12888 KB |
Output is correct |
46 |
Correct |
514 ms |
13144 KB |
Output is correct |
47 |
Correct |
565 ms |
13144 KB |
Output is correct |
48 |
Correct |
550 ms |
13144 KB |
Output is correct |
49 |
Correct |
532 ms |
13144 KB |
Output is correct |
50 |
Correct |
512 ms |
13144 KB |
Output is correct |
51 |
Correct |
490 ms |
13124 KB |
Output is correct |
52 |
Correct |
522 ms |
13144 KB |
Output is correct |
53 |
Correct |
482 ms |
13656 KB |
Output is correct |
54 |
Correct |
512 ms |
13144 KB |
Output is correct |
55 |
Correct |
544 ms |
13144 KB |
Output is correct |
56 |
Correct |
510 ms |
12888 KB |
Output is correct |
57 |
Correct |
554 ms |
12888 KB |
Output is correct |
58 |
Correct |
510 ms |
13656 KB |
Output is correct |
59 |
Correct |
529 ms |
14160 KB |
Output is correct |
60 |
Correct |
500 ms |
13944 KB |
Output is correct |
61 |
Correct |
545 ms |
13144 KB |
Output is correct |
62 |
Correct |
554 ms |
12884 KB |
Output is correct |
63 |
Correct |
526 ms |
12888 KB |
Output is correct |
64 |
Correct |
548 ms |
12888 KB |
Output is correct |
65 |
Correct |
268 ms |
12888 KB |
Output is correct |
66 |
Correct |
560 ms |
13144 KB |
Output is correct |
67 |
Correct |
552 ms |
13144 KB |
Output is correct |
68 |
Correct |
532 ms |
13144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
12888 KB |
Output is correct |
2 |
Correct |
2 ms |
12888 KB |
Output is correct |
3 |
Correct |
2 ms |
12888 KB |
Output is correct |
4 |
Correct |
2 ms |
12888 KB |
Output is correct |
5 |
Correct |
2 ms |
12928 KB |
Output is correct |
6 |
Correct |
2 ms |
12888 KB |
Output is correct |
7 |
Correct |
2 ms |
12888 KB |
Output is correct |
8 |
Correct |
2 ms |
12888 KB |
Output is correct |
9 |
Correct |
2 ms |
12888 KB |
Output is correct |
10 |
Correct |
2 ms |
12888 KB |
Output is correct |
11 |
Correct |
2 ms |
12888 KB |
Output is correct |
12 |
Correct |
2 ms |
12888 KB |
Output is correct |
13 |
Correct |
2 ms |
12888 KB |
Output is correct |
14 |
Correct |
2 ms |
12900 KB |
Output is correct |
15 |
Correct |
2 ms |
12888 KB |
Output is correct |
16 |
Correct |
2 ms |
12888 KB |
Output is correct |
17 |
Correct |
2 ms |
12888 KB |
Output is correct |
18 |
Correct |
2 ms |
12888 KB |
Output is correct |
19 |
Correct |
3 ms |
12888 KB |
Output is correct |
20 |
Correct |
2 ms |
12892 KB |
Output is correct |
21 |
Correct |
2 ms |
12888 KB |
Output is correct |
22 |
Correct |
2 ms |
12888 KB |
Output is correct |
23 |
Correct |
2 ms |
12888 KB |
Output is correct |
24 |
Correct |
2 ms |
12888 KB |
Output is correct |
25 |
Correct |
2 ms |
12888 KB |
Output is correct |
26 |
Correct |
2 ms |
12888 KB |
Output is correct |
27 |
Correct |
2 ms |
12888 KB |
Output is correct |
28 |
Correct |
2 ms |
12960 KB |
Output is correct |
29 |
Correct |
2 ms |
12888 KB |
Output is correct |
30 |
Correct |
2 ms |
12888 KB |
Output is correct |
31 |
Correct |
2 ms |
12888 KB |
Output is correct |
32 |
Correct |
2 ms |
12888 KB |
Output is correct |
33 |
Correct |
3 ms |
12888 KB |
Output is correct |
34 |
Correct |
2 ms |
12888 KB |
Output is correct |
35 |
Correct |
2 ms |
12888 KB |
Output is correct |
36 |
Correct |
2 ms |
12888 KB |
Output is correct |
37 |
Correct |
2 ms |
12888 KB |
Output is correct |
38 |
Correct |
2 ms |
12888 KB |
Output is correct |
39 |
Correct |
2 ms |
12888 KB |
Output is correct |
40 |
Correct |
2 ms |
12888 KB |
Output is correct |
41 |
Correct |
2 ms |
12888 KB |
Output is correct |
42 |
Correct |
2 ms |
12884 KB |
Output is correct |
43 |
Correct |
384 ms |
16640 KB |
Output is correct |
44 |
Correct |
557 ms |
20604 KB |
Output is correct |
45 |
Correct |
567 ms |
20608 KB |
Output is correct |
46 |
Correct |
561 ms |
20612 KB |
Output is correct |
47 |
Correct |
468 ms |
16640 KB |
Output is correct |
48 |
Correct |
573 ms |
20616 KB |
Output is correct |
49 |
Correct |
616 ms |
20588 KB |
Output is correct |
50 |
Correct |
586 ms |
20608 KB |
Output is correct |
51 |
Correct |
241 ms |
12888 KB |
Output is correct |
52 |
Correct |
538 ms |
13144 KB |
Output is correct |
53 |
Correct |
531 ms |
13144 KB |
Output is correct |
54 |
Correct |
531 ms |
13144 KB |
Output is correct |
55 |
Correct |
629 ms |
25104 KB |
Output is correct |
56 |
Correct |
627 ms |
24420 KB |
Output is correct |
57 |
Correct |
618 ms |
24648 KB |
Output is correct |
58 |
Correct |
492 ms |
24340 KB |
Output is correct |
59 |
Correct |
617 ms |
36916 KB |
Output is correct |
60 |
Correct |
573 ms |
36860 KB |
Output is correct |
61 |
Correct |
356 ms |
12888 KB |
Output is correct |
62 |
Correct |
509 ms |
12888 KB |
Output is correct |
63 |
Correct |
520 ms |
12888 KB |
Output is correct |
64 |
Correct |
514 ms |
13144 KB |
Output is correct |
65 |
Correct |
565 ms |
13144 KB |
Output is correct |
66 |
Correct |
550 ms |
13144 KB |
Output is correct |
67 |
Correct |
532 ms |
13144 KB |
Output is correct |
68 |
Correct |
512 ms |
13144 KB |
Output is correct |
69 |
Correct |
490 ms |
13124 KB |
Output is correct |
70 |
Correct |
522 ms |
13144 KB |
Output is correct |
71 |
Correct |
482 ms |
13656 KB |
Output is correct |
72 |
Correct |
512 ms |
13144 KB |
Output is correct |
73 |
Correct |
544 ms |
13144 KB |
Output is correct |
74 |
Correct |
510 ms |
12888 KB |
Output is correct |
75 |
Correct |
554 ms |
12888 KB |
Output is correct |
76 |
Correct |
510 ms |
13656 KB |
Output is correct |
77 |
Correct |
529 ms |
14160 KB |
Output is correct |
78 |
Correct |
500 ms |
13944 KB |
Output is correct |
79 |
Correct |
545 ms |
13144 KB |
Output is correct |
80 |
Correct |
554 ms |
12884 KB |
Output is correct |
81 |
Correct |
526 ms |
12888 KB |
Output is correct |
82 |
Correct |
548 ms |
12888 KB |
Output is correct |
83 |
Correct |
268 ms |
12888 KB |
Output is correct |
84 |
Correct |
560 ms |
13144 KB |
Output is correct |
85 |
Correct |
552 ms |
13144 KB |
Output is correct |
86 |
Correct |
532 ms |
13144 KB |
Output is correct |
87 |
Correct |
2 ms |
12888 KB |
Output is correct |
88 |
Correct |
390 ms |
24696 KB |
Output is correct |
89 |
Correct |
609 ms |
19404 KB |
Output is correct |
90 |
Correct |
606 ms |
20796 KB |
Output is correct |
91 |
Correct |
581 ms |
25148 KB |
Output is correct |
92 |
Correct |
613 ms |
25088 KB |
Output is correct |
93 |
Correct |
650 ms |
25188 KB |
Output is correct |
94 |
Correct |
632 ms |
25512 KB |
Output is correct |
95 |
Correct |
576 ms |
25080 KB |
Output is correct |
96 |
Correct |
538 ms |
20172 KB |
Output is correct |
97 |
Correct |
597 ms |
20172 KB |
Output is correct |
98 |
Correct |
551 ms |
31312 KB |
Output is correct |
99 |
Correct |
641 ms |
24684 KB |
Output is correct |
100 |
Incorrect |
593 ms |
25424 KB |
119th lines differ - on the 1st token, expected: '688149308', found: '513157708' |
101 |
Halted |
0 ms |
0 KB |
- |