#include "circuit.h"
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define all(x) x.begin(),x.end()
typedef long long ll;
#define pb push_back
#define MOD 1000002022
vector<ll>r;
ll m,n;
vector<vector<int>>g;
vector<pair<ll,ll>> tree;
vector<int>a;
void build(int start)
{
if(g[start].size()==1)
{
if(a[start])
tree[start].F=1;
else
tree[start].S=1;
return ;
}
ll l,r;
for(auto x:g[start])
if(x>start)
build(x);
l=g[start][1];
r=g[start][2];
tree[start].F=((tree[l].F*tree[r].F)%MOD + (tree[l].F*(tree[r].F+tree[r].S))%MOD + (tree[l].S*tree[r].F)%MOD)%MOD;
tree[start].S=((tree[l].S*(tree[r].F+tree[r].S))%MOD + (tree[l].F*tree[r].S)%MOD + (tree[l].S*tree[r].S)%MOD)%MOD;
return ;
}
void init(int N, int M, vector<int> P, vector<int> A)
{
n=N;
m=M;
tree.assign(n+m,{0,0});
g.assign(N,vector<int>());
a.assign(N+M,0);
for(int i=0;i<m;i++)
a[i+n]=A[i];
for(int i=1;i<N+M;i++)
{
g[i].pb(P[i]);
g[P[i]].pb(i);
}
}
int count_ways(int L, int R)
{
for(int i=L;i<R;i++)
a[i]=1-a[i];
build(0);
return (tree[0].F+tree[0].S)%MOD;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
464 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
464 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
464 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
13 ms |
8232 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
13 ms |
8232 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
464 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
464 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
464 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |