#include "circuit.h"
#include <vector>
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()]={0};
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(int N, int M, vector <int> P, vector <int> 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);
}
int count_ways(int L, int R){
update(1,0,n-1,L,R);
return st[1].val;
}
Compilation message
circuit.cpp: In function 'void dfs2(int, int)':
circuit.cpp:63:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
63 | for (int i=0;i<ke[u].size();i++)
| ~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
9560 KB |
Output is correct |
2 |
Correct |
2 ms |
9560 KB |
Output is correct |
3 |
Correct |
2 ms |
9560 KB |
Output is correct |
4 |
Correct |
2 ms |
9560 KB |
Output is correct |
5 |
Correct |
2 ms |
9560 KB |
Output is correct |
6 |
Correct |
3 ms |
9572 KB |
Output is correct |
7 |
Correct |
2 ms |
9560 KB |
Output is correct |
8 |
Correct |
2 ms |
9560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
9560 KB |
Output is correct |
2 |
Correct |
2 ms |
9560 KB |
Output is correct |
3 |
Correct |
2 ms |
9560 KB |
Output is correct |
4 |
Correct |
2 ms |
9560 KB |
Output is correct |
5 |
Correct |
2 ms |
9624 KB |
Output is correct |
6 |
Correct |
2 ms |
9560 KB |
Output is correct |
7 |
Correct |
2 ms |
9560 KB |
Output is correct |
8 |
Correct |
2 ms |
9560 KB |
Output is correct |
9 |
Correct |
2 ms |
9560 KB |
Output is correct |
10 |
Correct |
3 ms |
9816 KB |
Output is correct |
11 |
Correct |
2 ms |
9816 KB |
Output is correct |
12 |
Correct |
2 ms |
9560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
9560 KB |
Output is correct |
2 |
Correct |
2 ms |
9560 KB |
Output is correct |
3 |
Correct |
2 ms |
9560 KB |
Output is correct |
4 |
Correct |
2 ms |
9560 KB |
Output is correct |
5 |
Correct |
2 ms |
9560 KB |
Output is correct |
6 |
Correct |
3 ms |
9572 KB |
Output is correct |
7 |
Correct |
2 ms |
9560 KB |
Output is correct |
8 |
Correct |
2 ms |
9560 KB |
Output is correct |
9 |
Correct |
2 ms |
9560 KB |
Output is correct |
10 |
Correct |
2 ms |
9560 KB |
Output is correct |
11 |
Correct |
2 ms |
9560 KB |
Output is correct |
12 |
Correct |
2 ms |
9560 KB |
Output is correct |
13 |
Correct |
2 ms |
9624 KB |
Output is correct |
14 |
Correct |
2 ms |
9560 KB |
Output is correct |
15 |
Correct |
2 ms |
9560 KB |
Output is correct |
16 |
Correct |
2 ms |
9560 KB |
Output is correct |
17 |
Correct |
2 ms |
9560 KB |
Output is correct |
18 |
Correct |
3 ms |
9816 KB |
Output is correct |
19 |
Correct |
2 ms |
9816 KB |
Output is correct |
20 |
Correct |
2 ms |
9560 KB |
Output is correct |
21 |
Correct |
2 ms |
9560 KB |
Output is correct |
22 |
Correct |
2 ms |
9632 KB |
Output is correct |
23 |
Correct |
2 ms |
9560 KB |
Output is correct |
24 |
Correct |
2 ms |
9560 KB |
Output is correct |
25 |
Correct |
3 ms |
9560 KB |
Output is correct |
26 |
Correct |
2 ms |
9560 KB |
Output is correct |
27 |
Correct |
2 ms |
9560 KB |
Output is correct |
28 |
Correct |
2 ms |
9560 KB |
Output is correct |
29 |
Correct |
2 ms |
9560 KB |
Output is correct |
30 |
Correct |
2 ms |
9560 KB |
Output is correct |
31 |
Correct |
2 ms |
9560 KB |
Output is correct |
32 |
Correct |
2 ms |
9560 KB |
Output is correct |
33 |
Correct |
2 ms |
9560 KB |
Output is correct |
34 |
Correct |
3 ms |
9560 KB |
Output is correct |
35 |
Correct |
2 ms |
9560 KB |
Output is correct |
36 |
Correct |
2 ms |
9816 KB |
Output is correct |
37 |
Correct |
2 ms |
9840 KB |
Output is correct |
38 |
Correct |
2 ms |
10068 KB |
Output is correct |
39 |
Correct |
2 ms |
9560 KB |
Output is correct |
40 |
Correct |
2 ms |
9560 KB |
Output is correct |
41 |
Correct |
2 ms |
9560 KB |
Output is correct |
42 |
Correct |
2 ms |
9560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
414 ms |
11340 KB |
Output is correct |
2 |
Correct |
635 ms |
15272 KB |
Output is correct |
3 |
Correct |
583 ms |
15296 KB |
Output is correct |
4 |
Correct |
568 ms |
15296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
414 ms |
11340 KB |
Output is correct |
2 |
Correct |
635 ms |
15272 KB |
Output is correct |
3 |
Correct |
583 ms |
15296 KB |
Output is correct |
4 |
Correct |
568 ms |
15296 KB |
Output is correct |
5 |
Correct |
484 ms |
11268 KB |
Output is correct |
6 |
Correct |
622 ms |
15448 KB |
Output is correct |
7 |
Correct |
563 ms |
15300 KB |
Output is correct |
8 |
Correct |
568 ms |
15288 KB |
Output is correct |
9 |
Correct |
299 ms |
9560 KB |
Output is correct |
10 |
Correct |
516 ms |
9816 KB |
Output is correct |
11 |
Correct |
527 ms |
9816 KB |
Output is correct |
12 |
Correct |
547 ms |
9816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
9560 KB |
Output is correct |
2 |
Correct |
2 ms |
9560 KB |
Output is correct |
3 |
Correct |
2 ms |
9560 KB |
Output is correct |
4 |
Correct |
2 ms |
9560 KB |
Output is correct |
5 |
Correct |
2 ms |
9624 KB |
Output is correct |
6 |
Correct |
2 ms |
9560 KB |
Output is correct |
7 |
Correct |
2 ms |
9560 KB |
Output is correct |
8 |
Correct |
2 ms |
9560 KB |
Output is correct |
9 |
Correct |
2 ms |
9560 KB |
Output is correct |
10 |
Correct |
3 ms |
9816 KB |
Output is correct |
11 |
Correct |
2 ms |
9816 KB |
Output is correct |
12 |
Correct |
2 ms |
9560 KB |
Output is correct |
13 |
Correct |
414 ms |
11340 KB |
Output is correct |
14 |
Correct |
635 ms |
15272 KB |
Output is correct |
15 |
Correct |
583 ms |
15296 KB |
Output is correct |
16 |
Correct |
568 ms |
15296 KB |
Output is correct |
17 |
Correct |
484 ms |
11268 KB |
Output is correct |
18 |
Correct |
622 ms |
15448 KB |
Output is correct |
19 |
Correct |
563 ms |
15300 KB |
Output is correct |
20 |
Correct |
568 ms |
15288 KB |
Output is correct |
21 |
Correct |
299 ms |
9560 KB |
Output is correct |
22 |
Correct |
516 ms |
9816 KB |
Output is correct |
23 |
Correct |
527 ms |
9816 KB |
Output is correct |
24 |
Correct |
547 ms |
9816 KB |
Output is correct |
25 |
Correct |
564 ms |
18980 KB |
Output is correct |
26 |
Correct |
649 ms |
19000 KB |
Output is correct |
27 |
Correct |
622 ms |
19004 KB |
Output is correct |
28 |
Correct |
485 ms |
19096 KB |
Output is correct |
29 |
Correct |
635 ms |
31568 KB |
Output is correct |
30 |
Correct |
600 ms |
31664 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
9560 KB |
Output is correct |
2 |
Correct |
2 ms |
9560 KB |
Output is correct |
3 |
Correct |
2 ms |
9560 KB |
Output is correct |
4 |
Correct |
2 ms |
9560 KB |
Output is correct |
5 |
Correct |
2 ms |
9560 KB |
Output is correct |
6 |
Correct |
3 ms |
9572 KB |
Output is correct |
7 |
Correct |
2 ms |
9560 KB |
Output is correct |
8 |
Correct |
2 ms |
9560 KB |
Output is correct |
9 |
Correct |
2 ms |
9560 KB |
Output is correct |
10 |
Correct |
2 ms |
9560 KB |
Output is correct |
11 |
Correct |
2 ms |
9560 KB |
Output is correct |
12 |
Correct |
2 ms |
9560 KB |
Output is correct |
13 |
Correct |
2 ms |
9624 KB |
Output is correct |
14 |
Correct |
2 ms |
9560 KB |
Output is correct |
15 |
Correct |
2 ms |
9560 KB |
Output is correct |
16 |
Correct |
2 ms |
9560 KB |
Output is correct |
17 |
Correct |
2 ms |
9560 KB |
Output is correct |
18 |
Correct |
3 ms |
9816 KB |
Output is correct |
19 |
Correct |
2 ms |
9816 KB |
Output is correct |
20 |
Correct |
2 ms |
9560 KB |
Output is correct |
21 |
Correct |
2 ms |
9560 KB |
Output is correct |
22 |
Correct |
2 ms |
9632 KB |
Output is correct |
23 |
Correct |
2 ms |
9560 KB |
Output is correct |
24 |
Correct |
2 ms |
9560 KB |
Output is correct |
25 |
Correct |
3 ms |
9560 KB |
Output is correct |
26 |
Correct |
2 ms |
9560 KB |
Output is correct |
27 |
Correct |
2 ms |
9560 KB |
Output is correct |
28 |
Correct |
2 ms |
9560 KB |
Output is correct |
29 |
Correct |
2 ms |
9560 KB |
Output is correct |
30 |
Correct |
2 ms |
9560 KB |
Output is correct |
31 |
Correct |
2 ms |
9560 KB |
Output is correct |
32 |
Correct |
2 ms |
9560 KB |
Output is correct |
33 |
Correct |
2 ms |
9560 KB |
Output is correct |
34 |
Correct |
3 ms |
9560 KB |
Output is correct |
35 |
Correct |
2 ms |
9560 KB |
Output is correct |
36 |
Correct |
2 ms |
9816 KB |
Output is correct |
37 |
Correct |
2 ms |
9840 KB |
Output is correct |
38 |
Correct |
2 ms |
10068 KB |
Output is correct |
39 |
Correct |
2 ms |
9560 KB |
Output is correct |
40 |
Correct |
2 ms |
9560 KB |
Output is correct |
41 |
Correct |
2 ms |
9560 KB |
Output is correct |
42 |
Correct |
2 ms |
9560 KB |
Output is correct |
43 |
Correct |
404 ms |
9560 KB |
Output is correct |
44 |
Correct |
554 ms |
9816 KB |
Output is correct |
45 |
Correct |
538 ms |
9816 KB |
Output is correct |
46 |
Correct |
570 ms |
9816 KB |
Output is correct |
47 |
Correct |
561 ms |
9816 KB |
Output is correct |
48 |
Correct |
556 ms |
9816 KB |
Output is correct |
49 |
Correct |
546 ms |
9816 KB |
Output is correct |
50 |
Correct |
526 ms |
9816 KB |
Output is correct |
51 |
Correct |
508 ms |
9560 KB |
Output is correct |
52 |
Correct |
534 ms |
9560 KB |
Output is correct |
53 |
Correct |
490 ms |
10328 KB |
Output is correct |
54 |
Correct |
589 ms |
9816 KB |
Output is correct |
55 |
Correct |
585 ms |
9816 KB |
Output is correct |
56 |
Correct |
550 ms |
9560 KB |
Output is correct |
57 |
Correct |
554 ms |
9560 KB |
Output is correct |
58 |
Correct |
522 ms |
10328 KB |
Output is correct |
59 |
Correct |
506 ms |
10596 KB |
Output is correct |
60 |
Correct |
504 ms |
10616 KB |
Output is correct |
61 |
Correct |
526 ms |
9816 KB |
Output is correct |
62 |
Correct |
578 ms |
9560 KB |
Output is correct |
63 |
Correct |
584 ms |
9560 KB |
Output is correct |
64 |
Correct |
569 ms |
9812 KB |
Output is correct |
65 |
Correct |
275 ms |
9560 KB |
Output is correct |
66 |
Correct |
528 ms |
9816 KB |
Output is correct |
67 |
Correct |
525 ms |
9816 KB |
Output is correct |
68 |
Correct |
591 ms |
9816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
9560 KB |
Output is correct |
2 |
Correct |
2 ms |
9560 KB |
Output is correct |
3 |
Correct |
2 ms |
9560 KB |
Output is correct |
4 |
Correct |
2 ms |
9560 KB |
Output is correct |
5 |
Correct |
2 ms |
9560 KB |
Output is correct |
6 |
Correct |
3 ms |
9572 KB |
Output is correct |
7 |
Correct |
2 ms |
9560 KB |
Output is correct |
8 |
Correct |
2 ms |
9560 KB |
Output is correct |
9 |
Correct |
2 ms |
9560 KB |
Output is correct |
10 |
Correct |
2 ms |
9560 KB |
Output is correct |
11 |
Correct |
2 ms |
9560 KB |
Output is correct |
12 |
Correct |
2 ms |
9560 KB |
Output is correct |
13 |
Correct |
2 ms |
9624 KB |
Output is correct |
14 |
Correct |
2 ms |
9560 KB |
Output is correct |
15 |
Correct |
2 ms |
9560 KB |
Output is correct |
16 |
Correct |
2 ms |
9560 KB |
Output is correct |
17 |
Correct |
2 ms |
9560 KB |
Output is correct |
18 |
Correct |
3 ms |
9816 KB |
Output is correct |
19 |
Correct |
2 ms |
9816 KB |
Output is correct |
20 |
Correct |
2 ms |
9560 KB |
Output is correct |
21 |
Correct |
2 ms |
9560 KB |
Output is correct |
22 |
Correct |
2 ms |
9632 KB |
Output is correct |
23 |
Correct |
2 ms |
9560 KB |
Output is correct |
24 |
Correct |
2 ms |
9560 KB |
Output is correct |
25 |
Correct |
3 ms |
9560 KB |
Output is correct |
26 |
Correct |
2 ms |
9560 KB |
Output is correct |
27 |
Correct |
2 ms |
9560 KB |
Output is correct |
28 |
Correct |
2 ms |
9560 KB |
Output is correct |
29 |
Correct |
2 ms |
9560 KB |
Output is correct |
30 |
Correct |
2 ms |
9560 KB |
Output is correct |
31 |
Correct |
2 ms |
9560 KB |
Output is correct |
32 |
Correct |
2 ms |
9560 KB |
Output is correct |
33 |
Correct |
2 ms |
9560 KB |
Output is correct |
34 |
Correct |
3 ms |
9560 KB |
Output is correct |
35 |
Correct |
2 ms |
9560 KB |
Output is correct |
36 |
Correct |
2 ms |
9816 KB |
Output is correct |
37 |
Correct |
2 ms |
9840 KB |
Output is correct |
38 |
Correct |
2 ms |
10068 KB |
Output is correct |
39 |
Correct |
2 ms |
9560 KB |
Output is correct |
40 |
Correct |
2 ms |
9560 KB |
Output is correct |
41 |
Correct |
2 ms |
9560 KB |
Output is correct |
42 |
Correct |
2 ms |
9560 KB |
Output is correct |
43 |
Correct |
414 ms |
11340 KB |
Output is correct |
44 |
Correct |
635 ms |
15272 KB |
Output is correct |
45 |
Correct |
583 ms |
15296 KB |
Output is correct |
46 |
Correct |
568 ms |
15296 KB |
Output is correct |
47 |
Correct |
484 ms |
11268 KB |
Output is correct |
48 |
Correct |
622 ms |
15448 KB |
Output is correct |
49 |
Correct |
563 ms |
15300 KB |
Output is correct |
50 |
Correct |
568 ms |
15288 KB |
Output is correct |
51 |
Correct |
299 ms |
9560 KB |
Output is correct |
52 |
Correct |
516 ms |
9816 KB |
Output is correct |
53 |
Correct |
527 ms |
9816 KB |
Output is correct |
54 |
Correct |
547 ms |
9816 KB |
Output is correct |
55 |
Correct |
564 ms |
18980 KB |
Output is correct |
56 |
Correct |
649 ms |
19000 KB |
Output is correct |
57 |
Correct |
622 ms |
19004 KB |
Output is correct |
58 |
Correct |
485 ms |
19096 KB |
Output is correct |
59 |
Correct |
635 ms |
31568 KB |
Output is correct |
60 |
Correct |
600 ms |
31664 KB |
Output is correct |
61 |
Correct |
404 ms |
9560 KB |
Output is correct |
62 |
Correct |
554 ms |
9816 KB |
Output is correct |
63 |
Correct |
538 ms |
9816 KB |
Output is correct |
64 |
Correct |
570 ms |
9816 KB |
Output is correct |
65 |
Correct |
561 ms |
9816 KB |
Output is correct |
66 |
Correct |
556 ms |
9816 KB |
Output is correct |
67 |
Correct |
546 ms |
9816 KB |
Output is correct |
68 |
Correct |
526 ms |
9816 KB |
Output is correct |
69 |
Correct |
508 ms |
9560 KB |
Output is correct |
70 |
Correct |
534 ms |
9560 KB |
Output is correct |
71 |
Correct |
490 ms |
10328 KB |
Output is correct |
72 |
Correct |
589 ms |
9816 KB |
Output is correct |
73 |
Correct |
585 ms |
9816 KB |
Output is correct |
74 |
Correct |
550 ms |
9560 KB |
Output is correct |
75 |
Correct |
554 ms |
9560 KB |
Output is correct |
76 |
Correct |
522 ms |
10328 KB |
Output is correct |
77 |
Correct |
506 ms |
10596 KB |
Output is correct |
78 |
Correct |
504 ms |
10616 KB |
Output is correct |
79 |
Correct |
526 ms |
9816 KB |
Output is correct |
80 |
Correct |
578 ms |
9560 KB |
Output is correct |
81 |
Correct |
584 ms |
9560 KB |
Output is correct |
82 |
Correct |
569 ms |
9812 KB |
Output is correct |
83 |
Correct |
275 ms |
9560 KB |
Output is correct |
84 |
Correct |
528 ms |
9816 KB |
Output is correct |
85 |
Correct |
525 ms |
9816 KB |
Output is correct |
86 |
Correct |
591 ms |
9816 KB |
Output is correct |
87 |
Correct |
2 ms |
9560 KB |
Output is correct |
88 |
Correct |
414 ms |
18788 KB |
Output is correct |
89 |
Correct |
665 ms |
15696 KB |
Output is correct |
90 |
Correct |
601 ms |
15144 KB |
Output is correct |
91 |
Correct |
587 ms |
19284 KB |
Output is correct |
92 |
Correct |
603 ms |
19256 KB |
Output is correct |
93 |
Correct |
600 ms |
19448 KB |
Output is correct |
94 |
Correct |
700 ms |
19272 KB |
Output is correct |
95 |
Correct |
632 ms |
19272 KB |
Output is correct |
96 |
Correct |
570 ms |
14032 KB |
Output is correct |
97 |
Correct |
609 ms |
14020 KB |
Output is correct |
98 |
Correct |
576 ms |
27968 KB |
Output is correct |
99 |
Correct |
646 ms |
18996 KB |
Output is correct |
100 |
Incorrect |
643 ms |
17264 KB |
119th lines differ - on the 1st token, expected: '688149308', found: '513157708' |
101 |
Halted |
0 ms |
0 KB |
- |