#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
const long long mod=1'000'002'022;
long long pot2[200010];
long long iloL[200010], iloR[200010], ilo[200010];
vector<int>graf[200010];
long long policz(int n){
return pot2[n-1];
}
long long wsp[200010];
void dfs1(int x){
ilo[x] = 1;
if(graf[x].size())
ilo[x] = graf[x].size();
for(auto j: graf[x]){
dfs1(j);
ilo[x] = ilo[j]*ilo[x]%mod;
}
long long pom = 1;
for(int i=0;i<(int)graf[x].size();i++){
pom = pom*ilo[graf[x][i]]%mod;
iloL[graf[x][i]] = pom;
}
pom = 1;
for(int i=(int)graf[x].size()-1;i>=0;i--){
pom = pom*ilo[graf[x][i]]%mod;
iloR[graf[x][i]] = pom;
}
}
void dfs(int x, long long ilo){
if(graf[x].size()==0){
wsp[x] = ilo;
}
for(int i=0;i<(int)graf[x].size();i++){
long long pom = ilo;
if(i!=0)
pom = (pom*iloL[graf[x][i-1]])%mod;
if(i!=(int)graf[x].size()-1)
pom = (pom*iloR[graf[x][i+1]])%mod;
dfs(graf[x][i], pom);
}
}
struct node{long long val1, val2;bool czy;};
const int base = 1<<17;
node tree[2*base];
int M, N;
void change(int w, int l, int p, int a, int b){
if(l>b || p<a)return;
if(a<=l && p<=b){
swap(tree[w].val1, tree[w].val2);
tree[w*2].czy^=1;
tree[w*2+1].czy^=1;
return;
}
if(tree[w].czy){
swap(tree[w*2].val1, tree[w*2].val2);
swap(tree[w*2+1].val1, tree[w*2+1].val2);
tree[w*2].czy^=1;
tree[w*2+1].czy^=1;
tree[w].czy = 0;
}
change(w*2, l, (l+p)/2, a, b);
change(w*2+1, (l+p)/2+1, p, a, b);
tree[w].val1 = tree[w*2].val1+tree[w*2+1].val1;
tree[w].val2 = tree[w*2].val2+tree[w*2+1].val2;
}
void init(int n, int m, std::vector<int> P, std::vector<int> A) {
M = m;
N = n;
int i;
pot2[0] = 1;
for(int i=1;i<=n+m;i++)pot2[i] = pot2[i-1]*2%mod;
for(int i=1;i<n+m;i++)
graf[P[i]].push_back(i);
wsp[0] = 1;
dfs1(0);
dfs(0, 1);
// for(i=0;i<m;i++)
// printf("%lld ", wsp[i+n]);printf("\n");
// for(i=0;i<m+n;i++)
// printf("%lld ", ilo[i]);printf("\n");
for(int i=0;i<m;i++){
tree[i+base].val1 = wsp[i+n]*A[i];
tree[i+base].val2 = wsp[i+n]*(A[i]^1);
}
for(int i=base-1;i>0;i--){
tree[i].val1 = (tree[i*2].val1+tree[i*2+1].val1)%mod;
tree[i].val2 = (tree[i*2].val2+tree[i*2+1].val2)%mod;
}
// for(int i=0;i<M;i++)
// printf("%lld ", tree[i+base].val1);printf("\n");
}
int count_ways(int L, int R) {
long long res = 0;
L-=N;
R-=N;
// printf("%d %d\n", L, R);
// for(int i=0;i<M;i++)
// printf("%lld ", tree[i+base].val1);printf("\n");
for(int i=L;i<=R;i++){
swap(tree[i+base].val1, tree[i+base].val2);
}
for(int i=0;i<M;i++)
res = (res+tree[i+base].val1)%mod;
// for(int i=0;i<M;i++)
// printf("%lld ", tree[i+base].val1);printf("\n");
return res;
// change(1, 0, base-1, L, R);
return tree[1].val1%mod;
}
Compilation message
circuit.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>)':
circuit.cpp:74:6: warning: unused variable 'i' [-Wunused-variable]
74 | int i;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
19032 KB |
Output is correct |
2 |
Correct |
3 ms |
18892 KB |
Output is correct |
3 |
Correct |
3 ms |
19032 KB |
Output is correct |
4 |
Correct |
3 ms |
19032 KB |
Output is correct |
5 |
Correct |
2 ms |
19032 KB |
Output is correct |
6 |
Correct |
3 ms |
19032 KB |
Output is correct |
7 |
Correct |
3 ms |
19032 KB |
Output is correct |
8 |
Correct |
2 ms |
18920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
19032 KB |
Output is correct |
2 |
Correct |
3 ms |
19032 KB |
Output is correct |
3 |
Correct |
2 ms |
19032 KB |
Output is correct |
4 |
Correct |
3 ms |
19032 KB |
Output is correct |
5 |
Correct |
4 ms |
19032 KB |
Output is correct |
6 |
Correct |
3 ms |
19032 KB |
Output is correct |
7 |
Correct |
3 ms |
19032 KB |
Output is correct |
8 |
Correct |
3 ms |
19032 KB |
Output is correct |
9 |
Correct |
3 ms |
19032 KB |
Output is correct |
10 |
Correct |
3 ms |
19032 KB |
Output is correct |
11 |
Correct |
3 ms |
19032 KB |
Output is correct |
12 |
Correct |
2 ms |
19124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
19032 KB |
Output is correct |
2 |
Correct |
3 ms |
18892 KB |
Output is correct |
3 |
Correct |
3 ms |
19032 KB |
Output is correct |
4 |
Correct |
3 ms |
19032 KB |
Output is correct |
5 |
Correct |
2 ms |
19032 KB |
Output is correct |
6 |
Correct |
3 ms |
19032 KB |
Output is correct |
7 |
Correct |
3 ms |
19032 KB |
Output is correct |
8 |
Correct |
2 ms |
18920 KB |
Output is correct |
9 |
Correct |
3 ms |
19032 KB |
Output is correct |
10 |
Correct |
3 ms |
19032 KB |
Output is correct |
11 |
Correct |
2 ms |
19032 KB |
Output is correct |
12 |
Correct |
3 ms |
19032 KB |
Output is correct |
13 |
Correct |
4 ms |
19032 KB |
Output is correct |
14 |
Correct |
3 ms |
19032 KB |
Output is correct |
15 |
Correct |
3 ms |
19032 KB |
Output is correct |
16 |
Correct |
3 ms |
19032 KB |
Output is correct |
17 |
Correct |
3 ms |
19032 KB |
Output is correct |
18 |
Correct |
3 ms |
19032 KB |
Output is correct |
19 |
Correct |
3 ms |
19032 KB |
Output is correct |
20 |
Correct |
2 ms |
19124 KB |
Output is correct |
21 |
Correct |
3 ms |
19032 KB |
Output is correct |
22 |
Correct |
3 ms |
19032 KB |
Output is correct |
23 |
Correct |
3 ms |
19032 KB |
Output is correct |
24 |
Correct |
3 ms |
19032 KB |
Output is correct |
25 |
Correct |
3 ms |
19032 KB |
Output is correct |
26 |
Correct |
3 ms |
19032 KB |
Output is correct |
27 |
Correct |
4 ms |
19032 KB |
Output is correct |
28 |
Correct |
3 ms |
19032 KB |
Output is correct |
29 |
Correct |
3 ms |
18928 KB |
Output is correct |
30 |
Correct |
3 ms |
19036 KB |
Output is correct |
31 |
Correct |
3 ms |
19040 KB |
Output is correct |
32 |
Correct |
4 ms |
19036 KB |
Output is correct |
33 |
Correct |
3 ms |
19036 KB |
Output is correct |
34 |
Correct |
3 ms |
19044 KB |
Output is correct |
35 |
Correct |
3 ms |
19032 KB |
Output is correct |
36 |
Correct |
3 ms |
19032 KB |
Output is correct |
37 |
Correct |
3 ms |
19032 KB |
Output is correct |
38 |
Correct |
3 ms |
19032 KB |
Output is correct |
39 |
Correct |
3 ms |
19032 KB |
Output is correct |
40 |
Correct |
3 ms |
19032 KB |
Output is correct |
41 |
Correct |
4 ms |
19032 KB |
Output is correct |
42 |
Correct |
5 ms |
19032 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3055 ms |
20872 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3055 ms |
20872 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
19032 KB |
Output is correct |
2 |
Correct |
3 ms |
19032 KB |
Output is correct |
3 |
Correct |
2 ms |
19032 KB |
Output is correct |
4 |
Correct |
3 ms |
19032 KB |
Output is correct |
5 |
Correct |
4 ms |
19032 KB |
Output is correct |
6 |
Correct |
3 ms |
19032 KB |
Output is correct |
7 |
Correct |
3 ms |
19032 KB |
Output is correct |
8 |
Correct |
3 ms |
19032 KB |
Output is correct |
9 |
Correct |
3 ms |
19032 KB |
Output is correct |
10 |
Correct |
3 ms |
19032 KB |
Output is correct |
11 |
Correct |
3 ms |
19032 KB |
Output is correct |
12 |
Correct |
2 ms |
19124 KB |
Output is correct |
13 |
Execution timed out |
3055 ms |
20872 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
19032 KB |
Output is correct |
2 |
Correct |
3 ms |
18892 KB |
Output is correct |
3 |
Correct |
3 ms |
19032 KB |
Output is correct |
4 |
Correct |
3 ms |
19032 KB |
Output is correct |
5 |
Correct |
2 ms |
19032 KB |
Output is correct |
6 |
Correct |
3 ms |
19032 KB |
Output is correct |
7 |
Correct |
3 ms |
19032 KB |
Output is correct |
8 |
Correct |
2 ms |
18920 KB |
Output is correct |
9 |
Correct |
3 ms |
19032 KB |
Output is correct |
10 |
Correct |
3 ms |
19032 KB |
Output is correct |
11 |
Correct |
2 ms |
19032 KB |
Output is correct |
12 |
Correct |
3 ms |
19032 KB |
Output is correct |
13 |
Correct |
4 ms |
19032 KB |
Output is correct |
14 |
Correct |
3 ms |
19032 KB |
Output is correct |
15 |
Correct |
3 ms |
19032 KB |
Output is correct |
16 |
Correct |
3 ms |
19032 KB |
Output is correct |
17 |
Correct |
3 ms |
19032 KB |
Output is correct |
18 |
Correct |
3 ms |
19032 KB |
Output is correct |
19 |
Correct |
3 ms |
19032 KB |
Output is correct |
20 |
Correct |
2 ms |
19124 KB |
Output is correct |
21 |
Correct |
3 ms |
19032 KB |
Output is correct |
22 |
Correct |
3 ms |
19032 KB |
Output is correct |
23 |
Correct |
3 ms |
19032 KB |
Output is correct |
24 |
Correct |
3 ms |
19032 KB |
Output is correct |
25 |
Correct |
3 ms |
19032 KB |
Output is correct |
26 |
Correct |
3 ms |
19032 KB |
Output is correct |
27 |
Correct |
4 ms |
19032 KB |
Output is correct |
28 |
Correct |
3 ms |
19032 KB |
Output is correct |
29 |
Correct |
3 ms |
18928 KB |
Output is correct |
30 |
Correct |
3 ms |
19036 KB |
Output is correct |
31 |
Correct |
3 ms |
19040 KB |
Output is correct |
32 |
Correct |
4 ms |
19036 KB |
Output is correct |
33 |
Correct |
3 ms |
19036 KB |
Output is correct |
34 |
Correct |
3 ms |
19044 KB |
Output is correct |
35 |
Correct |
3 ms |
19032 KB |
Output is correct |
36 |
Correct |
3 ms |
19032 KB |
Output is correct |
37 |
Correct |
3 ms |
19032 KB |
Output is correct |
38 |
Correct |
3 ms |
19032 KB |
Output is correct |
39 |
Correct |
3 ms |
19032 KB |
Output is correct |
40 |
Correct |
3 ms |
19032 KB |
Output is correct |
41 |
Correct |
4 ms |
19032 KB |
Output is correct |
42 |
Correct |
5 ms |
19032 KB |
Output is correct |
43 |
Correct |
1176 ms |
19032 KB |
Output is correct |
44 |
Correct |
1561 ms |
19032 KB |
Output is correct |
45 |
Correct |
1720 ms |
19032 KB |
Output is correct |
46 |
Correct |
2446 ms |
19284 KB |
Output is correct |
47 |
Correct |
2576 ms |
19288 KB |
Output is correct |
48 |
Correct |
2580 ms |
19288 KB |
Output is correct |
49 |
Correct |
2547 ms |
19288 KB |
Output is correct |
50 |
Correct |
2867 ms |
19288 KB |
Output is correct |
51 |
Correct |
2816 ms |
19028 KB |
Output is correct |
52 |
Correct |
2573 ms |
19032 KB |
Output is correct |
53 |
Correct |
611 ms |
19544 KB |
Output is correct |
54 |
Correct |
2581 ms |
19288 KB |
Output is correct |
55 |
Correct |
2575 ms |
19032 KB |
Output is correct |
56 |
Correct |
2571 ms |
19032 KB |
Output is correct |
57 |
Correct |
2534 ms |
19032 KB |
Output is correct |
58 |
Correct |
2617 ms |
19544 KB |
Output is correct |
59 |
Correct |
2605 ms |
19796 KB |
Output is correct |
60 |
Correct |
2811 ms |
19692 KB |
Output is correct |
61 |
Correct |
1542 ms |
19288 KB |
Output is correct |
62 |
Correct |
1981 ms |
19032 KB |
Output is correct |
63 |
Correct |
2084 ms |
19032 KB |
Output is correct |
64 |
Correct |
2586 ms |
19032 KB |
Output is correct |
65 |
Correct |
730 ms |
19032 KB |
Output is correct |
66 |
Correct |
2233 ms |
19288 KB |
Output is correct |
67 |
Correct |
2250 ms |
19288 KB |
Output is correct |
68 |
Correct |
2416 ms |
19288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
19032 KB |
Output is correct |
2 |
Correct |
3 ms |
18892 KB |
Output is correct |
3 |
Correct |
3 ms |
19032 KB |
Output is correct |
4 |
Correct |
3 ms |
19032 KB |
Output is correct |
5 |
Correct |
2 ms |
19032 KB |
Output is correct |
6 |
Correct |
3 ms |
19032 KB |
Output is correct |
7 |
Correct |
3 ms |
19032 KB |
Output is correct |
8 |
Correct |
2 ms |
18920 KB |
Output is correct |
9 |
Correct |
3 ms |
19032 KB |
Output is correct |
10 |
Correct |
3 ms |
19032 KB |
Output is correct |
11 |
Correct |
2 ms |
19032 KB |
Output is correct |
12 |
Correct |
3 ms |
19032 KB |
Output is correct |
13 |
Correct |
4 ms |
19032 KB |
Output is correct |
14 |
Correct |
3 ms |
19032 KB |
Output is correct |
15 |
Correct |
3 ms |
19032 KB |
Output is correct |
16 |
Correct |
3 ms |
19032 KB |
Output is correct |
17 |
Correct |
3 ms |
19032 KB |
Output is correct |
18 |
Correct |
3 ms |
19032 KB |
Output is correct |
19 |
Correct |
3 ms |
19032 KB |
Output is correct |
20 |
Correct |
2 ms |
19124 KB |
Output is correct |
21 |
Correct |
3 ms |
19032 KB |
Output is correct |
22 |
Correct |
3 ms |
19032 KB |
Output is correct |
23 |
Correct |
3 ms |
19032 KB |
Output is correct |
24 |
Correct |
3 ms |
19032 KB |
Output is correct |
25 |
Correct |
3 ms |
19032 KB |
Output is correct |
26 |
Correct |
3 ms |
19032 KB |
Output is correct |
27 |
Correct |
4 ms |
19032 KB |
Output is correct |
28 |
Correct |
3 ms |
19032 KB |
Output is correct |
29 |
Correct |
3 ms |
18928 KB |
Output is correct |
30 |
Correct |
3 ms |
19036 KB |
Output is correct |
31 |
Correct |
3 ms |
19040 KB |
Output is correct |
32 |
Correct |
4 ms |
19036 KB |
Output is correct |
33 |
Correct |
3 ms |
19036 KB |
Output is correct |
34 |
Correct |
3 ms |
19044 KB |
Output is correct |
35 |
Correct |
3 ms |
19032 KB |
Output is correct |
36 |
Correct |
3 ms |
19032 KB |
Output is correct |
37 |
Correct |
3 ms |
19032 KB |
Output is correct |
38 |
Correct |
3 ms |
19032 KB |
Output is correct |
39 |
Correct |
3 ms |
19032 KB |
Output is correct |
40 |
Correct |
3 ms |
19032 KB |
Output is correct |
41 |
Correct |
4 ms |
19032 KB |
Output is correct |
42 |
Correct |
5 ms |
19032 KB |
Output is correct |
43 |
Execution timed out |
3055 ms |
20872 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |