#include <vector>
#include<bits/stdc++.h>
#include "circuit.h"
using namespace std;
#define vi vector<int>
#define vii vector<vi>
#define ll long long
#define vl vector<ll>
int n,m;
vii g;
vl ways;
vl wb;
int mod=1000002022;
ll sum(ll a, ll b){
return (a+b)%mod;
}
ll diff(ll a, ll b){
return(a-b+mod)%mod;
}
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
n=N;
m=M;
g.resize(N+M);
ways.resize(M+N);
wb.resize(M+N);
for(int i=1 ;i<N+M;i++){
g[P[i]].push_back(i);
}
for(int i=N;i<N+M;i++){
ways[i]=A[i-N];
wb[i]=!ways[i];
}
}
void dfs(int node){
for(int child:g[node]){
if(child>=n)continue;
dfs(child);
}
int p=g[node].size();
vl v(p+1);
for(int child:g[node]){
vl copy=v;
for(int i=0;i<=p;i++){
if(i<p){
copy[i+1]+=v[i+1]+v[i]*ways[child];
copy[i+1]%=mod;
}
copy[i]+=v[i]*wb[child];
copy[i]%=mod;
}
v=copy;
}
vl cum(p+1);
cum[0]=v[0];
for(int i=1;i<=p;i++){
cum[i]=sum(cum[i-1],v[i]);
}
for(int i=1;i<=p;i++){
wb[node]+=cum[i-1];
wb[node]%=mod;
ways[node]+=diff(cum[p],cum[i-1]);
ways[node]%=mod;
}
}
int count_ways(int L, int R) {
for(int i=L;i<=R;i++){
ways[i]=!ways[i];
wb[i]=!wb[i];
}
dfs(0);
return ways[0];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
224 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 |
1 ms |
208 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 |
0 ms |
224 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 |
Execution timed out |
3027 ms |
4644 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3027 ms |
4644 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
208 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 |
0 ms |
224 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 |
0 ms |
224 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |