#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;
ll ways[200005], s[100005];
ll seg[400005], lazy[400005];
vector<int> child[100005];
void init_seg(int i = 1, int L = 0, int R = M - 1)
{
if (L == R)
{
seg[i] = s[L];
return;
}
int mid = (L + R) / 2;
init_seg(i << 1, L, mid);
init_seg(i << 1 | 1, mid + 1, R);
seg[i] = (seg[i << 1] + seg[i << 1 | 1]) % mod;
}
ll ans = 0;
ll modify(int mL, int mR, int i = 1, int L = 0, int R = M - 1)
{
if (mL <= L && R <= mR)
{
lazy[i] ^= 1, seg[i] = -seg[i];
return -seg[i];
}
else if (R < mL || mR < L)
return 0;
else
{
int mid = (L + R) / 2;
if (lazy[i])
{
lazy[i] = 0;
lazy[i << 1] ^= 1;
lazy[i << 1 | 1] ^= 1;
seg[i << 1] = -seg[i << 1];
seg[i << 1 | 1] = -seg[i << 1 | 1];
}
ll res = (modify(mL, mR, i << 1, L, mid) +
modify(mL, mR, i << 1 | 1, mid + 1, R)) %
mod;
seg[i] = (seg[i << 1] + seg[i << 1 | 1]) % mod;
return res;
}
}
void dfs(int u, ll up)
{
if (u >= N)
s[u - N] = up;
else
{
int k = child[u].size();
vector<ll> pre(k + 1, up), suf(k + 1, up);
for (int i = 0; i < k; i++)
pre[i + 1] = pre[i] * ways[child[u][i]] % mod;
for (int i = k - 1; i >= 0; i--)
suf[i] = suf[i + 1] * ways[child[u][i]] % mod;
for (int i = 0; i < k; i++)
dfs(child[u][i], pre[i] * suf[i + 1] % mod);
}
}
}
void init(int N, int M, vector<int> P, vector<int> A)
{
::M = M;
::N = N;
for (int i = N + M - 1; i >= N; i--)
{
child[P[i]].emplace_back(i);
ways[i] = 1;
}
for (int i = N - 1; i >= 0; i--)
{
if (i)
child[P[i]].emplace_back(i);
ways[i] = child[i].size();
for (int j : child[i])
ways[i] = ways[i] * ways[j] % mod;
}
dfs(0, 1);
init_seg();
for (int i = 0; i < M; i++)
if (A[i])
ans = (ans + modify(i, i)) % mod;
}
int count_ways(int L, int R)
{
L -= N, R -= N;
ans = (ans + modify(L, R)) % mod;
return (ans + mod) % mod;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2768 KB |
Output is correct |
2 |
Correct |
1 ms |
2640 KB |
Output is correct |
3 |
Correct |
1 ms |
2640 KB |
Output is correct |
4 |
Correct |
1 ms |
2640 KB |
Output is correct |
5 |
Correct |
2 ms |
2768 KB |
Output is correct |
6 |
Correct |
1 ms |
2768 KB |
Output is correct |
7 |
Correct |
1 ms |
2640 KB |
Output is correct |
8 |
Correct |
1 ms |
2640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2640 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2640 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '458094764' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2768 KB |
Output is correct |
2 |
Correct |
1 ms |
2640 KB |
Output is correct |
3 |
Correct |
1 ms |
2640 KB |
Output is correct |
4 |
Correct |
1 ms |
2640 KB |
Output is correct |
5 |
Correct |
2 ms |
2768 KB |
Output is correct |
6 |
Correct |
1 ms |
2768 KB |
Output is correct |
7 |
Correct |
1 ms |
2640 KB |
Output is correct |
8 |
Correct |
1 ms |
2640 KB |
Output is correct |
9 |
Correct |
1 ms |
2640 KB |
Output is correct |
10 |
Incorrect |
1 ms |
2640 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '458094764' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
356 ms |
5976 KB |
1st lines differ - on the 1st token, expected: '431985922', found: '698541100' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
356 ms |
5976 KB |
1st lines differ - on the 1st token, expected: '431985922', found: '698541100' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2640 KB |
Output is correct |
2 |
Incorrect |
1 ms |
2640 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '458094764' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2768 KB |
Output is correct |
2 |
Correct |
1 ms |
2640 KB |
Output is correct |
3 |
Correct |
1 ms |
2640 KB |
Output is correct |
4 |
Correct |
1 ms |
2640 KB |
Output is correct |
5 |
Correct |
2 ms |
2768 KB |
Output is correct |
6 |
Correct |
1 ms |
2768 KB |
Output is correct |
7 |
Correct |
1 ms |
2640 KB |
Output is correct |
8 |
Correct |
1 ms |
2640 KB |
Output is correct |
9 |
Correct |
1 ms |
2640 KB |
Output is correct |
10 |
Incorrect |
1 ms |
2640 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '458094764' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2768 KB |
Output is correct |
2 |
Correct |
1 ms |
2640 KB |
Output is correct |
3 |
Correct |
1 ms |
2640 KB |
Output is correct |
4 |
Correct |
1 ms |
2640 KB |
Output is correct |
5 |
Correct |
2 ms |
2768 KB |
Output is correct |
6 |
Correct |
1 ms |
2768 KB |
Output is correct |
7 |
Correct |
1 ms |
2640 KB |
Output is correct |
8 |
Correct |
1 ms |
2640 KB |
Output is correct |
9 |
Correct |
1 ms |
2640 KB |
Output is correct |
10 |
Incorrect |
1 ms |
2640 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '458094764' |
11 |
Halted |
0 ms |
0 KB |
- |