#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];
if(parents[i]!=-1)
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 |
Incorrect |
2 ms |
4944 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
4944 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
4944 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
410 ms |
7964 KB |
1st lines differ - on the 1st token, expected: '431985922', found: '394586018' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
410 ms |
7964 KB |
1st lines differ - on the 1st token, expected: '431985922', found: '394586018' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
4944 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
4944 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
4944 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |