#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
const long long mod = 1e9 + 2022;
int n, m;
vector<int> g[maxn];
long long contribution[maxn];
long long power(long long a, long long b)
{
if (b == 0)
{
return 1LL;
}
if (b % 2 == 0)
{
long long result = power(a, b / 2);
return (result * result) % mod;
}
return (a * power(a, b - 1)) % mod;
}
void dfs(int node, int dep)
{
if (g[node].empty())
{
contribution[node] = power(2, n - dep);
return;
}
for (int i = 0; i < g[node].size(); ++i)
{
dfs(g[node][i], dep + 1);
}
}
long long preffix[maxn];
long long get_sum(int l, int r)
{
if (l == 0)
{
return preffix[r];
}
return (preffix[r] - preffix[l - 1] + mod) % mod;
}
struct segment_tree
{
struct vertex
{
long long sum;
bool lazy;
vertex()
{
sum = 0;
lazy = false;
}
vertex(long long _sum, bool _lazy)
{
sum = _sum;
lazy = _lazy;
}
};
vertex tree[4 * maxn];
void push_lazy(int node, int l, int r)
{
if (tree[node].lazy == true)
{
tree[node].sum = (get_sum(l, r) - tree[node].sum + mod) % mod;
if (l != r)
{
tree[2 * node].lazy = 1 - tree[2 * node].lazy;
tree[2 * node + 1].lazy = 1 - tree[2 * node + 1].lazy;
}
tree[node].lazy = false;
}
}
void update(int node, int l, int r, int ql, int qr)
{
push_lazy(node, l, r);
if (l > qr || r < ql)
{
return;
}
if (ql <= l && r <= qr)
{
tree[node].lazy = true;
push_lazy(node, l, r);
return;
}
int mid = (l + r) / 2;
update(2 * node, l, mid, ql, qr);
update(2 * node + 1, mid + 1, r, ql, qr);
tree[node].sum = (tree[2 * node].sum + tree[2 * node + 1].sum) % mod;
}
void update(int l, int r)
{
update(1, 0, m - 1, l, r);
}
};
segment_tree tree;
void init(int N, int M, vector<int> P, vector<int> A)
{
n = N;
m = M;
for (int i = 1; i < P.size(); ++i)
{
g[P[i]].push_back(i);
}
dfs(0, 0);
for (int i = 0; i < m; ++i)
{
preffix[i] = contribution[i + n];
if (i > 0)
{
preffix[i] += preffix[i - 1];
}
preffix[i] %= mod;
}
for (int i = 0; i < m; ++i)
{
if (A[i] == 1)
{
tree.update(i, i);
}
}
}
int count_ways(int L, int R)
{
int l = L - n;
int r = R - n;
tree.update(l, r);
return tree.tree[1].sum;
}
Compilation message
circuit.cpp: In function 'void dfs(int, int)':
circuit.cpp:40:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | for (int i = 0; i < g[node].size(); ++i)
| ~~^~~~~~~~~~~~~~~~
circuit.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>)':
circuit.cpp:133:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
133 | for (int i = 1; i < P.size(); ++i)
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
17488 KB |
Output is correct |
2 |
Correct |
8 ms |
17488 KB |
Output is correct |
3 |
Correct |
8 ms |
17488 KB |
Output is correct |
4 |
Correct |
8 ms |
17488 KB |
Output is correct |
5 |
Correct |
8 ms |
17460 KB |
Output is correct |
6 |
Correct |
8 ms |
17480 KB |
Output is correct |
7 |
Correct |
7 ms |
17488 KB |
Output is correct |
8 |
Correct |
7 ms |
17488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
17476 KB |
Output is correct |
2 |
Correct |
7 ms |
17488 KB |
Output is correct |
3 |
Correct |
7 ms |
17488 KB |
Output is correct |
4 |
Correct |
7 ms |
17488 KB |
Output is correct |
5 |
Correct |
7 ms |
17524 KB |
Output is correct |
6 |
Correct |
8 ms |
17488 KB |
Output is correct |
7 |
Correct |
9 ms |
17560 KB |
Output is correct |
8 |
Correct |
9 ms |
17472 KB |
Output is correct |
9 |
Correct |
8 ms |
17488 KB |
Output is correct |
10 |
Correct |
8 ms |
17616 KB |
Output is correct |
11 |
Correct |
8 ms |
17616 KB |
Output is correct |
12 |
Correct |
8 ms |
17488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
17488 KB |
Output is correct |
2 |
Correct |
8 ms |
17488 KB |
Output is correct |
3 |
Correct |
8 ms |
17488 KB |
Output is correct |
4 |
Correct |
8 ms |
17488 KB |
Output is correct |
5 |
Correct |
8 ms |
17460 KB |
Output is correct |
6 |
Correct |
8 ms |
17480 KB |
Output is correct |
7 |
Correct |
7 ms |
17488 KB |
Output is correct |
8 |
Correct |
7 ms |
17488 KB |
Output is correct |
9 |
Correct |
7 ms |
17476 KB |
Output is correct |
10 |
Correct |
7 ms |
17488 KB |
Output is correct |
11 |
Correct |
7 ms |
17488 KB |
Output is correct |
12 |
Correct |
7 ms |
17488 KB |
Output is correct |
13 |
Correct |
7 ms |
17524 KB |
Output is correct |
14 |
Correct |
8 ms |
17488 KB |
Output is correct |
15 |
Correct |
9 ms |
17560 KB |
Output is correct |
16 |
Correct |
9 ms |
17472 KB |
Output is correct |
17 |
Correct |
8 ms |
17488 KB |
Output is correct |
18 |
Correct |
8 ms |
17616 KB |
Output is correct |
19 |
Correct |
8 ms |
17616 KB |
Output is correct |
20 |
Correct |
8 ms |
17488 KB |
Output is correct |
21 |
Incorrect |
8 ms |
17488 KB |
1st lines differ - on the 1st token, expected: '759476520', found: '833967706' |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
594 ms |
19832 KB |
Output is correct |
2 |
Correct |
483 ms |
22128 KB |
Output is correct |
3 |
Correct |
728 ms |
22088 KB |
Output is correct |
4 |
Correct |
718 ms |
22216 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
594 ms |
19832 KB |
Output is correct |
2 |
Correct |
483 ms |
22128 KB |
Output is correct |
3 |
Correct |
728 ms |
22088 KB |
Output is correct |
4 |
Correct |
718 ms |
22216 KB |
Output is correct |
5 |
Correct |
555 ms |
19856 KB |
Output is correct |
6 |
Correct |
807 ms |
22088 KB |
Output is correct |
7 |
Correct |
702 ms |
22124 KB |
Output is correct |
8 |
Correct |
897 ms |
22144 KB |
Output is correct |
9 |
Correct |
371 ms |
17616 KB |
Output is correct |
10 |
Correct |
576 ms |
17744 KB |
Output is correct |
11 |
Correct |
631 ms |
17744 KB |
Output is correct |
12 |
Correct |
714 ms |
17744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
17476 KB |
Output is correct |
2 |
Correct |
7 ms |
17488 KB |
Output is correct |
3 |
Correct |
7 ms |
17488 KB |
Output is correct |
4 |
Correct |
7 ms |
17488 KB |
Output is correct |
5 |
Correct |
7 ms |
17524 KB |
Output is correct |
6 |
Correct |
8 ms |
17488 KB |
Output is correct |
7 |
Correct |
9 ms |
17560 KB |
Output is correct |
8 |
Correct |
9 ms |
17472 KB |
Output is correct |
9 |
Correct |
8 ms |
17488 KB |
Output is correct |
10 |
Correct |
8 ms |
17616 KB |
Output is correct |
11 |
Correct |
8 ms |
17616 KB |
Output is correct |
12 |
Correct |
8 ms |
17488 KB |
Output is correct |
13 |
Correct |
594 ms |
19832 KB |
Output is correct |
14 |
Correct |
483 ms |
22128 KB |
Output is correct |
15 |
Correct |
728 ms |
22088 KB |
Output is correct |
16 |
Correct |
718 ms |
22216 KB |
Output is correct |
17 |
Correct |
555 ms |
19856 KB |
Output is correct |
18 |
Correct |
807 ms |
22088 KB |
Output is correct |
19 |
Correct |
702 ms |
22124 KB |
Output is correct |
20 |
Correct |
897 ms |
22144 KB |
Output is correct |
21 |
Correct |
371 ms |
17616 KB |
Output is correct |
22 |
Correct |
576 ms |
17744 KB |
Output is correct |
23 |
Correct |
631 ms |
17744 KB |
Output is correct |
24 |
Correct |
714 ms |
17744 KB |
Output is correct |
25 |
Correct |
812 ms |
24392 KB |
Output is correct |
26 |
Correct |
728 ms |
24452 KB |
Output is correct |
27 |
Correct |
811 ms |
24508 KB |
Output is correct |
28 |
Correct |
788 ms |
24556 KB |
Output is correct |
29 |
Correct |
861 ms |
29200 KB |
Output is correct |
30 |
Correct |
774 ms |
29188 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
17488 KB |
Output is correct |
2 |
Correct |
8 ms |
17488 KB |
Output is correct |
3 |
Correct |
8 ms |
17488 KB |
Output is correct |
4 |
Correct |
8 ms |
17488 KB |
Output is correct |
5 |
Correct |
8 ms |
17460 KB |
Output is correct |
6 |
Correct |
8 ms |
17480 KB |
Output is correct |
7 |
Correct |
7 ms |
17488 KB |
Output is correct |
8 |
Correct |
7 ms |
17488 KB |
Output is correct |
9 |
Correct |
7 ms |
17476 KB |
Output is correct |
10 |
Correct |
7 ms |
17488 KB |
Output is correct |
11 |
Correct |
7 ms |
17488 KB |
Output is correct |
12 |
Correct |
7 ms |
17488 KB |
Output is correct |
13 |
Correct |
7 ms |
17524 KB |
Output is correct |
14 |
Correct |
8 ms |
17488 KB |
Output is correct |
15 |
Correct |
9 ms |
17560 KB |
Output is correct |
16 |
Correct |
9 ms |
17472 KB |
Output is correct |
17 |
Correct |
8 ms |
17488 KB |
Output is correct |
18 |
Correct |
8 ms |
17616 KB |
Output is correct |
19 |
Correct |
8 ms |
17616 KB |
Output is correct |
20 |
Correct |
8 ms |
17488 KB |
Output is correct |
21 |
Incorrect |
8 ms |
17488 KB |
1st lines differ - on the 1st token, expected: '759476520', found: '833967706' |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
17488 KB |
Output is correct |
2 |
Correct |
8 ms |
17488 KB |
Output is correct |
3 |
Correct |
8 ms |
17488 KB |
Output is correct |
4 |
Correct |
8 ms |
17488 KB |
Output is correct |
5 |
Correct |
8 ms |
17460 KB |
Output is correct |
6 |
Correct |
8 ms |
17480 KB |
Output is correct |
7 |
Correct |
7 ms |
17488 KB |
Output is correct |
8 |
Correct |
7 ms |
17488 KB |
Output is correct |
9 |
Correct |
7 ms |
17476 KB |
Output is correct |
10 |
Correct |
7 ms |
17488 KB |
Output is correct |
11 |
Correct |
7 ms |
17488 KB |
Output is correct |
12 |
Correct |
7 ms |
17488 KB |
Output is correct |
13 |
Correct |
7 ms |
17524 KB |
Output is correct |
14 |
Correct |
8 ms |
17488 KB |
Output is correct |
15 |
Correct |
9 ms |
17560 KB |
Output is correct |
16 |
Correct |
9 ms |
17472 KB |
Output is correct |
17 |
Correct |
8 ms |
17488 KB |
Output is correct |
18 |
Correct |
8 ms |
17616 KB |
Output is correct |
19 |
Correct |
8 ms |
17616 KB |
Output is correct |
20 |
Correct |
8 ms |
17488 KB |
Output is correct |
21 |
Incorrect |
8 ms |
17488 KB |
1st lines differ - on the 1st token, expected: '759476520', found: '833967706' |
22 |
Halted |
0 ms |
0 KB |
- |