#include "circuit.h"
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
constexpr int mod = 1e9 + 2022;
struct ST
{
int pool[2];
};
vector<int> adj[200005];
int choices[200005], coef[200005];
ll ans = 0;
int N, M;
void dfs1(int i)
{
choices[i] = max<int>(1, adj[i].size());
for (int j : adj[i])
{
dfs1(j);
choices[i] = 1ll * choices[i] * choices[j] % mod;
}
}
void dfs2(int i, int x)
{
if (i >= N)
{
coef[i] = x;
return;
}
int n = adj[i].size();
vector<int> l(n), r(n);
for (int j = 0; j < n; j++)
{
int w = adj[i][j];
l[j] = r[j] = choices[w];
if (j)
l[j] = 1ll * l[j] * l[j - 1] % mod;
}
for (int j = n - 2; j >= 0; j--)
r[j] = 1ll * r[j] * r[j + 1] % mod;
for (int j = 0; j < n; j++)
dfs2(adj[i][j], 1ll * (j ? l[j - 1] : 1) *
(j != n - 1 ? r[j + 1] : 1) % mod);
}
int A[100005];
void init(int N_, int M_, vector<int> P, vector<int> A_)
{
N = N_, M = M_;
memcpy(A, A_.data(), sizeof(int) * M);
assert((int)A_.size() == M);
for (int i = 1; i < N + M; i++)
adj[P[i]].push_back(i);
dfs1(0);
dfs2(0, 1);
for (int i = 0; i < M; i++)
{
ans += A[i] * coef[i + N];
ans %= mod;
}
}
int count_ways(int L, int R)
{
L -= N, R -= N;
for (int i = L; i <= R; i++)
{
if (A[i])
{
A[i] = 0;
ans = (ans + mod - coef[i + N]) % mod;
}
else
{
A[i] = 1;
ans = (ans + coef[i + N]) % mod;
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
3 ms |
4944 KB |
Output is correct |
3 |
Correct |
2 ms |
4944 KB |
Output is correct |
4 |
Correct |
2 ms |
4944 KB |
Output is correct |
5 |
Correct |
3 ms |
4944 KB |
Output is correct |
6 |
Correct |
3 ms |
4944 KB |
Output is correct |
7 |
Correct |
3 ms |
4944 KB |
Output is correct |
8 |
Correct |
2 ms |
4944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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: '128' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
3 ms |
4944 KB |
Output is correct |
3 |
Correct |
2 ms |
4944 KB |
Output is correct |
4 |
Correct |
2 ms |
4944 KB |
Output is correct |
5 |
Correct |
3 ms |
4944 KB |
Output is correct |
6 |
Correct |
3 ms |
4944 KB |
Output is correct |
7 |
Correct |
3 ms |
4944 KB |
Output is correct |
8 |
Correct |
2 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: '128' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
475 ms |
7236 KB |
1st lines differ - on the 1st token, expected: '431985922', found: '16402' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
475 ms |
7236 KB |
1st lines differ - on the 1st token, expected: '431985922', found: '16402' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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: '128' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
3 ms |
4944 KB |
Output is correct |
3 |
Correct |
2 ms |
4944 KB |
Output is correct |
4 |
Correct |
2 ms |
4944 KB |
Output is correct |
5 |
Correct |
3 ms |
4944 KB |
Output is correct |
6 |
Correct |
3 ms |
4944 KB |
Output is correct |
7 |
Correct |
3 ms |
4944 KB |
Output is correct |
8 |
Correct |
2 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: '128' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
3 ms |
4944 KB |
Output is correct |
3 |
Correct |
2 ms |
4944 KB |
Output is correct |
4 |
Correct |
2 ms |
4944 KB |
Output is correct |
5 |
Correct |
3 ms |
4944 KB |
Output is correct |
6 |
Correct |
3 ms |
4944 KB |
Output is correct |
7 |
Correct |
3 ms |
4944 KB |
Output is correct |
8 |
Correct |
2 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: '128' |
11 |
Halted |
0 ms |
0 KB |
- |