#include "circuit.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1'000'002'022;
namespace
{
int N, M;
vector<int> P, A, c;
vector<int> child[200005];
ll zero[200005], one[200005];
}
void dothings(int i)
{
int K = child[i].size();
vector<ll> dp(K + 1, 0);
dp[0] = 1;
for (auto j : child[i])
for (int k = K - 1; k >= 0; k--)
{
dp[k + 1] = (dp[k + 1] + dp[k] * one[j]) % mod;
dp[k] = (dp[k] * zero[j]) % mod;
}
zero[i] = one[i] = 0;
for (int k = 0; k <= K; k++)
{
zero[i] = (zero[i] + (K - k) * dp[k]) % mod;
one[i] = (one[i] + k * dp[k]) % mod;
}
}
void init(int N, int M, vector<int> P, vector<int> A)
{
::N = N;
::M = M;
::P = P;
::A = A;
c.resize(N);
for (int i = 1; i < N + M; i++)
c[P[i]]++, child[P[i]].emplace_back(i);
for (int i = 0; i < M; i++)
if (A[i] == 1)
zero[N + i] = 0, one[N + i] = 1;
else
zero[N + i] = 1, one[N + i] = 0;
for (int i = N - 1; i >= 0; i--)
dothings(i);
}
int count_ways(int L, int R)
{
L -= N, R -= N;
for (int i = L; i <= R; i++)
A[i] ^= 1;
for (int i = L; i <= R; i++)
if (A[i] == 1)
zero[N + i] = 0, one[N + i] = 1;
else
zero[N + i] = 1, one[N + i] = 0;
for (int i = P[L + N]; i >= 0; i = P[i])
dothings(i);
return one[0];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
2 ms |
4944 KB |
Output is correct |
3 |
Correct |
16 ms |
4944 KB |
Output is correct |
4 |
Correct |
20 ms |
5056 KB |
Output is correct |
5 |
Correct |
17 ms |
4944 KB |
Output is correct |
6 |
Correct |
20 ms |
4944 KB |
Output is correct |
7 |
Correct |
18 ms |
5056 KB |
Output is correct |
8 |
Correct |
17 ms |
4944 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Incorrect |
2 ms |
4944 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '474414066' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
2 ms |
4944 KB |
Output is correct |
3 |
Correct |
16 ms |
4944 KB |
Output is correct |
4 |
Correct |
20 ms |
5056 KB |
Output is correct |
5 |
Correct |
17 ms |
4944 KB |
Output is correct |
6 |
Correct |
20 ms |
4944 KB |
Output is correct |
7 |
Correct |
18 ms |
5056 KB |
Output is correct |
8 |
Correct |
17 ms |
4944 KB |
Output is correct |
9 |
Correct |
2 ms |
4944 KB |
Output is correct |
10 |
Incorrect |
2 ms |
4944 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '474414066' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
576 ms |
8276 KB |
Output is correct |
2 |
Correct |
779 ms |
11600 KB |
Output is correct |
3 |
Correct |
902 ms |
11668 KB |
Output is correct |
4 |
Correct |
816 ms |
11624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
576 ms |
8276 KB |
Output is correct |
2 |
Correct |
779 ms |
11600 KB |
Output is correct |
3 |
Correct |
902 ms |
11668 KB |
Output is correct |
4 |
Correct |
816 ms |
11624 KB |
Output is correct |
5 |
Execution timed out |
3078 ms |
8272 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Incorrect |
2 ms |
4944 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '474414066' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
2 ms |
4944 KB |
Output is correct |
3 |
Correct |
16 ms |
4944 KB |
Output is correct |
4 |
Correct |
20 ms |
5056 KB |
Output is correct |
5 |
Correct |
17 ms |
4944 KB |
Output is correct |
6 |
Correct |
20 ms |
4944 KB |
Output is correct |
7 |
Correct |
18 ms |
5056 KB |
Output is correct |
8 |
Correct |
17 ms |
4944 KB |
Output is correct |
9 |
Correct |
2 ms |
4944 KB |
Output is correct |
10 |
Incorrect |
2 ms |
4944 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '474414066' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
2 ms |
4944 KB |
Output is correct |
3 |
Correct |
16 ms |
4944 KB |
Output is correct |
4 |
Correct |
20 ms |
5056 KB |
Output is correct |
5 |
Correct |
17 ms |
4944 KB |
Output is correct |
6 |
Correct |
20 ms |
4944 KB |
Output is correct |
7 |
Correct |
18 ms |
5056 KB |
Output is correct |
8 |
Correct |
17 ms |
4944 KB |
Output is correct |
9 |
Correct |
2 ms |
4944 KB |
Output is correct |
10 |
Incorrect |
2 ms |
4944 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '474414066' |
11 |
Halted |
0 ms |
0 KB |
- |