#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long double ld;
typedef pair<ll, ll> pll;
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define ROF(i, a, b) for(int i = a; i >= b; i--)
#define ms memset
#define pb push_back
#define fi first
#define se second
ll MOD = 1e9 + 2022;
int n, m;
vi g[200000];
vector<ll> prod(100000);
vector<ll> b(100000);
vi a;
void get_prod(int u){
prod[u]=max(1,(int)g[u].size());
for (int v : g[u]){
get_prod(v);
prod[u] *= prod[v]; prod[u] %= MOD;
}
}
void dfs(int u, ll val){
int len = g[u].size();
if (len==0){
b[u-n] = val; return;
}
vector<ll> p(len);
FOR(i,0,len){
p[i] = prod[g[u][i]];
}
vector<ll> pre(len+1), suf(len+1);
pre[0]=1; FOR(i,1,len+1){
pre[i]=(pre[i-1]*p[i-1]) % MOD;
}
suf[len]=1; ROF(i,len-1,0){
suf[i]=(suf[i+1]*p[i]) % MOD;
}
FOR(i,0,len){
int v = g[u][i];
ll Val = (pre[i]*suf[i+1]) % MOD;
Val *= val; Val %= MOD;
dfs(v,Val);
}
}
ll ans=0;
void init(int N, int M, vi P, vi A) {
n=N, m=M; a=A;
FOR(i,1,n+m){
g[P[i]].pb(i);
}
get_prod(0); dfs(0,1);
//FOR(i,0,n+m) cout << prod[i] << " ";
//cout << '\n';
//FOR(i,0,m) cout << b[i] << " ";
//cout << '\n';
FOR(i,0,m){
if (a[i]){ans += b[i]; ans %= MOD;}
}
}
int count_ways(int L, int R) {
FOR(i,L-n,R+1-n){
if (a[i]){
ans+=MOD-b[i]; ans %= MOD;
}else{
ans+=b[i]; ans %= MOD;
}
a[i]=1-a[i];
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6480 KB |
Output is correct |
2 |
Correct |
2 ms |
6480 KB |
Output is correct |
3 |
Correct |
3 ms |
6620 KB |
Output is correct |
4 |
Correct |
3 ms |
6608 KB |
Output is correct |
5 |
Correct |
3 ms |
6608 KB |
Output is correct |
6 |
Correct |
3 ms |
6608 KB |
Output is correct |
7 |
Correct |
4 ms |
6608 KB |
Output is correct |
8 |
Correct |
3 ms |
6608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6500 KB |
Output is correct |
2 |
Correct |
3 ms |
6480 KB |
Output is correct |
3 |
Correct |
3 ms |
6480 KB |
Output is correct |
4 |
Correct |
3 ms |
6608 KB |
Output is correct |
5 |
Correct |
3 ms |
6532 KB |
Output is correct |
6 |
Correct |
3 ms |
6608 KB |
Output is correct |
7 |
Correct |
5 ms |
6864 KB |
Output is correct |
8 |
Correct |
3 ms |
6608 KB |
Output is correct |
9 |
Correct |
3 ms |
6608 KB |
Output is correct |
10 |
Correct |
3 ms |
6864 KB |
Output is correct |
11 |
Correct |
3 ms |
6864 KB |
Output is correct |
12 |
Correct |
3 ms |
6608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6480 KB |
Output is correct |
2 |
Correct |
2 ms |
6480 KB |
Output is correct |
3 |
Correct |
3 ms |
6620 KB |
Output is correct |
4 |
Correct |
3 ms |
6608 KB |
Output is correct |
5 |
Correct |
3 ms |
6608 KB |
Output is correct |
6 |
Correct |
3 ms |
6608 KB |
Output is correct |
7 |
Correct |
4 ms |
6608 KB |
Output is correct |
8 |
Correct |
3 ms |
6608 KB |
Output is correct |
9 |
Correct |
3 ms |
6500 KB |
Output is correct |
10 |
Correct |
3 ms |
6480 KB |
Output is correct |
11 |
Correct |
3 ms |
6480 KB |
Output is correct |
12 |
Correct |
3 ms |
6608 KB |
Output is correct |
13 |
Correct |
3 ms |
6532 KB |
Output is correct |
14 |
Correct |
3 ms |
6608 KB |
Output is correct |
15 |
Correct |
5 ms |
6864 KB |
Output is correct |
16 |
Correct |
3 ms |
6608 KB |
Output is correct |
17 |
Correct |
3 ms |
6608 KB |
Output is correct |
18 |
Correct |
3 ms |
6864 KB |
Output is correct |
19 |
Correct |
3 ms |
6864 KB |
Output is correct |
20 |
Correct |
3 ms |
6608 KB |
Output is correct |
21 |
Correct |
3 ms |
6608 KB |
Output is correct |
22 |
Correct |
3 ms |
6608 KB |
Output is correct |
23 |
Correct |
3 ms |
6608 KB |
Output is correct |
24 |
Correct |
3 ms |
6608 KB |
Output is correct |
25 |
Correct |
3 ms |
6608 KB |
Output is correct |
26 |
Correct |
3 ms |
6608 KB |
Output is correct |
27 |
Correct |
5 ms |
6608 KB |
Output is correct |
28 |
Correct |
3 ms |
6608 KB |
Output is correct |
29 |
Correct |
3 ms |
6608 KB |
Output is correct |
30 |
Correct |
4 ms |
6608 KB |
Output is correct |
31 |
Correct |
3 ms |
6864 KB |
Output is correct |
32 |
Correct |
3 ms |
6608 KB |
Output is correct |
33 |
Correct |
3 ms |
6480 KB |
Output is correct |
34 |
Correct |
4 ms |
6608 KB |
Output is correct |
35 |
Correct |
3 ms |
6620 KB |
Output is correct |
36 |
Correct |
3 ms |
6864 KB |
Output is correct |
37 |
Correct |
3 ms |
6864 KB |
Output is correct |
38 |
Correct |
3 ms |
6868 KB |
Output is correct |
39 |
Correct |
3 ms |
6608 KB |
Output is correct |
40 |
Correct |
3 ms |
6608 KB |
Output is correct |
41 |
Correct |
3 ms |
6480 KB |
Output is correct |
42 |
Correct |
3 ms |
6512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
409 ms |
8500 KB |
Output is correct |
2 |
Runtime error |
30 ms |
20916 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
409 ms |
8500 KB |
Output is correct |
2 |
Runtime error |
30 ms |
20916 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6500 KB |
Output is correct |
2 |
Correct |
3 ms |
6480 KB |
Output is correct |
3 |
Correct |
3 ms |
6480 KB |
Output is correct |
4 |
Correct |
3 ms |
6608 KB |
Output is correct |
5 |
Correct |
3 ms |
6532 KB |
Output is correct |
6 |
Correct |
3 ms |
6608 KB |
Output is correct |
7 |
Correct |
5 ms |
6864 KB |
Output is correct |
8 |
Correct |
3 ms |
6608 KB |
Output is correct |
9 |
Correct |
3 ms |
6608 KB |
Output is correct |
10 |
Correct |
3 ms |
6864 KB |
Output is correct |
11 |
Correct |
3 ms |
6864 KB |
Output is correct |
12 |
Correct |
3 ms |
6608 KB |
Output is correct |
13 |
Correct |
409 ms |
8500 KB |
Output is correct |
14 |
Runtime error |
30 ms |
20916 KB |
Execution killed with signal 11 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6480 KB |
Output is correct |
2 |
Correct |
2 ms |
6480 KB |
Output is correct |
3 |
Correct |
3 ms |
6620 KB |
Output is correct |
4 |
Correct |
3 ms |
6608 KB |
Output is correct |
5 |
Correct |
3 ms |
6608 KB |
Output is correct |
6 |
Correct |
3 ms |
6608 KB |
Output is correct |
7 |
Correct |
4 ms |
6608 KB |
Output is correct |
8 |
Correct |
3 ms |
6608 KB |
Output is correct |
9 |
Correct |
3 ms |
6500 KB |
Output is correct |
10 |
Correct |
3 ms |
6480 KB |
Output is correct |
11 |
Correct |
3 ms |
6480 KB |
Output is correct |
12 |
Correct |
3 ms |
6608 KB |
Output is correct |
13 |
Correct |
3 ms |
6532 KB |
Output is correct |
14 |
Correct |
3 ms |
6608 KB |
Output is correct |
15 |
Correct |
5 ms |
6864 KB |
Output is correct |
16 |
Correct |
3 ms |
6608 KB |
Output is correct |
17 |
Correct |
3 ms |
6608 KB |
Output is correct |
18 |
Correct |
3 ms |
6864 KB |
Output is correct |
19 |
Correct |
3 ms |
6864 KB |
Output is correct |
20 |
Correct |
3 ms |
6608 KB |
Output is correct |
21 |
Correct |
3 ms |
6608 KB |
Output is correct |
22 |
Correct |
3 ms |
6608 KB |
Output is correct |
23 |
Correct |
3 ms |
6608 KB |
Output is correct |
24 |
Correct |
3 ms |
6608 KB |
Output is correct |
25 |
Correct |
3 ms |
6608 KB |
Output is correct |
26 |
Correct |
3 ms |
6608 KB |
Output is correct |
27 |
Correct |
5 ms |
6608 KB |
Output is correct |
28 |
Correct |
3 ms |
6608 KB |
Output is correct |
29 |
Correct |
3 ms |
6608 KB |
Output is correct |
30 |
Correct |
4 ms |
6608 KB |
Output is correct |
31 |
Correct |
3 ms |
6864 KB |
Output is correct |
32 |
Correct |
3 ms |
6608 KB |
Output is correct |
33 |
Correct |
3 ms |
6480 KB |
Output is correct |
34 |
Correct |
4 ms |
6608 KB |
Output is correct |
35 |
Correct |
3 ms |
6620 KB |
Output is correct |
36 |
Correct |
3 ms |
6864 KB |
Output is correct |
37 |
Correct |
3 ms |
6864 KB |
Output is correct |
38 |
Correct |
3 ms |
6868 KB |
Output is correct |
39 |
Correct |
3 ms |
6608 KB |
Output is correct |
40 |
Correct |
3 ms |
6608 KB |
Output is correct |
41 |
Correct |
3 ms |
6480 KB |
Output is correct |
42 |
Correct |
3 ms |
6512 KB |
Output is correct |
43 |
Correct |
795 ms |
6736 KB |
Output is correct |
44 |
Correct |
1060 ms |
6772 KB |
Output is correct |
45 |
Correct |
1115 ms |
6748 KB |
Output is correct |
46 |
Correct |
545 ms |
6864 KB |
Output is correct |
47 |
Correct |
1451 ms |
6864 KB |
Output is correct |
48 |
Correct |
1430 ms |
6872 KB |
Output is correct |
49 |
Correct |
1524 ms |
6860 KB |
Output is correct |
50 |
Correct |
2702 ms |
6864 KB |
Output is correct |
51 |
Correct |
2918 ms |
6840 KB |
Output is correct |
52 |
Correct |
1419 ms |
6832 KB |
Output is correct |
53 |
Correct |
602 ms |
8144 KB |
Output is correct |
54 |
Correct |
1469 ms |
6864 KB |
Output is correct |
55 |
Correct |
1224 ms |
6752 KB |
Output is correct |
56 |
Correct |
1491 ms |
6748 KB |
Output is correct |
57 |
Correct |
1518 ms |
6712 KB |
Output is correct |
58 |
Correct |
1420 ms |
8256 KB |
Output is correct |
59 |
Correct |
1385 ms |
8400 KB |
Output is correct |
60 |
Correct |
2616 ms |
8400 KB |
Output is correct |
61 |
Correct |
1018 ms |
7092 KB |
Output is correct |
62 |
Correct |
1022 ms |
6716 KB |
Output is correct |
63 |
Correct |
1216 ms |
6704 KB |
Output is correct |
64 |
Correct |
1397 ms |
6756 KB |
Output is correct |
65 |
Correct |
428 ms |
6672 KB |
Output is correct |
66 |
Correct |
1184 ms |
6800 KB |
Output is correct |
67 |
Correct |
1149 ms |
6812 KB |
Output is correct |
68 |
Correct |
2517 ms |
6800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6480 KB |
Output is correct |
2 |
Correct |
2 ms |
6480 KB |
Output is correct |
3 |
Correct |
3 ms |
6620 KB |
Output is correct |
4 |
Correct |
3 ms |
6608 KB |
Output is correct |
5 |
Correct |
3 ms |
6608 KB |
Output is correct |
6 |
Correct |
3 ms |
6608 KB |
Output is correct |
7 |
Correct |
4 ms |
6608 KB |
Output is correct |
8 |
Correct |
3 ms |
6608 KB |
Output is correct |
9 |
Correct |
3 ms |
6500 KB |
Output is correct |
10 |
Correct |
3 ms |
6480 KB |
Output is correct |
11 |
Correct |
3 ms |
6480 KB |
Output is correct |
12 |
Correct |
3 ms |
6608 KB |
Output is correct |
13 |
Correct |
3 ms |
6532 KB |
Output is correct |
14 |
Correct |
3 ms |
6608 KB |
Output is correct |
15 |
Correct |
5 ms |
6864 KB |
Output is correct |
16 |
Correct |
3 ms |
6608 KB |
Output is correct |
17 |
Correct |
3 ms |
6608 KB |
Output is correct |
18 |
Correct |
3 ms |
6864 KB |
Output is correct |
19 |
Correct |
3 ms |
6864 KB |
Output is correct |
20 |
Correct |
3 ms |
6608 KB |
Output is correct |
21 |
Correct |
3 ms |
6608 KB |
Output is correct |
22 |
Correct |
3 ms |
6608 KB |
Output is correct |
23 |
Correct |
3 ms |
6608 KB |
Output is correct |
24 |
Correct |
3 ms |
6608 KB |
Output is correct |
25 |
Correct |
3 ms |
6608 KB |
Output is correct |
26 |
Correct |
3 ms |
6608 KB |
Output is correct |
27 |
Correct |
5 ms |
6608 KB |
Output is correct |
28 |
Correct |
3 ms |
6608 KB |
Output is correct |
29 |
Correct |
3 ms |
6608 KB |
Output is correct |
30 |
Correct |
4 ms |
6608 KB |
Output is correct |
31 |
Correct |
3 ms |
6864 KB |
Output is correct |
32 |
Correct |
3 ms |
6608 KB |
Output is correct |
33 |
Correct |
3 ms |
6480 KB |
Output is correct |
34 |
Correct |
4 ms |
6608 KB |
Output is correct |
35 |
Correct |
3 ms |
6620 KB |
Output is correct |
36 |
Correct |
3 ms |
6864 KB |
Output is correct |
37 |
Correct |
3 ms |
6864 KB |
Output is correct |
38 |
Correct |
3 ms |
6868 KB |
Output is correct |
39 |
Correct |
3 ms |
6608 KB |
Output is correct |
40 |
Correct |
3 ms |
6608 KB |
Output is correct |
41 |
Correct |
3 ms |
6480 KB |
Output is correct |
42 |
Correct |
3 ms |
6512 KB |
Output is correct |
43 |
Correct |
409 ms |
8500 KB |
Output is correct |
44 |
Runtime error |
30 ms |
20916 KB |
Execution killed with signal 11 |
45 |
Halted |
0 ms |
0 KB |
- |