#include "circuit.h"
//#include "stub.cpp"
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD= 1000002022;
struct node
{
node* left, *right;
int allume, eteint;
void update()
{
int comp=0;
comp+=(left->eteint*right->allume)%MOD;
comp+=(left->allume*right->eteint)%MOD;
comp%=MOD;
allume=comp+(left->allume*right->allume*2);
eteint=comp+(left->eteint*right->eteint*2);
allume%=MOD, eteint%=MOD;
}
};
/*int query(node* root, int left, int right, int qLeft, int qRight)
{
if (left>qRight || right<qLeft) return 0;
if (left>=qLeft && right<=qRight) return root->sum;
int mid=(left+right)/2;
return query(root->left, left, mid, qLeft, qRight)+query(root->right, mid+1, right, qLeft, qRight);
}*/
void update(node* root, int left, int right, int qLeft, int qRight)
{
if (left>qRight || right<qLeft) return;
if (left==right)
{
root->allume^=1;
root->eteint^=1;
return;
}
int mid=(left+right)/2;
update(root->left, left, mid, qLeft, qRight);
update(root->right, mid+1, right, qLeft, qRight);
root->update();
}
void build(node* root, int left, int right, const vector<signed> &v)
{
if (left==right)
{
root->allume=v[left];
root->eteint=v[left]^1;
return;
}
root->left=new node{NULL, NULL, 0, 0};
root->right=new node{NULL, NULL, 0, 0};
int mid=(left+right)/2;
build(root->left, left, mid, v);
build(root->right, mid+1, right, v);
root->update();
}
void destroy(node* root)
{
if (root->left) destroy(root->left);
if (root->right) destroy(root->right);
delete root;
}
vector<signed> a;
vector<int> adj[100005];
int n, m;
pair<int, int> dfs(int s) {
if (s>=n) {
return {a[s-n], a[s-n]^1};
}
vector<int> dp(adj[s].size()+1, 0);
dp[0]=1;
for (auto u: adj[s]) {
auto act=dfs(u);
for (int i=dp.size()-1; i>=0; i--) {
dp[i]=(dp[i]*act.second)%MOD;
if (i>0) {
dp[i]+=(dp[i-1]*act.first)%MOD;
}
dp[i]%=MOD;
}
}
pair<int, int> ans={0, 0};
for (int i=1; i<(int)dp.size()-1; i++) {
ans.first+=(dp[i]*i)%MOD;
ans.second+=(dp[i]*(dp.size()-i-1));
ans.first%=MOD, ans.second%=MOD;
}
ans.first+=dp[dp.size()-1]*(dp.size()-1);
ans.second+=dp[0]*(dp.size()-1);
return {ans.first%MOD, ans.second%MOD};
}
bool subtask5=false;
node *root=new node{NULL, NULL, 0, 0};
#undef int
void init(int N, int M, vector<int> p, vector<int> aa) {
a=aa;
n=N, m=M;
for (int i=1; i<n+m; i++) {
adj[p[i]].push_back(i);
}
if (m!=n+1) return;
int power=1;
while (power<m) power*=2;
if (power!=m) return;
subtask5=true;
build(root, 0, m-1, a);
}
int count_ways(int L, int R) {
#define int long long
if (subtask5) {
update(root, 0, m-1, L-n, R-n);
return root->allume;
}
for (int i=L; i<=R; i++) {
a[i-n]^=1;
}
return dfs(0).first;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2648 KB |
Output is correct |
3 |
Correct |
16 ms |
2648 KB |
Output is correct |
4 |
Correct |
17 ms |
2648 KB |
Output is correct |
5 |
Correct |
17 ms |
2648 KB |
Output is correct |
6 |
Correct |
17 ms |
2648 KB |
Output is correct |
7 |
Correct |
17 ms |
2648 KB |
Output is correct |
8 |
Correct |
17 ms |
2816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2648 KB |
Output is correct |
3 |
Correct |
1 ms |
2648 KB |
Output is correct |
4 |
Correct |
2 ms |
2648 KB |
Output is correct |
5 |
Correct |
1 ms |
2648 KB |
Output is correct |
6 |
Correct |
1 ms |
2648 KB |
Output is correct |
7 |
Correct |
1 ms |
2648 KB |
Output is correct |
8 |
Correct |
1 ms |
2648 KB |
Output is correct |
9 |
Correct |
1 ms |
2648 KB |
Output is correct |
10 |
Correct |
2 ms |
2904 KB |
Output is correct |
11 |
Correct |
1 ms |
2904 KB |
Output is correct |
12 |
Correct |
1 ms |
2648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2648 KB |
Output is correct |
3 |
Correct |
16 ms |
2648 KB |
Output is correct |
4 |
Correct |
17 ms |
2648 KB |
Output is correct |
5 |
Correct |
17 ms |
2648 KB |
Output is correct |
6 |
Correct |
17 ms |
2648 KB |
Output is correct |
7 |
Correct |
17 ms |
2648 KB |
Output is correct |
8 |
Correct |
17 ms |
2816 KB |
Output is correct |
9 |
Correct |
1 ms |
2648 KB |
Output is correct |
10 |
Correct |
1 ms |
2648 KB |
Output is correct |
11 |
Correct |
1 ms |
2648 KB |
Output is correct |
12 |
Correct |
2 ms |
2648 KB |
Output is correct |
13 |
Correct |
1 ms |
2648 KB |
Output is correct |
14 |
Correct |
1 ms |
2648 KB |
Output is correct |
15 |
Correct |
1 ms |
2648 KB |
Output is correct |
16 |
Correct |
1 ms |
2648 KB |
Output is correct |
17 |
Correct |
1 ms |
2648 KB |
Output is correct |
18 |
Correct |
2 ms |
2904 KB |
Output is correct |
19 |
Correct |
1 ms |
2904 KB |
Output is correct |
20 |
Correct |
1 ms |
2648 KB |
Output is correct |
21 |
Correct |
1 ms |
2648 KB |
Output is correct |
22 |
Correct |
2 ms |
2648 KB |
Output is correct |
23 |
Correct |
1 ms |
2648 KB |
Output is correct |
24 |
Correct |
1 ms |
2648 KB |
Output is correct |
25 |
Correct |
1 ms |
2648 KB |
Output is correct |
26 |
Correct |
1 ms |
2648 KB |
Output is correct |
27 |
Correct |
1 ms |
2648 KB |
Output is correct |
28 |
Correct |
2 ms |
2648 KB |
Output is correct |
29 |
Correct |
17 ms |
2648 KB |
Output is correct |
30 |
Correct |
17 ms |
2648 KB |
Output is correct |
31 |
Correct |
1 ms |
2904 KB |
Output is correct |
32 |
Correct |
1 ms |
2648 KB |
Output is correct |
33 |
Correct |
1 ms |
2648 KB |
Output is correct |
34 |
Correct |
1 ms |
2648 KB |
Output is correct |
35 |
Correct |
4 ms |
2648 KB |
Output is correct |
36 |
Correct |
1 ms |
2904 KB |
Output is correct |
37 |
Correct |
17 ms |
2904 KB |
Output is correct |
38 |
Correct |
18 ms |
2904 KB |
Output is correct |
39 |
Correct |
1 ms |
2648 KB |
Output is correct |
40 |
Correct |
1 ms |
2648 KB |
Output is correct |
41 |
Correct |
1 ms |
2648 KB |
Output is correct |
42 |
Correct |
1 ms |
2648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
367 ms |
7768 KB |
Output is correct |
2 |
Correct |
593 ms |
12780 KB |
Output is correct |
3 |
Correct |
556 ms |
12780 KB |
Output is correct |
4 |
Correct |
570 ms |
12788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
367 ms |
7768 KB |
Output is correct |
2 |
Correct |
593 ms |
12780 KB |
Output is correct |
3 |
Correct |
556 ms |
12780 KB |
Output is correct |
4 |
Correct |
570 ms |
12788 KB |
Output is correct |
5 |
Execution timed out |
3062 ms |
7768 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2648 KB |
Output is correct |
3 |
Correct |
1 ms |
2648 KB |
Output is correct |
4 |
Correct |
2 ms |
2648 KB |
Output is correct |
5 |
Correct |
1 ms |
2648 KB |
Output is correct |
6 |
Correct |
1 ms |
2648 KB |
Output is correct |
7 |
Correct |
1 ms |
2648 KB |
Output is correct |
8 |
Correct |
1 ms |
2648 KB |
Output is correct |
9 |
Correct |
1 ms |
2648 KB |
Output is correct |
10 |
Correct |
2 ms |
2904 KB |
Output is correct |
11 |
Correct |
1 ms |
2904 KB |
Output is correct |
12 |
Correct |
1 ms |
2648 KB |
Output is correct |
13 |
Correct |
367 ms |
7768 KB |
Output is correct |
14 |
Correct |
593 ms |
12780 KB |
Output is correct |
15 |
Correct |
556 ms |
12780 KB |
Output is correct |
16 |
Correct |
570 ms |
12788 KB |
Output is correct |
17 |
Execution timed out |
3062 ms |
7768 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2648 KB |
Output is correct |
3 |
Correct |
16 ms |
2648 KB |
Output is correct |
4 |
Correct |
17 ms |
2648 KB |
Output is correct |
5 |
Correct |
17 ms |
2648 KB |
Output is correct |
6 |
Correct |
17 ms |
2648 KB |
Output is correct |
7 |
Correct |
17 ms |
2648 KB |
Output is correct |
8 |
Correct |
17 ms |
2816 KB |
Output is correct |
9 |
Correct |
1 ms |
2648 KB |
Output is correct |
10 |
Correct |
1 ms |
2648 KB |
Output is correct |
11 |
Correct |
1 ms |
2648 KB |
Output is correct |
12 |
Correct |
2 ms |
2648 KB |
Output is correct |
13 |
Correct |
1 ms |
2648 KB |
Output is correct |
14 |
Correct |
1 ms |
2648 KB |
Output is correct |
15 |
Correct |
1 ms |
2648 KB |
Output is correct |
16 |
Correct |
1 ms |
2648 KB |
Output is correct |
17 |
Correct |
1 ms |
2648 KB |
Output is correct |
18 |
Correct |
2 ms |
2904 KB |
Output is correct |
19 |
Correct |
1 ms |
2904 KB |
Output is correct |
20 |
Correct |
1 ms |
2648 KB |
Output is correct |
21 |
Correct |
1 ms |
2648 KB |
Output is correct |
22 |
Correct |
2 ms |
2648 KB |
Output is correct |
23 |
Correct |
1 ms |
2648 KB |
Output is correct |
24 |
Correct |
1 ms |
2648 KB |
Output is correct |
25 |
Correct |
1 ms |
2648 KB |
Output is correct |
26 |
Correct |
1 ms |
2648 KB |
Output is correct |
27 |
Correct |
1 ms |
2648 KB |
Output is correct |
28 |
Correct |
2 ms |
2648 KB |
Output is correct |
29 |
Correct |
17 ms |
2648 KB |
Output is correct |
30 |
Correct |
17 ms |
2648 KB |
Output is correct |
31 |
Correct |
1 ms |
2904 KB |
Output is correct |
32 |
Correct |
1 ms |
2648 KB |
Output is correct |
33 |
Correct |
1 ms |
2648 KB |
Output is correct |
34 |
Correct |
1 ms |
2648 KB |
Output is correct |
35 |
Correct |
4 ms |
2648 KB |
Output is correct |
36 |
Correct |
1 ms |
2904 KB |
Output is correct |
37 |
Correct |
17 ms |
2904 KB |
Output is correct |
38 |
Correct |
18 ms |
2904 KB |
Output is correct |
39 |
Correct |
1 ms |
2648 KB |
Output is correct |
40 |
Correct |
1 ms |
2648 KB |
Output is correct |
41 |
Correct |
1 ms |
2648 KB |
Output is correct |
42 |
Correct |
1 ms |
2648 KB |
Output is correct |
43 |
Execution timed out |
3014 ms |
2904 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2648 KB |
Output is correct |
3 |
Correct |
16 ms |
2648 KB |
Output is correct |
4 |
Correct |
17 ms |
2648 KB |
Output is correct |
5 |
Correct |
17 ms |
2648 KB |
Output is correct |
6 |
Correct |
17 ms |
2648 KB |
Output is correct |
7 |
Correct |
17 ms |
2648 KB |
Output is correct |
8 |
Correct |
17 ms |
2816 KB |
Output is correct |
9 |
Correct |
1 ms |
2648 KB |
Output is correct |
10 |
Correct |
1 ms |
2648 KB |
Output is correct |
11 |
Correct |
1 ms |
2648 KB |
Output is correct |
12 |
Correct |
2 ms |
2648 KB |
Output is correct |
13 |
Correct |
1 ms |
2648 KB |
Output is correct |
14 |
Correct |
1 ms |
2648 KB |
Output is correct |
15 |
Correct |
1 ms |
2648 KB |
Output is correct |
16 |
Correct |
1 ms |
2648 KB |
Output is correct |
17 |
Correct |
1 ms |
2648 KB |
Output is correct |
18 |
Correct |
2 ms |
2904 KB |
Output is correct |
19 |
Correct |
1 ms |
2904 KB |
Output is correct |
20 |
Correct |
1 ms |
2648 KB |
Output is correct |
21 |
Correct |
1 ms |
2648 KB |
Output is correct |
22 |
Correct |
2 ms |
2648 KB |
Output is correct |
23 |
Correct |
1 ms |
2648 KB |
Output is correct |
24 |
Correct |
1 ms |
2648 KB |
Output is correct |
25 |
Correct |
1 ms |
2648 KB |
Output is correct |
26 |
Correct |
1 ms |
2648 KB |
Output is correct |
27 |
Correct |
1 ms |
2648 KB |
Output is correct |
28 |
Correct |
2 ms |
2648 KB |
Output is correct |
29 |
Correct |
17 ms |
2648 KB |
Output is correct |
30 |
Correct |
17 ms |
2648 KB |
Output is correct |
31 |
Correct |
1 ms |
2904 KB |
Output is correct |
32 |
Correct |
1 ms |
2648 KB |
Output is correct |
33 |
Correct |
1 ms |
2648 KB |
Output is correct |
34 |
Correct |
1 ms |
2648 KB |
Output is correct |
35 |
Correct |
4 ms |
2648 KB |
Output is correct |
36 |
Correct |
1 ms |
2904 KB |
Output is correct |
37 |
Correct |
17 ms |
2904 KB |
Output is correct |
38 |
Correct |
18 ms |
2904 KB |
Output is correct |
39 |
Correct |
1 ms |
2648 KB |
Output is correct |
40 |
Correct |
1 ms |
2648 KB |
Output is correct |
41 |
Correct |
1 ms |
2648 KB |
Output is correct |
42 |
Correct |
1 ms |
2648 KB |
Output is correct |
43 |
Correct |
367 ms |
7768 KB |
Output is correct |
44 |
Correct |
593 ms |
12780 KB |
Output is correct |
45 |
Correct |
556 ms |
12780 KB |
Output is correct |
46 |
Correct |
570 ms |
12788 KB |
Output is correct |
47 |
Execution timed out |
3062 ms |
7768 KB |
Time limit exceeded |
48 |
Halted |
0 ms |
0 KB |
- |