#include "circuit.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
const int K=1<<18;
const ll mod=1e9+2022;
int n,m;
ll a[N],mul[N];
vector<int> adj[N];
struct segtree{
ll t[K],all[K];
bool lz[K];
void pushlz(int l,int r,int i){
if(!lz[i])return;
t[i]=(mod+all[i]-t[i])%mod;
if(l<r){
lz[i*2]^=true;
lz[i*2+1]^=true;
}
lz[i]=false;
}
void build(int l,int r,int i){
if(l==r){
t[i]=a[l]*mul[l];
all[i]=mul[l];
return;
}
int m=(l+r)/2;
build(l,m,i*2);
build(m+1,r,i*2+1);
t[i]=(t[i*2]+t[i*2+1])%mod;
all[i]=(all[i*2]+all[i*2+1])%mod;
}
void build(){
build(1,m,1);
}
void update(int l,int r,int i,int x,int y){
pushlz(l,r,i);
if(y<l||r<x)return;
if(x<=l&&r<=y)return lz[i]=true,pushlz(l,r,i),void();
int m=(l+r)/2;
update(l,m,i*2,x,y);
update(m+1,r,i*2+1,x,y);
t[i]=(t[i*2]+t[i*2+1])%mod;
}
void update(int x,int y){
update(1,m,1,x,y);
}
}s;
struct segtree2{
ll t[K];
void build(int l,int r,int i){
if(l==r)return void(t[i]=adj[l].size());
int m=(l+r)/2;
build(l,m,i*2);
build(m+1,r,i*2+1);
t[i]=(t[i*2]*t[i*2+1])%mod;
}
void build(){
build(1,n,1);
}
void update(int l,int r,int i,int x,int v){
if(x<l||r<x)return;
if(l==r)return void(t[i]=v);
int m=(l+r)/2;
update(l,m,i*2,x,v);
update(m+1,r,i*2+1,x,v);
t[i]=(t[i*2]*t[i*2+1])%mod;
}
void update(int x,int y){
update(1,n,1,x,y);
}
}s2;
void dfs(int u,int d=0){
if(u>n)return void(mul[u-n]=s2.t[1]);
s2.update(u,1);
for(auto v:adj[u])dfs(v,d+1);
s2.update(u,adj[u].size());
}
void init(int N,int M,vector<int> P,vector<int> A) {
n=N,m=M;
for(int i=1;i<=m;i++)a[i]=A[i-1];
for(int i=1;i<n+m;i++)adj[P[i]+1].emplace_back(i+1);
s2.build();
dfs(1);
s.build();
}
int count_ways(int L, int R) {
L-=n-1;
R-=n-1;
s.update(L,R);
return s.t[1];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2640 KB |
Output is correct |
2 |
Correct |
1 ms |
2640 KB |
Output is correct |
3 |
Correct |
1 ms |
2640 KB |
Output is correct |
4 |
Correct |
1 ms |
2640 KB |
Output is correct |
5 |
Correct |
1 ms |
2640 KB |
Output is correct |
6 |
Correct |
2 ms |
2640 KB |
Output is correct |
7 |
Correct |
1 ms |
2640 KB |
Output is correct |
8 |
Correct |
2 ms |
2752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2640 KB |
Output is correct |
2 |
Correct |
1 ms |
2640 KB |
Output is correct |
3 |
Correct |
2 ms |
2688 KB |
Output is correct |
4 |
Correct |
2 ms |
2712 KB |
Output is correct |
5 |
Correct |
2 ms |
2640 KB |
Output is correct |
6 |
Correct |
2 ms |
2768 KB |
Output is correct |
7 |
Correct |
2 ms |
2768 KB |
Output is correct |
8 |
Correct |
2 ms |
2768 KB |
Output is correct |
9 |
Correct |
2 ms |
2768 KB |
Output is correct |
10 |
Correct |
2 ms |
2768 KB |
Output is correct |
11 |
Correct |
2 ms |
2768 KB |
Output is correct |
12 |
Correct |
2 ms |
2768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2640 KB |
Output is correct |
2 |
Correct |
1 ms |
2640 KB |
Output is correct |
3 |
Correct |
1 ms |
2640 KB |
Output is correct |
4 |
Correct |
1 ms |
2640 KB |
Output is correct |
5 |
Correct |
1 ms |
2640 KB |
Output is correct |
6 |
Correct |
2 ms |
2640 KB |
Output is correct |
7 |
Correct |
1 ms |
2640 KB |
Output is correct |
8 |
Correct |
2 ms |
2752 KB |
Output is correct |
9 |
Correct |
2 ms |
2640 KB |
Output is correct |
10 |
Correct |
1 ms |
2640 KB |
Output is correct |
11 |
Correct |
2 ms |
2688 KB |
Output is correct |
12 |
Correct |
2 ms |
2712 KB |
Output is correct |
13 |
Correct |
2 ms |
2640 KB |
Output is correct |
14 |
Correct |
2 ms |
2768 KB |
Output is correct |
15 |
Correct |
2 ms |
2768 KB |
Output is correct |
16 |
Correct |
2 ms |
2768 KB |
Output is correct |
17 |
Correct |
2 ms |
2768 KB |
Output is correct |
18 |
Correct |
2 ms |
2768 KB |
Output is correct |
19 |
Correct |
2 ms |
2768 KB |
Output is correct |
20 |
Correct |
2 ms |
2768 KB |
Output is correct |
21 |
Correct |
2 ms |
2768 KB |
Output is correct |
22 |
Correct |
2 ms |
2640 KB |
Output is correct |
23 |
Correct |
2 ms |
2768 KB |
Output is correct |
24 |
Correct |
2 ms |
2768 KB |
Output is correct |
25 |
Correct |
2 ms |
2768 KB |
Output is correct |
26 |
Correct |
2 ms |
2768 KB |
Output is correct |
27 |
Correct |
2 ms |
2768 KB |
Output is correct |
28 |
Correct |
2 ms |
2768 KB |
Output is correct |
29 |
Correct |
1 ms |
2640 KB |
Output is correct |
30 |
Correct |
1 ms |
2640 KB |
Output is correct |
31 |
Correct |
2 ms |
2768 KB |
Output is correct |
32 |
Correct |
2 ms |
2768 KB |
Output is correct |
33 |
Correct |
2 ms |
2768 KB |
Output is correct |
34 |
Correct |
2 ms |
2768 KB |
Output is correct |
35 |
Correct |
1 ms |
2640 KB |
Output is correct |
36 |
Correct |
2 ms |
2768 KB |
Output is correct |
37 |
Correct |
2 ms |
2768 KB |
Output is correct |
38 |
Correct |
2 ms |
2768 KB |
Output is correct |
39 |
Correct |
2 ms |
2768 KB |
Output is correct |
40 |
Correct |
2 ms |
2768 KB |
Output is correct |
41 |
Correct |
2 ms |
2768 KB |
Output is correct |
42 |
Correct |
2 ms |
2640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
548 ms |
6516 KB |
Output is correct |
2 |
Correct |
628 ms |
10304 KB |
Output is correct |
3 |
Correct |
878 ms |
10348 KB |
Output is correct |
4 |
Correct |
790 ms |
10336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
548 ms |
6516 KB |
Output is correct |
2 |
Correct |
628 ms |
10304 KB |
Output is correct |
3 |
Correct |
878 ms |
10348 KB |
Output is correct |
4 |
Correct |
790 ms |
10336 KB |
Output is correct |
5 |
Correct |
501 ms |
6480 KB |
Output is correct |
6 |
Correct |
729 ms |
10372 KB |
Output is correct |
7 |
Correct |
813 ms |
10328 KB |
Output is correct |
8 |
Correct |
670 ms |
10308 KB |
Output is correct |
9 |
Correct |
307 ms |
2916 KB |
Output is correct |
10 |
Correct |
675 ms |
3104 KB |
Output is correct |
11 |
Correct |
548 ms |
3152 KB |
Output is correct |
12 |
Correct |
642 ms |
3152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2640 KB |
Output is correct |
2 |
Correct |
1 ms |
2640 KB |
Output is correct |
3 |
Correct |
2 ms |
2688 KB |
Output is correct |
4 |
Correct |
2 ms |
2712 KB |
Output is correct |
5 |
Correct |
2 ms |
2640 KB |
Output is correct |
6 |
Correct |
2 ms |
2768 KB |
Output is correct |
7 |
Correct |
2 ms |
2768 KB |
Output is correct |
8 |
Correct |
2 ms |
2768 KB |
Output is correct |
9 |
Correct |
2 ms |
2768 KB |
Output is correct |
10 |
Correct |
2 ms |
2768 KB |
Output is correct |
11 |
Correct |
2 ms |
2768 KB |
Output is correct |
12 |
Correct |
2 ms |
2768 KB |
Output is correct |
13 |
Correct |
548 ms |
6516 KB |
Output is correct |
14 |
Correct |
628 ms |
10304 KB |
Output is correct |
15 |
Correct |
878 ms |
10348 KB |
Output is correct |
16 |
Correct |
790 ms |
10336 KB |
Output is correct |
17 |
Correct |
501 ms |
6480 KB |
Output is correct |
18 |
Correct |
729 ms |
10372 KB |
Output is correct |
19 |
Correct |
813 ms |
10328 KB |
Output is correct |
20 |
Correct |
670 ms |
10308 KB |
Output is correct |
21 |
Correct |
307 ms |
2916 KB |
Output is correct |
22 |
Correct |
675 ms |
3104 KB |
Output is correct |
23 |
Correct |
548 ms |
3152 KB |
Output is correct |
24 |
Correct |
642 ms |
3152 KB |
Output is correct |
25 |
Correct |
706 ms |
15704 KB |
Output is correct |
26 |
Correct |
794 ms |
15828 KB |
Output is correct |
27 |
Correct |
731 ms |
15832 KB |
Output is correct |
28 |
Correct |
683 ms |
15840 KB |
Output is correct |
29 |
Correct |
656 ms |
23628 KB |
Output is correct |
30 |
Correct |
810 ms |
23564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2640 KB |
Output is correct |
2 |
Correct |
1 ms |
2640 KB |
Output is correct |
3 |
Correct |
1 ms |
2640 KB |
Output is correct |
4 |
Correct |
1 ms |
2640 KB |
Output is correct |
5 |
Correct |
1 ms |
2640 KB |
Output is correct |
6 |
Correct |
2 ms |
2640 KB |
Output is correct |
7 |
Correct |
1 ms |
2640 KB |
Output is correct |
8 |
Correct |
2 ms |
2752 KB |
Output is correct |
9 |
Correct |
2 ms |
2640 KB |
Output is correct |
10 |
Correct |
1 ms |
2640 KB |
Output is correct |
11 |
Correct |
2 ms |
2688 KB |
Output is correct |
12 |
Correct |
2 ms |
2712 KB |
Output is correct |
13 |
Correct |
2 ms |
2640 KB |
Output is correct |
14 |
Correct |
2 ms |
2768 KB |
Output is correct |
15 |
Correct |
2 ms |
2768 KB |
Output is correct |
16 |
Correct |
2 ms |
2768 KB |
Output is correct |
17 |
Correct |
2 ms |
2768 KB |
Output is correct |
18 |
Correct |
2 ms |
2768 KB |
Output is correct |
19 |
Correct |
2 ms |
2768 KB |
Output is correct |
20 |
Correct |
2 ms |
2768 KB |
Output is correct |
21 |
Correct |
2 ms |
2768 KB |
Output is correct |
22 |
Correct |
2 ms |
2640 KB |
Output is correct |
23 |
Correct |
2 ms |
2768 KB |
Output is correct |
24 |
Correct |
2 ms |
2768 KB |
Output is correct |
25 |
Correct |
2 ms |
2768 KB |
Output is correct |
26 |
Correct |
2 ms |
2768 KB |
Output is correct |
27 |
Correct |
2 ms |
2768 KB |
Output is correct |
28 |
Correct |
2 ms |
2768 KB |
Output is correct |
29 |
Correct |
1 ms |
2640 KB |
Output is correct |
30 |
Correct |
1 ms |
2640 KB |
Output is correct |
31 |
Correct |
2 ms |
2768 KB |
Output is correct |
32 |
Correct |
2 ms |
2768 KB |
Output is correct |
33 |
Correct |
2 ms |
2768 KB |
Output is correct |
34 |
Correct |
2 ms |
2768 KB |
Output is correct |
35 |
Correct |
1 ms |
2640 KB |
Output is correct |
36 |
Correct |
2 ms |
2768 KB |
Output is correct |
37 |
Correct |
2 ms |
2768 KB |
Output is correct |
38 |
Correct |
2 ms |
2768 KB |
Output is correct |
39 |
Correct |
2 ms |
2768 KB |
Output is correct |
40 |
Correct |
2 ms |
2768 KB |
Output is correct |
41 |
Correct |
2 ms |
2768 KB |
Output is correct |
42 |
Correct |
2 ms |
2640 KB |
Output is correct |
43 |
Correct |
587 ms |
3024 KB |
Output is correct |
44 |
Correct |
828 ms |
3024 KB |
Output is correct |
45 |
Correct |
693 ms |
3024 KB |
Output is correct |
46 |
Correct |
582 ms |
3408 KB |
Output is correct |
47 |
Correct |
670 ms |
3408 KB |
Output is correct |
48 |
Correct |
721 ms |
3408 KB |
Output is correct |
49 |
Correct |
852 ms |
3408 KB |
Output is correct |
50 |
Correct |
852 ms |
3408 KB |
Output is correct |
51 |
Correct |
552 ms |
3152 KB |
Output is correct |
52 |
Correct |
775 ms |
3152 KB |
Output is correct |
53 |
Correct |
541 ms |
3280 KB |
Output is correct |
54 |
Correct |
413 ms |
3408 KB |
Output is correct |
55 |
Correct |
623 ms |
3268 KB |
Output is correct |
56 |
Correct |
737 ms |
3152 KB |
Output is correct |
57 |
Correct |
665 ms |
3132 KB |
Output is correct |
58 |
Correct |
550 ms |
3792 KB |
Output is correct |
59 |
Correct |
580 ms |
3864 KB |
Output is correct |
60 |
Correct |
495 ms |
3860 KB |
Output is correct |
61 |
Correct |
810 ms |
3152 KB |
Output is correct |
62 |
Correct |
514 ms |
3024 KB |
Output is correct |
63 |
Correct |
831 ms |
3024 KB |
Output is correct |
64 |
Correct |
769 ms |
3024 KB |
Output is correct |
65 |
Correct |
442 ms |
2896 KB |
Output is correct |
66 |
Correct |
882 ms |
3152 KB |
Output is correct |
67 |
Correct |
761 ms |
3152 KB |
Output is correct |
68 |
Correct |
698 ms |
3152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2640 KB |
Output is correct |
2 |
Correct |
1 ms |
2640 KB |
Output is correct |
3 |
Correct |
1 ms |
2640 KB |
Output is correct |
4 |
Correct |
1 ms |
2640 KB |
Output is correct |
5 |
Correct |
1 ms |
2640 KB |
Output is correct |
6 |
Correct |
2 ms |
2640 KB |
Output is correct |
7 |
Correct |
1 ms |
2640 KB |
Output is correct |
8 |
Correct |
2 ms |
2752 KB |
Output is correct |
9 |
Correct |
2 ms |
2640 KB |
Output is correct |
10 |
Correct |
1 ms |
2640 KB |
Output is correct |
11 |
Correct |
2 ms |
2688 KB |
Output is correct |
12 |
Correct |
2 ms |
2712 KB |
Output is correct |
13 |
Correct |
2 ms |
2640 KB |
Output is correct |
14 |
Correct |
2 ms |
2768 KB |
Output is correct |
15 |
Correct |
2 ms |
2768 KB |
Output is correct |
16 |
Correct |
2 ms |
2768 KB |
Output is correct |
17 |
Correct |
2 ms |
2768 KB |
Output is correct |
18 |
Correct |
2 ms |
2768 KB |
Output is correct |
19 |
Correct |
2 ms |
2768 KB |
Output is correct |
20 |
Correct |
2 ms |
2768 KB |
Output is correct |
21 |
Correct |
2 ms |
2768 KB |
Output is correct |
22 |
Correct |
2 ms |
2640 KB |
Output is correct |
23 |
Correct |
2 ms |
2768 KB |
Output is correct |
24 |
Correct |
2 ms |
2768 KB |
Output is correct |
25 |
Correct |
2 ms |
2768 KB |
Output is correct |
26 |
Correct |
2 ms |
2768 KB |
Output is correct |
27 |
Correct |
2 ms |
2768 KB |
Output is correct |
28 |
Correct |
2 ms |
2768 KB |
Output is correct |
29 |
Correct |
1 ms |
2640 KB |
Output is correct |
30 |
Correct |
1 ms |
2640 KB |
Output is correct |
31 |
Correct |
2 ms |
2768 KB |
Output is correct |
32 |
Correct |
2 ms |
2768 KB |
Output is correct |
33 |
Correct |
2 ms |
2768 KB |
Output is correct |
34 |
Correct |
2 ms |
2768 KB |
Output is correct |
35 |
Correct |
1 ms |
2640 KB |
Output is correct |
36 |
Correct |
2 ms |
2768 KB |
Output is correct |
37 |
Correct |
2 ms |
2768 KB |
Output is correct |
38 |
Correct |
2 ms |
2768 KB |
Output is correct |
39 |
Correct |
2 ms |
2768 KB |
Output is correct |
40 |
Correct |
2 ms |
2768 KB |
Output is correct |
41 |
Correct |
2 ms |
2768 KB |
Output is correct |
42 |
Correct |
2 ms |
2640 KB |
Output is correct |
43 |
Correct |
548 ms |
6516 KB |
Output is correct |
44 |
Correct |
628 ms |
10304 KB |
Output is correct |
45 |
Correct |
878 ms |
10348 KB |
Output is correct |
46 |
Correct |
790 ms |
10336 KB |
Output is correct |
47 |
Correct |
501 ms |
6480 KB |
Output is correct |
48 |
Correct |
729 ms |
10372 KB |
Output is correct |
49 |
Correct |
813 ms |
10328 KB |
Output is correct |
50 |
Correct |
670 ms |
10308 KB |
Output is correct |
51 |
Correct |
307 ms |
2916 KB |
Output is correct |
52 |
Correct |
675 ms |
3104 KB |
Output is correct |
53 |
Correct |
548 ms |
3152 KB |
Output is correct |
54 |
Correct |
642 ms |
3152 KB |
Output is correct |
55 |
Correct |
706 ms |
15704 KB |
Output is correct |
56 |
Correct |
794 ms |
15828 KB |
Output is correct |
57 |
Correct |
731 ms |
15832 KB |
Output is correct |
58 |
Correct |
683 ms |
15840 KB |
Output is correct |
59 |
Correct |
656 ms |
23628 KB |
Output is correct |
60 |
Correct |
810 ms |
23564 KB |
Output is correct |
61 |
Correct |
587 ms |
3024 KB |
Output is correct |
62 |
Correct |
828 ms |
3024 KB |
Output is correct |
63 |
Correct |
693 ms |
3024 KB |
Output is correct |
64 |
Correct |
582 ms |
3408 KB |
Output is correct |
65 |
Correct |
670 ms |
3408 KB |
Output is correct |
66 |
Correct |
721 ms |
3408 KB |
Output is correct |
67 |
Correct |
852 ms |
3408 KB |
Output is correct |
68 |
Correct |
852 ms |
3408 KB |
Output is correct |
69 |
Correct |
552 ms |
3152 KB |
Output is correct |
70 |
Correct |
775 ms |
3152 KB |
Output is correct |
71 |
Correct |
541 ms |
3280 KB |
Output is correct |
72 |
Correct |
413 ms |
3408 KB |
Output is correct |
73 |
Correct |
623 ms |
3268 KB |
Output is correct |
74 |
Correct |
737 ms |
3152 KB |
Output is correct |
75 |
Correct |
665 ms |
3132 KB |
Output is correct |
76 |
Correct |
550 ms |
3792 KB |
Output is correct |
77 |
Correct |
580 ms |
3864 KB |
Output is correct |
78 |
Correct |
495 ms |
3860 KB |
Output is correct |
79 |
Correct |
810 ms |
3152 KB |
Output is correct |
80 |
Correct |
514 ms |
3024 KB |
Output is correct |
81 |
Correct |
831 ms |
3024 KB |
Output is correct |
82 |
Correct |
769 ms |
3024 KB |
Output is correct |
83 |
Correct |
442 ms |
2896 KB |
Output is correct |
84 |
Correct |
882 ms |
3152 KB |
Output is correct |
85 |
Correct |
761 ms |
3152 KB |
Output is correct |
86 |
Correct |
698 ms |
3152 KB |
Output is correct |
87 |
Correct |
1 ms |
2640 KB |
Output is correct |
88 |
Correct |
420 ms |
15008 KB |
Output is correct |
89 |
Correct |
778 ms |
11364 KB |
Output is correct |
90 |
Correct |
766 ms |
11080 KB |
Output is correct |
91 |
Correct |
850 ms |
15944 KB |
Output is correct |
92 |
Correct |
751 ms |
15944 KB |
Output is correct |
93 |
Correct |
872 ms |
15860 KB |
Output is correct |
94 |
Correct |
863 ms |
15864 KB |
Output is correct |
95 |
Correct |
877 ms |
15868 KB |
Output is correct |
96 |
Correct |
564 ms |
10352 KB |
Output is correct |
97 |
Correct |
753 ms |
10304 KB |
Output is correct |
98 |
Correct |
857 ms |
16348 KB |
Output is correct |
99 |
Correct |
815 ms |
15744 KB |
Output is correct |
100 |
Correct |
730 ms |
12884 KB |
Output is correct |
101 |
Correct |
911 ms |
11768 KB |
Output is correct |
102 |
Correct |
810 ms |
10324 KB |
Output is correct |
103 |
Correct |
587 ms |
23640 KB |
Output is correct |
104 |
Correct |
755 ms |
24152 KB |
Output is correct |
105 |
Correct |
642 ms |
24188 KB |
Output is correct |
106 |
Correct |
728 ms |
12744 KB |
Output is correct |
107 |
Correct |
789 ms |
11396 KB |
Output is correct |
108 |
Correct |
701 ms |
10988 KB |
Output is correct |
109 |
Correct |
651 ms |
10352 KB |
Output is correct |