#include <bits/stdc++.h>
#include "circuit.h"
using namespace std;
const int BASE = 1e9 + 2022;
const int N = 100100;
int n, m;
vector<int> a[N];
vector<int> states;
vector<long long> coef;
long long ans;
void dfs(int x)
{
vector<long long> prefix(size(a[x]));
for (int i = 0; i < size(a[x]); i++)
{
int y = a[x][i];
prefix[i] = max(1, int(size(a[y])));
if (i)
prefix[i] = prefix[i] * prefix[i - 1] % BASE;
}
long long suffix = 1;
for (int i = int(size(a[x])) - 1; i >= 0; i--)
{
int y = a[x][i];
coef[y] = suffix;
if (i)
coef[y] = coef[y] * prefix[i - 1] % BASE;
suffix *= max(1, int(size(a[y])));
suffix %= BASE;
}
for (int y : a[x])
{
coef[y] = coef[y] * coef[x] % BASE;
dfs(y);
}
}
void init(int N, int M, vector<int> P, vector<int> A)
{
n = N;
m = M;
for (int i = 1; i < n + m; i++)
a[P[i]].push_back(i);
states = A;
coef.assign(n + m, 1);
dfs(0);
for (int i = 0; i < m; i++)
if (states[i])
ans = (ans + coef[n + i]) % BASE;
}
int count_ways(int L, int R)
{
for (int i = L; i <= R; i++)
{
states[i - n] ^= 1;
if (states[i - n]) ans = (ans + coef[i]) % BASE;
else ans = (ans - coef[i] + BASE) % BASE;
}
return ans;
}
Compilation message
circuit.cpp: In function 'void dfs(int)':
circuit.cpp:16:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
16 | for (int i = 0; i < size(a[x]); i++)
| ~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2640 KB |
Output is correct |
2 |
Correct |
1 ms |
2640 KB |
Output is correct |
3 |
Correct |
2 ms |
2640 KB |
Output is correct |
4 |
Correct |
2 ms |
2640 KB |
Output is correct |
5 |
Correct |
1 ms |
2640 KB |
Output is correct |
6 |
Correct |
2 ms |
2640 KB |
Output is correct |
7 |
Correct |
2 ms |
2640 KB |
Output is correct |
8 |
Correct |
2 ms |
2672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2640 KB |
Output is correct |
2 |
Incorrect |
2 ms |
2672 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '16384' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2640 KB |
Output is correct |
2 |
Correct |
1 ms |
2640 KB |
Output is correct |
3 |
Correct |
2 ms |
2640 KB |
Output is correct |
4 |
Correct |
2 ms |
2640 KB |
Output is correct |
5 |
Correct |
1 ms |
2640 KB |
Output is correct |
6 |
Correct |
2 ms |
2640 KB |
Output is correct |
7 |
Correct |
2 ms |
2640 KB |
Output is correct |
8 |
Correct |
2 ms |
2672 KB |
Output is correct |
9 |
Correct |
1 ms |
2640 KB |
Output is correct |
10 |
Incorrect |
2 ms |
2672 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '16384' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
830 ms |
5088 KB |
1st lines differ - on the 1st token, expected: '431985922', found: '268730368' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
830 ms |
5088 KB |
1st lines differ - on the 1st token, expected: '431985922', found: '268730368' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2640 KB |
Output is correct |
2 |
Incorrect |
2 ms |
2672 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '16384' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2640 KB |
Output is correct |
2 |
Correct |
1 ms |
2640 KB |
Output is correct |
3 |
Correct |
2 ms |
2640 KB |
Output is correct |
4 |
Correct |
2 ms |
2640 KB |
Output is correct |
5 |
Correct |
1 ms |
2640 KB |
Output is correct |
6 |
Correct |
2 ms |
2640 KB |
Output is correct |
7 |
Correct |
2 ms |
2640 KB |
Output is correct |
8 |
Correct |
2 ms |
2672 KB |
Output is correct |
9 |
Correct |
1 ms |
2640 KB |
Output is correct |
10 |
Incorrect |
2 ms |
2672 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '16384' |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2640 KB |
Output is correct |
2 |
Correct |
1 ms |
2640 KB |
Output is correct |
3 |
Correct |
2 ms |
2640 KB |
Output is correct |
4 |
Correct |
2 ms |
2640 KB |
Output is correct |
5 |
Correct |
1 ms |
2640 KB |
Output is correct |
6 |
Correct |
2 ms |
2640 KB |
Output is correct |
7 |
Correct |
2 ms |
2640 KB |
Output is correct |
8 |
Correct |
2 ms |
2672 KB |
Output is correct |
9 |
Correct |
1 ms |
2640 KB |
Output is correct |
10 |
Incorrect |
2 ms |
2672 KB |
1st lines differ - on the 1st token, expected: '52130940', found: '16384' |
11 |
Halted |
0 ms |
0 KB |
- |