#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
int N,M;
const int MOD=1e9+2022;
vector<vector<int>> tree;
vector<int> state;
vector<int> depth;
vector<int> poss;
vector<vector<int>> memo;
int mult=1;
int dfs(int i, int on){
if(i>=N){
if(on) return state[i];
else return 1-state[i];
}
if(memo[i][on]!=-1) return memo[i][on];
int lo=dfs(tree[i][0],true)%MOD, lf=dfs(tree[i][0],false)%MOD;
int ro=dfs(tree[i][1],true)%MOD, rf=dfs(tree[i][1],false)%MOD;
int ret=(lo*rf)%MOD+(ro*lf)%MOD;
if(on) ret+=(lo*ro*2)%MOD;
else ret+=(2*lf*rf)%MOD;
return memo[i][on]=ret%MOD;
}
void init(signed n, signed m, std::vector<signed> P, std::vector<signed> A) {
N=n; M=m;
tree.resize(N+M); state.resize(N+M);
memo.clear(); memo.resize(N+M, vector<int>(2,-1));
for (int i = 1; i < N+M; i++) tree[P[i]].push_back(i);
state[N]=1;
mult=dfs(0,true);
for (int i = N; i < N+M; i++) state[i] = A[i-N];
}
signed count_ways(signed L, signed R) {
poss.clear(); poss.resize(N+M,0);
memo.clear(); memo.resize(N+M, vector<int>(2,-1));
int state_sum=0;
for (int i = L; i <= R; i++) {
state[i] = 1-state[i];
}
for (int i = N; i < M+N; i++)
{
state_sum+=state[i];
}
signed d=(state_sum%MOD*mult%MOD)%MOD;
return d;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Runtime error |
1296 ms |
2097152 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
356 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Incorrect |
1 ms |
604 KB |
1st lines differ - on the 1st token, expected: '706880838', found: '688331746' |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Runtime error |
1296 ms |
2097152 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3006 ms |
7864 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3006 ms |
7864 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
356 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Incorrect |
1 ms |
604 KB |
1st lines differ - on the 1st token, expected: '706880838', found: '688331746' |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Runtime error |
1296 ms |
2097152 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Runtime error |
1296 ms |
2097152 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |