#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll MOD = 1000002022;
const int MAXN = 1e5+5;
vector<int>adj[MAXN];
ll c[MAXN],sub[MAXN];
int n,m;
void dfs(int v){
if(adj[v].empty())sub[v] = 1;
else sub[v] = adj[v].size();
for(int x:adj[v]){
dfs(x);
sub[v] = sub[v]*sub[x]%MOD;
}
}
void dfs(int v,ll cur){
if(adj[v].empty()){
c[v-n] = cur;
return;
}
int s = adj[v].size();
vector<ll>pref(s,1),suff(s,1);
for(int i=0;i<s;i++){
pref[i] = sub[adj[v][i]];
suff[i] = sub[adj[v][i]];
if(i)pref[i] = pref[i]*pref[i-1]%MOD;
}
for(int i=s-2;i>=0;i--)suff[i] = suff[i]*suff[i+1]%MOD;
for(int i=0;i<s;i++){
ll k = 1;
if(i)k = pref[i-1]*k%MOD;
if(i!=s-1)k = suff[i+1]*k%MOD;
dfs(adj[v][i],(cur*k)%MOD);
}
}
ll ans = 0;
vector<int>a;
void init(int N, int M, vector<int> p, vector<int> A) {
n = N;
m = M;
a = A;
for(int i=1;i<n+m;i++)adj[p[i]].push_back(i);
dfs(0);
dfs(0,1);
for(int i=0;i<m;i++){
if(a[i])ans+=c[i];
ans%=MOD;
}
}
int count_ways(int L, int R) {
L-=n;
R-=n;
for(int i=L;i<=R;i++){
if(!a[i])ans+=c[i];
else ans+=MOD-c[i];
a[i]^=1;
ans%=MOD;
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2640 KB |
Output is correct |
2 |
Correct |
1 ms |
2640 KB |
Output is correct |
3 |
Correct |
2 ms |
2640 KB |
Output is correct |
4 |
Correct |
2 ms |
2640 KB |
Output is correct |
5 |
Correct |
2 ms |
2640 KB |
Output is correct |
6 |
Correct |
1 ms |
2640 KB |
Output is correct |
7 |
Correct |
2 ms |
2640 KB |
Output is correct |
8 |
Correct |
2 ms |
2640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2640 KB |
Output is correct |
2 |
Correct |
2 ms |
2640 KB |
Output is correct |
3 |
Correct |
2 ms |
2640 KB |
Output is correct |
4 |
Correct |
2 ms |
2640 KB |
Output is correct |
5 |
Correct |
2 ms |
2640 KB |
Output is correct |
6 |
Correct |
2 ms |
2708 KB |
Output is correct |
7 |
Correct |
2 ms |
2640 KB |
Output is correct |
8 |
Correct |
2 ms |
2640 KB |
Output is correct |
9 |
Correct |
2 ms |
2640 KB |
Output is correct |
10 |
Correct |
2 ms |
2896 KB |
Output is correct |
11 |
Correct |
2 ms |
2896 KB |
Output is correct |
12 |
Correct |
2 ms |
2640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2640 KB |
Output is correct |
2 |
Correct |
1 ms |
2640 KB |
Output is correct |
3 |
Correct |
2 ms |
2640 KB |
Output is correct |
4 |
Correct |
2 ms |
2640 KB |
Output is correct |
5 |
Correct |
2 ms |
2640 KB |
Output is correct |
6 |
Correct |
1 ms |
2640 KB |
Output is correct |
7 |
Correct |
2 ms |
2640 KB |
Output is correct |
8 |
Correct |
2 ms |
2640 KB |
Output is correct |
9 |
Correct |
2 ms |
2640 KB |
Output is correct |
10 |
Correct |
2 ms |
2640 KB |
Output is correct |
11 |
Correct |
2 ms |
2640 KB |
Output is correct |
12 |
Correct |
2 ms |
2640 KB |
Output is correct |
13 |
Correct |
2 ms |
2640 KB |
Output is correct |
14 |
Correct |
2 ms |
2708 KB |
Output is correct |
15 |
Correct |
2 ms |
2640 KB |
Output is correct |
16 |
Correct |
2 ms |
2640 KB |
Output is correct |
17 |
Correct |
2 ms |
2640 KB |
Output is correct |
18 |
Correct |
2 ms |
2896 KB |
Output is correct |
19 |
Correct |
2 ms |
2896 KB |
Output is correct |
20 |
Correct |
2 ms |
2640 KB |
Output is correct |
21 |
Correct |
2 ms |
2640 KB |
Output is correct |
22 |
Correct |
2 ms |
2640 KB |
Output is correct |
23 |
Correct |
2 ms |
2640 KB |
Output is correct |
24 |
Correct |
2 ms |
2640 KB |
Output is correct |
25 |
Correct |
2 ms |
2640 KB |
Output is correct |
26 |
Correct |
2 ms |
2640 KB |
Output is correct |
27 |
Correct |
2 ms |
2640 KB |
Output is correct |
28 |
Correct |
2 ms |
2640 KB |
Output is correct |
29 |
Correct |
2 ms |
2596 KB |
Output is correct |
30 |
Correct |
2 ms |
2640 KB |
Output is correct |
31 |
Correct |
2 ms |
2768 KB |
Output is correct |
32 |
Correct |
2 ms |
2640 KB |
Output is correct |
33 |
Correct |
2 ms |
2640 KB |
Output is correct |
34 |
Correct |
2 ms |
2640 KB |
Output is correct |
35 |
Correct |
2 ms |
2628 KB |
Output is correct |
36 |
Correct |
2 ms |
2912 KB |
Output is correct |
37 |
Correct |
2 ms |
2896 KB |
Output is correct |
38 |
Correct |
2 ms |
2896 KB |
Output is correct |
39 |
Correct |
2 ms |
2640 KB |
Output is correct |
40 |
Correct |
2 ms |
2640 KB |
Output is correct |
41 |
Correct |
2 ms |
2640 KB |
Output is correct |
42 |
Correct |
2 ms |
2640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
459 ms |
5340 KB |
Output is correct |
2 |
Runtime error |
29 ms |
14156 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
459 ms |
5340 KB |
Output is correct |
2 |
Runtime error |
29 ms |
14156 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2640 KB |
Output is correct |
2 |
Correct |
2 ms |
2640 KB |
Output is correct |
3 |
Correct |
2 ms |
2640 KB |
Output is correct |
4 |
Correct |
2 ms |
2640 KB |
Output is correct |
5 |
Correct |
2 ms |
2640 KB |
Output is correct |
6 |
Correct |
2 ms |
2708 KB |
Output is correct |
7 |
Correct |
2 ms |
2640 KB |
Output is correct |
8 |
Correct |
2 ms |
2640 KB |
Output is correct |
9 |
Correct |
2 ms |
2640 KB |
Output is correct |
10 |
Correct |
2 ms |
2896 KB |
Output is correct |
11 |
Correct |
2 ms |
2896 KB |
Output is correct |
12 |
Correct |
2 ms |
2640 KB |
Output is correct |
13 |
Correct |
459 ms |
5340 KB |
Output is correct |
14 |
Runtime error |
29 ms |
14156 KB |
Execution killed with signal 11 |
15 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2640 KB |
Output is correct |
2 |
Correct |
1 ms |
2640 KB |
Output is correct |
3 |
Correct |
2 ms |
2640 KB |
Output is correct |
4 |
Correct |
2 ms |
2640 KB |
Output is correct |
5 |
Correct |
2 ms |
2640 KB |
Output is correct |
6 |
Correct |
1 ms |
2640 KB |
Output is correct |
7 |
Correct |
2 ms |
2640 KB |
Output is correct |
8 |
Correct |
2 ms |
2640 KB |
Output is correct |
9 |
Correct |
2 ms |
2640 KB |
Output is correct |
10 |
Correct |
2 ms |
2640 KB |
Output is correct |
11 |
Correct |
2 ms |
2640 KB |
Output is correct |
12 |
Correct |
2 ms |
2640 KB |
Output is correct |
13 |
Correct |
2 ms |
2640 KB |
Output is correct |
14 |
Correct |
2 ms |
2708 KB |
Output is correct |
15 |
Correct |
2 ms |
2640 KB |
Output is correct |
16 |
Correct |
2 ms |
2640 KB |
Output is correct |
17 |
Correct |
2 ms |
2640 KB |
Output is correct |
18 |
Correct |
2 ms |
2896 KB |
Output is correct |
19 |
Correct |
2 ms |
2896 KB |
Output is correct |
20 |
Correct |
2 ms |
2640 KB |
Output is correct |
21 |
Correct |
2 ms |
2640 KB |
Output is correct |
22 |
Correct |
2 ms |
2640 KB |
Output is correct |
23 |
Correct |
2 ms |
2640 KB |
Output is correct |
24 |
Correct |
2 ms |
2640 KB |
Output is correct |
25 |
Correct |
2 ms |
2640 KB |
Output is correct |
26 |
Correct |
2 ms |
2640 KB |
Output is correct |
27 |
Correct |
2 ms |
2640 KB |
Output is correct |
28 |
Correct |
2 ms |
2640 KB |
Output is correct |
29 |
Correct |
2 ms |
2596 KB |
Output is correct |
30 |
Correct |
2 ms |
2640 KB |
Output is correct |
31 |
Correct |
2 ms |
2768 KB |
Output is correct |
32 |
Correct |
2 ms |
2640 KB |
Output is correct |
33 |
Correct |
2 ms |
2640 KB |
Output is correct |
34 |
Correct |
2 ms |
2640 KB |
Output is correct |
35 |
Correct |
2 ms |
2628 KB |
Output is correct |
36 |
Correct |
2 ms |
2912 KB |
Output is correct |
37 |
Correct |
2 ms |
2896 KB |
Output is correct |
38 |
Correct |
2 ms |
2896 KB |
Output is correct |
39 |
Correct |
2 ms |
2640 KB |
Output is correct |
40 |
Correct |
2 ms |
2640 KB |
Output is correct |
41 |
Correct |
2 ms |
2640 KB |
Output is correct |
42 |
Correct |
2 ms |
2640 KB |
Output is correct |
43 |
Correct |
777 ms |
2776 KB |
Output is correct |
44 |
Correct |
1258 ms |
2896 KB |
Output is correct |
45 |
Correct |
1334 ms |
2904 KB |
Output is correct |
46 |
Correct |
926 ms |
3064 KB |
Output is correct |
47 |
Correct |
1636 ms |
3024 KB |
Output is correct |
48 |
Correct |
1568 ms |
3024 KB |
Output is correct |
49 |
Correct |
1640 ms |
3024 KB |
Output is correct |
50 |
Correct |
2830 ms |
3024 KB |
Output is correct |
51 |
Correct |
2617 ms |
2960 KB |
Output is correct |
52 |
Correct |
1609 ms |
2944 KB |
Output is correct |
53 |
Correct |
810 ms |
3792 KB |
Output is correct |
54 |
Correct |
1536 ms |
3024 KB |
Output is correct |
55 |
Correct |
1411 ms |
2896 KB |
Output is correct |
56 |
Correct |
1649 ms |
2900 KB |
Output is correct |
57 |
Correct |
1455 ms |
2872 KB |
Output is correct |
58 |
Correct |
1538 ms |
4048 KB |
Output is correct |
59 |
Correct |
1410 ms |
4048 KB |
Output is correct |
60 |
Correct |
2882 ms |
4176 KB |
Output is correct |
61 |
Correct |
1187 ms |
3152 KB |
Output is correct |
62 |
Correct |
1324 ms |
2768 KB |
Output is correct |
63 |
Correct |
1375 ms |
2768 KB |
Output is correct |
64 |
Correct |
1393 ms |
2896 KB |
Output is correct |
65 |
Correct |
589 ms |
2768 KB |
Output is correct |
66 |
Correct |
1274 ms |
2904 KB |
Output is correct |
67 |
Correct |
1403 ms |
2900 KB |
Output is correct |
68 |
Correct |
2481 ms |
2908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2640 KB |
Output is correct |
2 |
Correct |
1 ms |
2640 KB |
Output is correct |
3 |
Correct |
2 ms |
2640 KB |
Output is correct |
4 |
Correct |
2 ms |
2640 KB |
Output is correct |
5 |
Correct |
2 ms |
2640 KB |
Output is correct |
6 |
Correct |
1 ms |
2640 KB |
Output is correct |
7 |
Correct |
2 ms |
2640 KB |
Output is correct |
8 |
Correct |
2 ms |
2640 KB |
Output is correct |
9 |
Correct |
2 ms |
2640 KB |
Output is correct |
10 |
Correct |
2 ms |
2640 KB |
Output is correct |
11 |
Correct |
2 ms |
2640 KB |
Output is correct |
12 |
Correct |
2 ms |
2640 KB |
Output is correct |
13 |
Correct |
2 ms |
2640 KB |
Output is correct |
14 |
Correct |
2 ms |
2708 KB |
Output is correct |
15 |
Correct |
2 ms |
2640 KB |
Output is correct |
16 |
Correct |
2 ms |
2640 KB |
Output is correct |
17 |
Correct |
2 ms |
2640 KB |
Output is correct |
18 |
Correct |
2 ms |
2896 KB |
Output is correct |
19 |
Correct |
2 ms |
2896 KB |
Output is correct |
20 |
Correct |
2 ms |
2640 KB |
Output is correct |
21 |
Correct |
2 ms |
2640 KB |
Output is correct |
22 |
Correct |
2 ms |
2640 KB |
Output is correct |
23 |
Correct |
2 ms |
2640 KB |
Output is correct |
24 |
Correct |
2 ms |
2640 KB |
Output is correct |
25 |
Correct |
2 ms |
2640 KB |
Output is correct |
26 |
Correct |
2 ms |
2640 KB |
Output is correct |
27 |
Correct |
2 ms |
2640 KB |
Output is correct |
28 |
Correct |
2 ms |
2640 KB |
Output is correct |
29 |
Correct |
2 ms |
2596 KB |
Output is correct |
30 |
Correct |
2 ms |
2640 KB |
Output is correct |
31 |
Correct |
2 ms |
2768 KB |
Output is correct |
32 |
Correct |
2 ms |
2640 KB |
Output is correct |
33 |
Correct |
2 ms |
2640 KB |
Output is correct |
34 |
Correct |
2 ms |
2640 KB |
Output is correct |
35 |
Correct |
2 ms |
2628 KB |
Output is correct |
36 |
Correct |
2 ms |
2912 KB |
Output is correct |
37 |
Correct |
2 ms |
2896 KB |
Output is correct |
38 |
Correct |
2 ms |
2896 KB |
Output is correct |
39 |
Correct |
2 ms |
2640 KB |
Output is correct |
40 |
Correct |
2 ms |
2640 KB |
Output is correct |
41 |
Correct |
2 ms |
2640 KB |
Output is correct |
42 |
Correct |
2 ms |
2640 KB |
Output is correct |
43 |
Correct |
459 ms |
5340 KB |
Output is correct |
44 |
Runtime error |
29 ms |
14156 KB |
Execution killed with signal 11 |
45 |
Halted |
0 ms |
0 KB |
- |