#include"circuit.h"
#include<vector>
#include<iostream>
using namespace std;
typedef long long ll;
const int MOD=1000002022;
int parents[200000];
ll sub_mul[200000];
vector<int>children[200000];
int n,m;
vector<ll>vals;
vector<bool>active;
ll curr_res=0;
void dfs2(int node){
if(children[node].empty()){
sub_mul[node]=1;
return;
}
sub_mul[node]=children[node].size();
for(int ch:children[node]){
dfs2(ch);
sub_mul[node]*=sub_mul[ch];
sub_mul[node]%=MOD;
}
}
void dfs3(int node,ll val){
if(children[node].empty()){
vals.push_back(val);
return;
}
for(int ch:children[node]){
ll val2=val;
for(int ch2:children[node]){
if(ch2!=ch){
val2*=sub_mul[ch2];
val2%=MOD;
}
}
dfs3(ch,val2);
}
}
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
n=N;
m=M;
for(int i=0;i<n+m;i++){
parents[i]=P[i];
children[parents[i]].push_back(i);
}
dfs2(0);
dfs3(0,1);
for(int i=0;i<(int)A.size();i++){
if(A[i]==1){
curr_res+=vals[i];
curr_res%=MOD;
}
active.push_back(A[i]==1);
}
}
int count_ways(int L, int R) {
L-=n;
R-=n;
for(int i=L;i<=R;i++){
if(active[i]){
active[i]=false;
curr_res+=MOD-vals[i];
curr_res%=MOD;
}else{
active[i]=true;
curr_res+=vals[i];
curr_res%=MOD;
}
}
/*for(int i=0;i<m;i++)
cout<<active[i]<<" ";
cout<<"\n";
for(int i=0;i<m;i++)
cout<<vals[i]<<" ";
cout<<"\n";*/
return (int)curr_res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
7 ms |
10064 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
8 ms |
10064 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
7 ms |
10064 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
14 ms |
11668 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
14 ms |
11668 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
8 ms |
10064 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
7 ms |
10064 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
7 ms |
10064 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |