#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
const ll mod = 1'000'002'022;
ll ad(ll a, ll b)
{
return (a+b)%mod;
}
ll mul(ll a, ll b)
{
return (a*b)%mod;
}
const int mx = 200'000;
vll pow2(1 + mx);
vi children[1 + mx];
int N, M;
vi depth(1 + mx, 0);
vi A;
ll res = 0;
void dfs(int u)
{
for(int v : children[u])
{
depth[v] = depth[u] + 1;
dfs(v);
}
}
void init(int N_, int M_, vi P_, vi A_)
{
N = N_;
M = M_;
for(int i = 1; i < N+M; i++)
children[P_[i]].push_back(i);
dfs(0);
A = vi(N, 0);
for(int a : A_)
A.push_back(a);
pow2[0] = 1;
for(int e = 1; e <= mx; e++)
pow2[e] = mul(2, pow2[e-1]);
for(int i = N; i < N+M; i++)
res = ad(res, mul(A[i], pow2[depth[i]]));
}
int count_ways(int L, int R)
{
for(int i = L; i <= R; i++)
{
if(A[i] == 0)
{
A[i] = 1;
res = ad(res, pow2[depth[i]]);
}
else
{
A[i] = 0;
res = ad(res, mod - pow2[depth[i]]);
}
}
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
7352 KB |
1st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
7356 KB |
1st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
7352 KB |
1st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
522 ms |
9664 KB |
1st lines differ - on the 1st token, expected: '431985922', found: '537460736' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
522 ms |
9664 KB |
1st lines differ - on the 1st token, expected: '431985922', found: '537460736' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
7356 KB |
1st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
7352 KB |
1st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
7352 KB |
1st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |