#include "circuit.h"
//#include "stub.cpp"
#include <bits/stdc++.h>
using namespace std;
const long long MOD= 1000002022;
vector<int> a;
vector<int> adj[100005];
vector<pair<int, int>> memo;
int n, m;
pair<long long, long long> dfs(int s) {
if (s>=n) {
return {a[s-n], a[s-n]^1};
}
if (memo[s].first!=-1) return memo[s];
long long erase1=1, erase2=1, comp=1;
for (auto u: adj[s]) {
auto act=dfs(u);
comp=(comp*(act.first+act.second))%MOD;
erase1*=act.first, erase2*=act.second;
erase1%=MOD, erase2%=MOD;
}
comp-=erase1+erase2;
comp=(comp+10*MOD)%MOD;
return memo[s]={
(comp+(erase1)%MOD)%MOD,
(comp+(erase2)%MOD)%MOD
};
}
void init(int N, int M, vector<int> p, vector<int> aa) {
a=aa;
n=N, m=M;
for (int i=1; i<n+m; i++) {
adj[p[i]].push_back(i);
}
}
int count_ways(int L, int R) {
for (int i=L; i<=R; i++) {
a[i-n]^=1;
}
memo.clear();
memo.resize(n, {-1, -1});
return dfs(0).first;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2648 KB |
2nd lines differ - on the 1st token, expected: '2', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2648 KB |
2nd lines differ - on the 1st token, expected: '2', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2648 KB |
2nd lines differ - on the 1st token, expected: '2', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3041 ms |
4724 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3041 ms |
4724 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2648 KB |
2nd lines differ - on the 1st token, expected: '2', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2648 KB |
2nd lines differ - on the 1st token, expected: '2', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2648 KB |
2nd lines differ - on the 1st token, expected: '2', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |