#include "circuit.h"
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define f first
#define s second
using namespace std;
const ll mod=1e9+2022;
const ll N=2e5+9;
ll n, m, a[N], pw[N], cnt[N], ans=0;
vector<ll> v[N], pre[N], suf[N];
void dfs(ll x){
if (x>=n){
pw[x]=1;
return;
}
pw[x]=v[x].size();
for (ll i: v[x]){
dfs(i);
pw[x]=pw[x]*pw[i]%mod;
}
}
void dfs2(ll x, ll now=1){
if (x>=n){
cnt[x]=now;
return;
}
ll sz=v[x].size();
pre[x].resize(sz);
pre[x][0]=pw[v[x][0]];
for (int i=1; i<sz; i++) pre[x][i]=pre[x][i-1]*pw[v[x][i]]%mod;
suf[x].resize(sz);
suf[x][sz-1]=pw[v[x][sz-1]];
for (int i=sz-2; i>=0; i--) suf[x][i]=suf[x][i+1]*pw[v[x][i]]%mod;
for (int i=0; i<sz; i++){
ll tmp=now;
if (i) tmp=tmp*pre[x][i-1]%mod;
if (i<sz-1) tmp=tmp*suf[x][i+1]%mod;
dfs2(v[x][i], tmp);
}
}
void init(int N, int M, vector<int> P, vector<int> A){
n=N, m=M;
for (int i=1; i<n+m; i++) v[P[i]].push_back(i);
for (int i=0; i<m; i++) a[i+n]=A[i];
dfs(0);
dfs2(0);
for (int i=n; i<n+m; i++){
if (a[i]) ans=(ans+cnt[i])%mod;
}
}
int count_ways(int L, int R){
for (int i=L; i<=R; i++){
a[i]^=1;
if (a[i]) ans=(ans+cnt[i])%mod;
else ans=(ans-cnt[i]+mod)%mod;
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14288 KB |
Output is correct |
2 |
Correct |
8 ms |
14288 KB |
Output is correct |
3 |
Correct |
8 ms |
14416 KB |
Output is correct |
4 |
Correct |
7 ms |
14416 KB |
Output is correct |
5 |
Correct |
7 ms |
14416 KB |
Output is correct |
6 |
Correct |
9 ms |
14360 KB |
Output is correct |
7 |
Correct |
8 ms |
14376 KB |
Output is correct |
8 |
Correct |
8 ms |
14416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14416 KB |
Output is correct |
2 |
Correct |
7 ms |
14416 KB |
Output is correct |
3 |
Correct |
7 ms |
14416 KB |
Output is correct |
4 |
Correct |
8 ms |
14376 KB |
Output is correct |
5 |
Correct |
8 ms |
14436 KB |
Output is correct |
6 |
Correct |
8 ms |
14416 KB |
Output is correct |
7 |
Correct |
9 ms |
14484 KB |
Output is correct |
8 |
Correct |
8 ms |
14544 KB |
Output is correct |
9 |
Correct |
8 ms |
14544 KB |
Output is correct |
10 |
Correct |
8 ms |
14544 KB |
Output is correct |
11 |
Correct |
8 ms |
14548 KB |
Output is correct |
12 |
Correct |
8 ms |
14416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14288 KB |
Output is correct |
2 |
Correct |
8 ms |
14288 KB |
Output is correct |
3 |
Correct |
8 ms |
14416 KB |
Output is correct |
4 |
Correct |
7 ms |
14416 KB |
Output is correct |
5 |
Correct |
7 ms |
14416 KB |
Output is correct |
6 |
Correct |
9 ms |
14360 KB |
Output is correct |
7 |
Correct |
8 ms |
14376 KB |
Output is correct |
8 |
Correct |
8 ms |
14416 KB |
Output is correct |
9 |
Correct |
7 ms |
14416 KB |
Output is correct |
10 |
Correct |
7 ms |
14416 KB |
Output is correct |
11 |
Correct |
7 ms |
14416 KB |
Output is correct |
12 |
Correct |
8 ms |
14376 KB |
Output is correct |
13 |
Correct |
8 ms |
14436 KB |
Output is correct |
14 |
Correct |
8 ms |
14416 KB |
Output is correct |
15 |
Correct |
9 ms |
14484 KB |
Output is correct |
16 |
Correct |
8 ms |
14544 KB |
Output is correct |
17 |
Correct |
8 ms |
14544 KB |
Output is correct |
18 |
Correct |
8 ms |
14544 KB |
Output is correct |
19 |
Correct |
8 ms |
14548 KB |
Output is correct |
20 |
Correct |
8 ms |
14416 KB |
Output is correct |
21 |
Correct |
8 ms |
14456 KB |
Output is correct |
22 |
Correct |
8 ms |
14416 KB |
Output is correct |
23 |
Correct |
8 ms |
14416 KB |
Output is correct |
24 |
Correct |
8 ms |
14544 KB |
Output is correct |
25 |
Correct |
8 ms |
14544 KB |
Output is correct |
26 |
Correct |
8 ms |
14544 KB |
Output is correct |
27 |
Correct |
8 ms |
14544 KB |
Output is correct |
28 |
Correct |
8 ms |
14544 KB |
Output is correct |
29 |
Correct |
8 ms |
14416 KB |
Output is correct |
30 |
Correct |
8 ms |
14416 KB |
Output is correct |
31 |
Correct |
8 ms |
14544 KB |
Output is correct |
32 |
Correct |
8 ms |
14492 KB |
Output is correct |
33 |
Correct |
8 ms |
14416 KB |
Output is correct |
34 |
Correct |
8 ms |
14376 KB |
Output is correct |
35 |
Correct |
9 ms |
14416 KB |
Output is correct |
36 |
Correct |
8 ms |
14544 KB |
Output is correct |
37 |
Correct |
8 ms |
14672 KB |
Output is correct |
38 |
Correct |
11 ms |
14672 KB |
Output is correct |
39 |
Correct |
9 ms |
14416 KB |
Output is correct |
40 |
Correct |
8 ms |
14416 KB |
Output is correct |
41 |
Correct |
10 ms |
14416 KB |
Output is correct |
42 |
Correct |
10 ms |
14416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
477 ms |
19256 KB |
Output is correct |
2 |
Correct |
708 ms |
24136 KB |
Output is correct |
3 |
Correct |
712 ms |
24108 KB |
Output is correct |
4 |
Correct |
723 ms |
24136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
477 ms |
19256 KB |
Output is correct |
2 |
Correct |
708 ms |
24136 KB |
Output is correct |
3 |
Correct |
712 ms |
24108 KB |
Output is correct |
4 |
Correct |
723 ms |
24136 KB |
Output is correct |
5 |
Execution timed out |
3077 ms |
19188 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14416 KB |
Output is correct |
2 |
Correct |
7 ms |
14416 KB |
Output is correct |
3 |
Correct |
7 ms |
14416 KB |
Output is correct |
4 |
Correct |
8 ms |
14376 KB |
Output is correct |
5 |
Correct |
8 ms |
14436 KB |
Output is correct |
6 |
Correct |
8 ms |
14416 KB |
Output is correct |
7 |
Correct |
9 ms |
14484 KB |
Output is correct |
8 |
Correct |
8 ms |
14544 KB |
Output is correct |
9 |
Correct |
8 ms |
14544 KB |
Output is correct |
10 |
Correct |
8 ms |
14544 KB |
Output is correct |
11 |
Correct |
8 ms |
14548 KB |
Output is correct |
12 |
Correct |
8 ms |
14416 KB |
Output is correct |
13 |
Correct |
477 ms |
19256 KB |
Output is correct |
14 |
Correct |
708 ms |
24136 KB |
Output is correct |
15 |
Correct |
712 ms |
24108 KB |
Output is correct |
16 |
Correct |
723 ms |
24136 KB |
Output is correct |
17 |
Execution timed out |
3077 ms |
19188 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14288 KB |
Output is correct |
2 |
Correct |
8 ms |
14288 KB |
Output is correct |
3 |
Correct |
8 ms |
14416 KB |
Output is correct |
4 |
Correct |
7 ms |
14416 KB |
Output is correct |
5 |
Correct |
7 ms |
14416 KB |
Output is correct |
6 |
Correct |
9 ms |
14360 KB |
Output is correct |
7 |
Correct |
8 ms |
14376 KB |
Output is correct |
8 |
Correct |
8 ms |
14416 KB |
Output is correct |
9 |
Correct |
7 ms |
14416 KB |
Output is correct |
10 |
Correct |
7 ms |
14416 KB |
Output is correct |
11 |
Correct |
7 ms |
14416 KB |
Output is correct |
12 |
Correct |
8 ms |
14376 KB |
Output is correct |
13 |
Correct |
8 ms |
14436 KB |
Output is correct |
14 |
Correct |
8 ms |
14416 KB |
Output is correct |
15 |
Correct |
9 ms |
14484 KB |
Output is correct |
16 |
Correct |
8 ms |
14544 KB |
Output is correct |
17 |
Correct |
8 ms |
14544 KB |
Output is correct |
18 |
Correct |
8 ms |
14544 KB |
Output is correct |
19 |
Correct |
8 ms |
14548 KB |
Output is correct |
20 |
Correct |
8 ms |
14416 KB |
Output is correct |
21 |
Correct |
8 ms |
14456 KB |
Output is correct |
22 |
Correct |
8 ms |
14416 KB |
Output is correct |
23 |
Correct |
8 ms |
14416 KB |
Output is correct |
24 |
Correct |
8 ms |
14544 KB |
Output is correct |
25 |
Correct |
8 ms |
14544 KB |
Output is correct |
26 |
Correct |
8 ms |
14544 KB |
Output is correct |
27 |
Correct |
8 ms |
14544 KB |
Output is correct |
28 |
Correct |
8 ms |
14544 KB |
Output is correct |
29 |
Correct |
8 ms |
14416 KB |
Output is correct |
30 |
Correct |
8 ms |
14416 KB |
Output is correct |
31 |
Correct |
8 ms |
14544 KB |
Output is correct |
32 |
Correct |
8 ms |
14492 KB |
Output is correct |
33 |
Correct |
8 ms |
14416 KB |
Output is correct |
34 |
Correct |
8 ms |
14376 KB |
Output is correct |
35 |
Correct |
9 ms |
14416 KB |
Output is correct |
36 |
Correct |
8 ms |
14544 KB |
Output is correct |
37 |
Correct |
8 ms |
14672 KB |
Output is correct |
38 |
Correct |
11 ms |
14672 KB |
Output is correct |
39 |
Correct |
9 ms |
14416 KB |
Output is correct |
40 |
Correct |
8 ms |
14416 KB |
Output is correct |
41 |
Correct |
10 ms |
14416 KB |
Output is correct |
42 |
Correct |
10 ms |
14416 KB |
Output is correct |
43 |
Correct |
902 ms |
14800 KB |
Output is correct |
44 |
Correct |
1233 ms |
14928 KB |
Output is correct |
45 |
Correct |
1313 ms |
14800 KB |
Output is correct |
46 |
Correct |
687 ms |
15184 KB |
Output is correct |
47 |
Correct |
1631 ms |
15180 KB |
Output is correct |
48 |
Correct |
1566 ms |
15184 KB |
Output is correct |
49 |
Correct |
1569 ms |
15184 KB |
Output is correct |
50 |
Correct |
2860 ms |
15184 KB |
Output is correct |
51 |
Execution timed out |
3025 ms |
14672 KB |
Time limit exceeded |
52 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14288 KB |
Output is correct |
2 |
Correct |
8 ms |
14288 KB |
Output is correct |
3 |
Correct |
8 ms |
14416 KB |
Output is correct |
4 |
Correct |
7 ms |
14416 KB |
Output is correct |
5 |
Correct |
7 ms |
14416 KB |
Output is correct |
6 |
Correct |
9 ms |
14360 KB |
Output is correct |
7 |
Correct |
8 ms |
14376 KB |
Output is correct |
8 |
Correct |
8 ms |
14416 KB |
Output is correct |
9 |
Correct |
7 ms |
14416 KB |
Output is correct |
10 |
Correct |
7 ms |
14416 KB |
Output is correct |
11 |
Correct |
7 ms |
14416 KB |
Output is correct |
12 |
Correct |
8 ms |
14376 KB |
Output is correct |
13 |
Correct |
8 ms |
14436 KB |
Output is correct |
14 |
Correct |
8 ms |
14416 KB |
Output is correct |
15 |
Correct |
9 ms |
14484 KB |
Output is correct |
16 |
Correct |
8 ms |
14544 KB |
Output is correct |
17 |
Correct |
8 ms |
14544 KB |
Output is correct |
18 |
Correct |
8 ms |
14544 KB |
Output is correct |
19 |
Correct |
8 ms |
14548 KB |
Output is correct |
20 |
Correct |
8 ms |
14416 KB |
Output is correct |
21 |
Correct |
8 ms |
14456 KB |
Output is correct |
22 |
Correct |
8 ms |
14416 KB |
Output is correct |
23 |
Correct |
8 ms |
14416 KB |
Output is correct |
24 |
Correct |
8 ms |
14544 KB |
Output is correct |
25 |
Correct |
8 ms |
14544 KB |
Output is correct |
26 |
Correct |
8 ms |
14544 KB |
Output is correct |
27 |
Correct |
8 ms |
14544 KB |
Output is correct |
28 |
Correct |
8 ms |
14544 KB |
Output is correct |
29 |
Correct |
8 ms |
14416 KB |
Output is correct |
30 |
Correct |
8 ms |
14416 KB |
Output is correct |
31 |
Correct |
8 ms |
14544 KB |
Output is correct |
32 |
Correct |
8 ms |
14492 KB |
Output is correct |
33 |
Correct |
8 ms |
14416 KB |
Output is correct |
34 |
Correct |
8 ms |
14376 KB |
Output is correct |
35 |
Correct |
9 ms |
14416 KB |
Output is correct |
36 |
Correct |
8 ms |
14544 KB |
Output is correct |
37 |
Correct |
8 ms |
14672 KB |
Output is correct |
38 |
Correct |
11 ms |
14672 KB |
Output is correct |
39 |
Correct |
9 ms |
14416 KB |
Output is correct |
40 |
Correct |
8 ms |
14416 KB |
Output is correct |
41 |
Correct |
10 ms |
14416 KB |
Output is correct |
42 |
Correct |
10 ms |
14416 KB |
Output is correct |
43 |
Correct |
477 ms |
19256 KB |
Output is correct |
44 |
Correct |
708 ms |
24136 KB |
Output is correct |
45 |
Correct |
712 ms |
24108 KB |
Output is correct |
46 |
Correct |
723 ms |
24136 KB |
Output is correct |
47 |
Execution timed out |
3077 ms |
19188 KB |
Time limit exceeded |
48 |
Halted |
0 ms |
0 KB |
- |