#include "circuit.h"
//#include "stub.cpp"
#include <bits/stdc++.h>
using namespace std;
const long long MOD=1000002020;
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];
auto left=dfs(adj[s][0]);
auto right=dfs(adj[s][1]);
long long comp=0;
comp+=(left.second*right.first)%MOD;
comp+=(left.first*right.second)%MOD;
return memo[s]={
(comp+(left.first*right.first*2LL)%MOD)%MOD,
(comp+(left.second*right.second*2LL)%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 |
Correct |
2 ms |
2648 KB |
Output is correct |
2 |
Runtime error |
1308 ms |
2097152 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2648 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '467219764' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2648 KB |
Output is correct |
2 |
Runtime error |
1308 ms |
2097152 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3089 ms |
4724 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3089 ms |
4724 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2648 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '467219764' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2648 KB |
Output is correct |
2 |
Runtime error |
1308 ms |
2097152 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2648 KB |
Output is correct |
2 |
Runtime error |
1308 ms |
2097152 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |