#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
ll m,n;
vector<vector<int>>g;
vector<pair<ll,ll>> tree;
vector<int>a;
void build(int start)
{
if(g[start].size()==1)
{
tree[start]={0,0};
if(a[start])
tree[start].F=1;
else
tree[start].S=1;
//cout<<start<<" |"<<tree[start].F<<' '<<tree[start].S<<'\n';
return ;
}
ll l,r;
for(auto x:g[start])
if(x>start)
build(x);
ll add=0;
if(start==0)
add=-1;
l=g[start][1+add];
r=g[start][2+add];
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;
// cout<<start<<" |"<<tree[start].F<<' '<<tree[start].S<<'\n';
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+M,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);
//cout<<tree[0].F<<' '<<tree[0].S;
return tree[0].F;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Incorrect |
0 ms |
208 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
464 KB |
Output is correct |
8 |
Correct |
1 ms |
464 KB |
Output is correct |
9 |
Correct |
1 ms |
464 KB |
Output is correct |
10 |
Correct |
1 ms |
464 KB |
Output is correct |
11 |
Correct |
1 ms |
464 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Incorrect |
0 ms |
208 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3019 ms |
5840 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3019 ms |
5840 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
464 KB |
Output is correct |
8 |
Correct |
1 ms |
464 KB |
Output is correct |
9 |
Correct |
1 ms |
464 KB |
Output is correct |
10 |
Correct |
1 ms |
464 KB |
Output is correct |
11 |
Correct |
1 ms |
464 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Execution timed out |
3019 ms |
5840 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Incorrect |
0 ms |
208 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Incorrect |
0 ms |
208 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |