#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],id;
vector <int> ke[200001],d[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)
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];
}
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;
}
for (int v:ke[u])
d[u].push_back(1LL*(d[u].empty()?1:d[u].back())*c[v]%mod);
int cur=1;
for (int i=ke[u].size()-1;i>=0;i--){
dfs2(ke[u][i],1LL*cur*(i?d[u][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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
13656 KB |
Output is correct |
2 |
Correct |
2 ms |
13748 KB |
Output is correct |
3 |
Correct |
3 ms |
13736 KB |
Output is correct |
4 |
Correct |
3 ms |
13656 KB |
Output is correct |
5 |
Correct |
3 ms |
13656 KB |
Output is correct |
6 |
Correct |
3 ms |
13656 KB |
Output is correct |
7 |
Correct |
3 ms |
13656 KB |
Output is correct |
8 |
Correct |
3 ms |
13684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
13656 KB |
Output is correct |
2 |
Correct |
2 ms |
13656 KB |
Output is correct |
3 |
Correct |
3 ms |
13680 KB |
Output is correct |
4 |
Correct |
3 ms |
13656 KB |
Output is correct |
5 |
Correct |
3 ms |
13656 KB |
Output is correct |
6 |
Correct |
3 ms |
13656 KB |
Output is correct |
7 |
Correct |
3 ms |
13656 KB |
Output is correct |
8 |
Correct |
3 ms |
13656 KB |
Output is correct |
9 |
Correct |
3 ms |
13656 KB |
Output is correct |
10 |
Correct |
4 ms |
13912 KB |
Output is correct |
11 |
Correct |
3 ms |
13912 KB |
Output is correct |
12 |
Correct |
3 ms |
13656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
13656 KB |
Output is correct |
2 |
Correct |
2 ms |
13748 KB |
Output is correct |
3 |
Correct |
3 ms |
13736 KB |
Output is correct |
4 |
Correct |
3 ms |
13656 KB |
Output is correct |
5 |
Correct |
3 ms |
13656 KB |
Output is correct |
6 |
Correct |
3 ms |
13656 KB |
Output is correct |
7 |
Correct |
3 ms |
13656 KB |
Output is correct |
8 |
Correct |
3 ms |
13684 KB |
Output is correct |
9 |
Correct |
2 ms |
13656 KB |
Output is correct |
10 |
Correct |
2 ms |
13656 KB |
Output is correct |
11 |
Correct |
3 ms |
13680 KB |
Output is correct |
12 |
Correct |
3 ms |
13656 KB |
Output is correct |
13 |
Correct |
3 ms |
13656 KB |
Output is correct |
14 |
Correct |
3 ms |
13656 KB |
Output is correct |
15 |
Correct |
3 ms |
13656 KB |
Output is correct |
16 |
Correct |
3 ms |
13656 KB |
Output is correct |
17 |
Correct |
3 ms |
13656 KB |
Output is correct |
18 |
Correct |
4 ms |
13912 KB |
Output is correct |
19 |
Correct |
3 ms |
13912 KB |
Output is correct |
20 |
Correct |
3 ms |
13656 KB |
Output is correct |
21 |
Correct |
3 ms |
13656 KB |
Output is correct |
22 |
Correct |
3 ms |
13756 KB |
Output is correct |
23 |
Correct |
3 ms |
13656 KB |
Output is correct |
24 |
Correct |
3 ms |
13656 KB |
Output is correct |
25 |
Correct |
3 ms |
13656 KB |
Output is correct |
26 |
Correct |
3 ms |
13656 KB |
Output is correct |
27 |
Correct |
3 ms |
13908 KB |
Output is correct |
28 |
Correct |
3 ms |
13656 KB |
Output is correct |
29 |
Correct |
3 ms |
13656 KB |
Output is correct |
30 |
Correct |
3 ms |
13656 KB |
Output is correct |
31 |
Correct |
3 ms |
13912 KB |
Output is correct |
32 |
Correct |
3 ms |
13656 KB |
Output is correct |
33 |
Correct |
3 ms |
13908 KB |
Output is correct |
34 |
Correct |
3 ms |
13656 KB |
Output is correct |
35 |
Correct |
3 ms |
13656 KB |
Output is correct |
36 |
Correct |
3 ms |
13912 KB |
Output is correct |
37 |
Correct |
3 ms |
13912 KB |
Output is correct |
38 |
Correct |
3 ms |
13912 KB |
Output is correct |
39 |
Correct |
3 ms |
13656 KB |
Output is correct |
40 |
Correct |
3 ms |
13656 KB |
Output is correct |
41 |
Correct |
3 ms |
13656 KB |
Output is correct |
42 |
Correct |
3 ms |
13656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
406 ms |
18796 KB |
Output is correct |
2 |
Correct |
545 ms |
21328 KB |
Output is correct |
3 |
Correct |
531 ms |
21448 KB |
Output is correct |
4 |
Correct |
557 ms |
21472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
406 ms |
18796 KB |
Output is correct |
2 |
Correct |
545 ms |
21328 KB |
Output is correct |
3 |
Correct |
531 ms |
21448 KB |
Output is correct |
4 |
Correct |
557 ms |
21472 KB |
Output is correct |
5 |
Correct |
432 ms |
18500 KB |
Output is correct |
6 |
Correct |
590 ms |
21584 KB |
Output is correct |
7 |
Correct |
590 ms |
21328 KB |
Output is correct |
8 |
Correct |
540 ms |
21328 KB |
Output is correct |
9 |
Correct |
266 ms |
13912 KB |
Output is correct |
10 |
Correct |
544 ms |
13912 KB |
Output is correct |
11 |
Correct |
581 ms |
13912 KB |
Output is correct |
12 |
Correct |
523 ms |
13912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
13656 KB |
Output is correct |
2 |
Correct |
2 ms |
13656 KB |
Output is correct |
3 |
Correct |
3 ms |
13680 KB |
Output is correct |
4 |
Correct |
3 ms |
13656 KB |
Output is correct |
5 |
Correct |
3 ms |
13656 KB |
Output is correct |
6 |
Correct |
3 ms |
13656 KB |
Output is correct |
7 |
Correct |
3 ms |
13656 KB |
Output is correct |
8 |
Correct |
3 ms |
13656 KB |
Output is correct |
9 |
Correct |
3 ms |
13656 KB |
Output is correct |
10 |
Correct |
4 ms |
13912 KB |
Output is correct |
11 |
Correct |
3 ms |
13912 KB |
Output is correct |
12 |
Correct |
3 ms |
13656 KB |
Output is correct |
13 |
Correct |
406 ms |
18796 KB |
Output is correct |
14 |
Correct |
545 ms |
21328 KB |
Output is correct |
15 |
Correct |
531 ms |
21448 KB |
Output is correct |
16 |
Correct |
557 ms |
21472 KB |
Output is correct |
17 |
Correct |
432 ms |
18500 KB |
Output is correct |
18 |
Correct |
590 ms |
21584 KB |
Output is correct |
19 |
Correct |
590 ms |
21328 KB |
Output is correct |
20 |
Correct |
540 ms |
21328 KB |
Output is correct |
21 |
Correct |
266 ms |
13912 KB |
Output is correct |
22 |
Correct |
544 ms |
13912 KB |
Output is correct |
23 |
Correct |
581 ms |
13912 KB |
Output is correct |
24 |
Correct |
523 ms |
13912 KB |
Output is correct |
25 |
Correct |
611 ms |
26284 KB |
Output is correct |
26 |
Correct |
633 ms |
26340 KB |
Output is correct |
27 |
Correct |
610 ms |
26620 KB |
Output is correct |
28 |
Correct |
503 ms |
26440 KB |
Output is correct |
29 |
Correct |
617 ms |
37196 KB |
Output is correct |
30 |
Correct |
595 ms |
37412 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
13656 KB |
Output is correct |
2 |
Correct |
2 ms |
13748 KB |
Output is correct |
3 |
Correct |
3 ms |
13736 KB |
Output is correct |
4 |
Correct |
3 ms |
13656 KB |
Output is correct |
5 |
Correct |
3 ms |
13656 KB |
Output is correct |
6 |
Correct |
3 ms |
13656 KB |
Output is correct |
7 |
Correct |
3 ms |
13656 KB |
Output is correct |
8 |
Correct |
3 ms |
13684 KB |
Output is correct |
9 |
Correct |
2 ms |
13656 KB |
Output is correct |
10 |
Correct |
2 ms |
13656 KB |
Output is correct |
11 |
Correct |
3 ms |
13680 KB |
Output is correct |
12 |
Correct |
3 ms |
13656 KB |
Output is correct |
13 |
Correct |
3 ms |
13656 KB |
Output is correct |
14 |
Correct |
3 ms |
13656 KB |
Output is correct |
15 |
Correct |
3 ms |
13656 KB |
Output is correct |
16 |
Correct |
3 ms |
13656 KB |
Output is correct |
17 |
Correct |
3 ms |
13656 KB |
Output is correct |
18 |
Correct |
4 ms |
13912 KB |
Output is correct |
19 |
Correct |
3 ms |
13912 KB |
Output is correct |
20 |
Correct |
3 ms |
13656 KB |
Output is correct |
21 |
Correct |
3 ms |
13656 KB |
Output is correct |
22 |
Correct |
3 ms |
13756 KB |
Output is correct |
23 |
Correct |
3 ms |
13656 KB |
Output is correct |
24 |
Correct |
3 ms |
13656 KB |
Output is correct |
25 |
Correct |
3 ms |
13656 KB |
Output is correct |
26 |
Correct |
3 ms |
13656 KB |
Output is correct |
27 |
Correct |
3 ms |
13908 KB |
Output is correct |
28 |
Correct |
3 ms |
13656 KB |
Output is correct |
29 |
Correct |
3 ms |
13656 KB |
Output is correct |
30 |
Correct |
3 ms |
13656 KB |
Output is correct |
31 |
Correct |
3 ms |
13912 KB |
Output is correct |
32 |
Correct |
3 ms |
13656 KB |
Output is correct |
33 |
Correct |
3 ms |
13908 KB |
Output is correct |
34 |
Correct |
3 ms |
13656 KB |
Output is correct |
35 |
Correct |
3 ms |
13656 KB |
Output is correct |
36 |
Correct |
3 ms |
13912 KB |
Output is correct |
37 |
Correct |
3 ms |
13912 KB |
Output is correct |
38 |
Correct |
3 ms |
13912 KB |
Output is correct |
39 |
Correct |
3 ms |
13656 KB |
Output is correct |
40 |
Correct |
3 ms |
13656 KB |
Output is correct |
41 |
Correct |
3 ms |
13656 KB |
Output is correct |
42 |
Correct |
3 ms |
13656 KB |
Output is correct |
43 |
Correct |
387 ms |
13912 KB |
Output is correct |
44 |
Correct |
544 ms |
13912 KB |
Output is correct |
45 |
Correct |
566 ms |
13912 KB |
Output is correct |
46 |
Correct |
522 ms |
14168 KB |
Output is correct |
47 |
Correct |
522 ms |
14168 KB |
Output is correct |
48 |
Correct |
534 ms |
14168 KB |
Output is correct |
49 |
Correct |
540 ms |
14168 KB |
Output is correct |
50 |
Correct |
545 ms |
14168 KB |
Output is correct |
51 |
Correct |
526 ms |
13656 KB |
Output is correct |
52 |
Correct |
524 ms |
13656 KB |
Output is correct |
53 |
Correct |
495 ms |
14424 KB |
Output is correct |
54 |
Correct |
495 ms |
14168 KB |
Output is correct |
55 |
Correct |
520 ms |
13912 KB |
Output is correct |
56 |
Correct |
529 ms |
13912 KB |
Output is correct |
57 |
Correct |
499 ms |
13656 KB |
Output is correct |
58 |
Correct |
508 ms |
14680 KB |
Output is correct |
59 |
Correct |
512 ms |
14680 KB |
Output is correct |
60 |
Correct |
519 ms |
14680 KB |
Output is correct |
61 |
Correct |
538 ms |
14168 KB |
Output is correct |
62 |
Correct |
538 ms |
13912 KB |
Output is correct |
63 |
Correct |
545 ms |
13912 KB |
Output is correct |
64 |
Correct |
502 ms |
13656 KB |
Output is correct |
65 |
Correct |
243 ms |
13912 KB |
Output is correct |
66 |
Correct |
518 ms |
13912 KB |
Output is correct |
67 |
Correct |
538 ms |
14164 KB |
Output is correct |
68 |
Correct |
520 ms |
13912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
13656 KB |
Output is correct |
2 |
Correct |
2 ms |
13748 KB |
Output is correct |
3 |
Correct |
3 ms |
13736 KB |
Output is correct |
4 |
Correct |
3 ms |
13656 KB |
Output is correct |
5 |
Correct |
3 ms |
13656 KB |
Output is correct |
6 |
Correct |
3 ms |
13656 KB |
Output is correct |
7 |
Correct |
3 ms |
13656 KB |
Output is correct |
8 |
Correct |
3 ms |
13684 KB |
Output is correct |
9 |
Correct |
2 ms |
13656 KB |
Output is correct |
10 |
Correct |
2 ms |
13656 KB |
Output is correct |
11 |
Correct |
3 ms |
13680 KB |
Output is correct |
12 |
Correct |
3 ms |
13656 KB |
Output is correct |
13 |
Correct |
3 ms |
13656 KB |
Output is correct |
14 |
Correct |
3 ms |
13656 KB |
Output is correct |
15 |
Correct |
3 ms |
13656 KB |
Output is correct |
16 |
Correct |
3 ms |
13656 KB |
Output is correct |
17 |
Correct |
3 ms |
13656 KB |
Output is correct |
18 |
Correct |
4 ms |
13912 KB |
Output is correct |
19 |
Correct |
3 ms |
13912 KB |
Output is correct |
20 |
Correct |
3 ms |
13656 KB |
Output is correct |
21 |
Correct |
3 ms |
13656 KB |
Output is correct |
22 |
Correct |
3 ms |
13756 KB |
Output is correct |
23 |
Correct |
3 ms |
13656 KB |
Output is correct |
24 |
Correct |
3 ms |
13656 KB |
Output is correct |
25 |
Correct |
3 ms |
13656 KB |
Output is correct |
26 |
Correct |
3 ms |
13656 KB |
Output is correct |
27 |
Correct |
3 ms |
13908 KB |
Output is correct |
28 |
Correct |
3 ms |
13656 KB |
Output is correct |
29 |
Correct |
3 ms |
13656 KB |
Output is correct |
30 |
Correct |
3 ms |
13656 KB |
Output is correct |
31 |
Correct |
3 ms |
13912 KB |
Output is correct |
32 |
Correct |
3 ms |
13656 KB |
Output is correct |
33 |
Correct |
3 ms |
13908 KB |
Output is correct |
34 |
Correct |
3 ms |
13656 KB |
Output is correct |
35 |
Correct |
3 ms |
13656 KB |
Output is correct |
36 |
Correct |
3 ms |
13912 KB |
Output is correct |
37 |
Correct |
3 ms |
13912 KB |
Output is correct |
38 |
Correct |
3 ms |
13912 KB |
Output is correct |
39 |
Correct |
3 ms |
13656 KB |
Output is correct |
40 |
Correct |
3 ms |
13656 KB |
Output is correct |
41 |
Correct |
3 ms |
13656 KB |
Output is correct |
42 |
Correct |
3 ms |
13656 KB |
Output is correct |
43 |
Correct |
406 ms |
18796 KB |
Output is correct |
44 |
Correct |
545 ms |
21328 KB |
Output is correct |
45 |
Correct |
531 ms |
21448 KB |
Output is correct |
46 |
Correct |
557 ms |
21472 KB |
Output is correct |
47 |
Correct |
432 ms |
18500 KB |
Output is correct |
48 |
Correct |
590 ms |
21584 KB |
Output is correct |
49 |
Correct |
590 ms |
21328 KB |
Output is correct |
50 |
Correct |
540 ms |
21328 KB |
Output is correct |
51 |
Correct |
266 ms |
13912 KB |
Output is correct |
52 |
Correct |
544 ms |
13912 KB |
Output is correct |
53 |
Correct |
581 ms |
13912 KB |
Output is correct |
54 |
Correct |
523 ms |
13912 KB |
Output is correct |
55 |
Correct |
611 ms |
26284 KB |
Output is correct |
56 |
Correct |
633 ms |
26340 KB |
Output is correct |
57 |
Correct |
610 ms |
26620 KB |
Output is correct |
58 |
Correct |
503 ms |
26440 KB |
Output is correct |
59 |
Correct |
617 ms |
37196 KB |
Output is correct |
60 |
Correct |
595 ms |
37412 KB |
Output is correct |
61 |
Correct |
387 ms |
13912 KB |
Output is correct |
62 |
Correct |
544 ms |
13912 KB |
Output is correct |
63 |
Correct |
566 ms |
13912 KB |
Output is correct |
64 |
Correct |
522 ms |
14168 KB |
Output is correct |
65 |
Correct |
522 ms |
14168 KB |
Output is correct |
66 |
Correct |
534 ms |
14168 KB |
Output is correct |
67 |
Correct |
540 ms |
14168 KB |
Output is correct |
68 |
Correct |
545 ms |
14168 KB |
Output is correct |
69 |
Correct |
526 ms |
13656 KB |
Output is correct |
70 |
Correct |
524 ms |
13656 KB |
Output is correct |
71 |
Correct |
495 ms |
14424 KB |
Output is correct |
72 |
Correct |
495 ms |
14168 KB |
Output is correct |
73 |
Correct |
520 ms |
13912 KB |
Output is correct |
74 |
Correct |
529 ms |
13912 KB |
Output is correct |
75 |
Correct |
499 ms |
13656 KB |
Output is correct |
76 |
Correct |
508 ms |
14680 KB |
Output is correct |
77 |
Correct |
512 ms |
14680 KB |
Output is correct |
78 |
Correct |
519 ms |
14680 KB |
Output is correct |
79 |
Correct |
538 ms |
14168 KB |
Output is correct |
80 |
Correct |
538 ms |
13912 KB |
Output is correct |
81 |
Correct |
545 ms |
13912 KB |
Output is correct |
82 |
Correct |
502 ms |
13656 KB |
Output is correct |
83 |
Correct |
243 ms |
13912 KB |
Output is correct |
84 |
Correct |
518 ms |
13912 KB |
Output is correct |
85 |
Correct |
538 ms |
14164 KB |
Output is correct |
86 |
Correct |
520 ms |
13912 KB |
Output is correct |
87 |
Correct |
2 ms |
13656 KB |
Output is correct |
88 |
Correct |
348 ms |
25640 KB |
Output is correct |
89 |
Correct |
557 ms |
21968 KB |
Output is correct |
90 |
Correct |
597 ms |
21368 KB |
Output is correct |
91 |
Correct |
594 ms |
26636 KB |
Output is correct |
92 |
Correct |
690 ms |
26436 KB |
Output is correct |
93 |
Correct |
645 ms |
26448 KB |
Output is correct |
94 |
Correct |
626 ms |
26504 KB |
Output is correct |
95 |
Correct |
588 ms |
26440 KB |
Output is correct |
96 |
Correct |
585 ms |
18260 KB |
Output is correct |
97 |
Correct |
602 ms |
18128 KB |
Output is correct |
98 |
Correct |
557 ms |
33604 KB |
Output is correct |
99 |
Correct |
615 ms |
26460 KB |
Output is correct |
100 |
Incorrect |
616 ms |
23076 KB |
119th lines differ - on the 1st token, expected: '688149308', found: '513157708' |
101 |
Halted |
0 ms |
0 KB |
- |