#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define loop(x, i) for (int i = 0; i < x; i++)
#define rev(x, i) for (int i = (int)x - 1; i >= 0; i--)
#define ALL(x) begin(x), end(x)
#define sz(x) (int)x.size()
typedef array<int, 2> ii;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
constexpr int MOD = 1'000'002'022;
vvi children;
int n, m;
vb a;
void init(int N, int M, vi P, vi A)
{
n = N;
m = M;
children = vvi(N);
a = vb(M);
loop(sz(P), i)
{
if (i == 0)
continue;
children[P[i]].pb(i);
}
loop(sz(A), i)
{
a[i] = A[i];
}
}
ii calc(int i)
{
if (i >= n)
{
if (a[i - n])
return {0, 1};
return {1, 0};
}
vii vs;
for (int j : children[i])
{
vs.pb(calc(j));
}
assert(vs.size() == 2);
int mid = vs[0][0] * vs[1][1] + vs[0][1] * vs[1][0];
int r0 = vs[0][0] * vs[1][0] + mid, r1 = vs[0][1] * vs[1][1] + mid;
return {r0, r1};
}
int count_ways(int L, int R)
{
for (int i = L; i <= R; i++)
{
a[i].flip();
}
return calc(0)[1];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
2nd lines differ - on the 1st token, expected: '2', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
2nd lines differ - on the 1st token, expected: '2', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
2nd lines differ - on the 1st token, expected: '2', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
19 ms |
4816 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
19 ms |
4816 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
2nd lines differ - on the 1st token, expected: '2', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
2nd lines differ - on the 1st token, expected: '2', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
2nd lines differ - on the 1st token, expected: '2', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |