#include "circuit.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1'000'002'022;
int n, m;
vector<ll> storage;//When you call the constructor, make sure that everything is reduced modulo MOD
vector<int> a;
class Lazy{
public:
int L, R;
ll total_sum;
ll active;//MAKE SURE THAT THIS IS ALWAYS ACCURATE
bool flip;//When I need to flip, I don't need to flip myself, I need to flip my children only
Lazy* left;
Lazy* right;
Lazy()
{
L = 0; R = 0;
total_sum = 0; active = 0; flip = 0;
left = nullptr; right = nullptr;
}
Lazy(int l, int r)
{
L = l; R = r;
flip = 0;
if (L==R)
{
left = nullptr;
right = nullptr;
total_sum = storage[L];
if (a[L] == 1)
active = total_sum;
else
active = 0;
}
else
{
int mid = (l+r)/2;
left = new Lazy(l, mid);
right = new Lazy(mid+1, r);
total_sum = left->total_sum + right->total_sum;
active = left->active + right->active;
}
}
void update()
{
//assumption: My children could have just updated themselves, and so should I
if (left!=nullptr)
active = left->active + right->active;
}
void pancake_flip()
{
//assumption: this is updated, and I want to update myself
active = total_sum - active;
if (flip == 0)
flip = 1;
else
flip = 0;
}
void push_down()
{
//assumption: this is updated, and I want to update my children
if (flip == 1)
{
flip = 0;
if (left != nullptr)
{
left->pancake_flip();
right->pancake_flip();
}
}
}
void range_flip(int range_l, int range_r)
{
int intersect_l = max(range_l, L);
int intersect_r = min(range_r, R);
if ((intersect_l == L) and (intersect_r==R))
{
pancake_flip();
push_down();
}
else if (intersect_l <= intersect_r)
{
push_down();
left->range_flip(range_l, range_r);
right->range_flip(range_l, range_r);
update();
}
}
};
Lazy circ = Lazy();
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
n = N;
m = M;
vector<ll> degrees(N, 0);
for (int i=1; i<(N+M); i++)
degrees[P[i]]++;
vector<vector<bool>> ancestor(N+M, vector<bool> (N, 0));
for (int i=1; i<(N+M); i++)
{
int par = P[i];
for (int j=0; j<N; j++)
ancestor[i][j] = ancestor[par][j];
ancestor[i][par] = 1;
}
a = A;
for (int i=N; i<(N+M); i++)
{
ll ans = 1;
for (int j = 0; j<N; j++)
if (ancestor[i][j] == 0)
ans = (ans*degrees[j])%MOD;
storage.push_back(ans);
}
circ = Lazy(0, M-1);
}
int count_ways(int L, int R) {
L -= n;
R -= n;
circ.range_flip(L, R);
/*for (int i=L; i<=R; i++)
a[i] = 1-a[i];
ll total = 0;
for (int i=0; i<m; i++)
{
if (a[i]==1)
total = total+storage[i];
}*/
ll fa = circ.active%MOD;
int ffa = fa;
return ffa;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
600 KB |
Output is correct |
4 |
Correct |
0 ms |
600 KB |
Output is correct |
5 |
Correct |
0 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
0 ms |
600 KB |
Output is correct |
8 |
Correct |
0 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
3 ms |
600 KB |
Output is correct |
4 |
Correct |
4 ms |
600 KB |
Output is correct |
5 |
Correct |
3 ms |
564 KB |
Output is correct |
6 |
Correct |
6 ms |
600 KB |
Output is correct |
7 |
Correct |
11 ms |
824 KB |
Output is correct |
8 |
Correct |
11 ms |
856 KB |
Output is correct |
9 |
Correct |
11 ms |
824 KB |
Output is correct |
10 |
Correct |
10 ms |
856 KB |
Output is correct |
11 |
Correct |
9 ms |
820 KB |
Output is correct |
12 |
Correct |
8 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
600 KB |
Output is correct |
4 |
Correct |
0 ms |
600 KB |
Output is correct |
5 |
Correct |
0 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
0 ms |
600 KB |
Output is correct |
8 |
Correct |
0 ms |
600 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
3 ms |
600 KB |
Output is correct |
12 |
Correct |
4 ms |
600 KB |
Output is correct |
13 |
Correct |
3 ms |
564 KB |
Output is correct |
14 |
Correct |
6 ms |
600 KB |
Output is correct |
15 |
Correct |
11 ms |
824 KB |
Output is correct |
16 |
Correct |
11 ms |
856 KB |
Output is correct |
17 |
Correct |
11 ms |
824 KB |
Output is correct |
18 |
Correct |
10 ms |
856 KB |
Output is correct |
19 |
Correct |
9 ms |
820 KB |
Output is correct |
20 |
Correct |
8 ms |
600 KB |
Output is correct |
21 |
Correct |
7 ms |
600 KB |
Output is correct |
22 |
Correct |
6 ms |
640 KB |
Output is correct |
23 |
Correct |
5 ms |
600 KB |
Output is correct |
24 |
Correct |
11 ms |
824 KB |
Output is correct |
25 |
Correct |
11 ms |
856 KB |
Output is correct |
26 |
Correct |
11 ms |
856 KB |
Output is correct |
27 |
Correct |
11 ms |
816 KB |
Output is correct |
28 |
Correct |
11 ms |
856 KB |
Output is correct |
29 |
Correct |
1 ms |
600 KB |
Output is correct |
30 |
Correct |
1 ms |
600 KB |
Output is correct |
31 |
Correct |
4 ms |
608 KB |
Output is correct |
32 |
Correct |
11 ms |
832 KB |
Output is correct |
33 |
Correct |
5 ms |
612 KB |
Output is correct |
34 |
Correct |
3 ms |
612 KB |
Output is correct |
35 |
Correct |
0 ms |
612 KB |
Output is correct |
36 |
Correct |
10 ms |
868 KB |
Output is correct |
37 |
Correct |
8 ms |
868 KB |
Output is correct |
38 |
Correct |
8 ms |
868 KB |
Output is correct |
39 |
Correct |
4 ms |
620 KB |
Output is correct |
40 |
Correct |
5 ms |
600 KB |
Output is correct |
41 |
Correct |
3 ms |
600 KB |
Output is correct |
42 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3086 ms |
267600 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3086 ms |
267600 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
3 ms |
600 KB |
Output is correct |
4 |
Correct |
4 ms |
600 KB |
Output is correct |
5 |
Correct |
3 ms |
564 KB |
Output is correct |
6 |
Correct |
6 ms |
600 KB |
Output is correct |
7 |
Correct |
11 ms |
824 KB |
Output is correct |
8 |
Correct |
11 ms |
856 KB |
Output is correct |
9 |
Correct |
11 ms |
824 KB |
Output is correct |
10 |
Correct |
10 ms |
856 KB |
Output is correct |
11 |
Correct |
9 ms |
820 KB |
Output is correct |
12 |
Correct |
8 ms |
600 KB |
Output is correct |
13 |
Execution timed out |
3086 ms |
267600 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
600 KB |
Output is correct |
4 |
Correct |
0 ms |
600 KB |
Output is correct |
5 |
Correct |
0 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
0 ms |
600 KB |
Output is correct |
8 |
Correct |
0 ms |
600 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
3 ms |
600 KB |
Output is correct |
12 |
Correct |
4 ms |
600 KB |
Output is correct |
13 |
Correct |
3 ms |
564 KB |
Output is correct |
14 |
Correct |
6 ms |
600 KB |
Output is correct |
15 |
Correct |
11 ms |
824 KB |
Output is correct |
16 |
Correct |
11 ms |
856 KB |
Output is correct |
17 |
Correct |
11 ms |
824 KB |
Output is correct |
18 |
Correct |
10 ms |
856 KB |
Output is correct |
19 |
Correct |
9 ms |
820 KB |
Output is correct |
20 |
Correct |
8 ms |
600 KB |
Output is correct |
21 |
Correct |
7 ms |
600 KB |
Output is correct |
22 |
Correct |
6 ms |
640 KB |
Output is correct |
23 |
Correct |
5 ms |
600 KB |
Output is correct |
24 |
Correct |
11 ms |
824 KB |
Output is correct |
25 |
Correct |
11 ms |
856 KB |
Output is correct |
26 |
Correct |
11 ms |
856 KB |
Output is correct |
27 |
Correct |
11 ms |
816 KB |
Output is correct |
28 |
Correct |
11 ms |
856 KB |
Output is correct |
29 |
Correct |
1 ms |
600 KB |
Output is correct |
30 |
Correct |
1 ms |
600 KB |
Output is correct |
31 |
Correct |
4 ms |
608 KB |
Output is correct |
32 |
Correct |
11 ms |
832 KB |
Output is correct |
33 |
Correct |
5 ms |
612 KB |
Output is correct |
34 |
Correct |
3 ms |
612 KB |
Output is correct |
35 |
Correct |
0 ms |
612 KB |
Output is correct |
36 |
Correct |
10 ms |
868 KB |
Output is correct |
37 |
Correct |
8 ms |
868 KB |
Output is correct |
38 |
Correct |
8 ms |
868 KB |
Output is correct |
39 |
Correct |
4 ms |
620 KB |
Output is correct |
40 |
Correct |
5 ms |
600 KB |
Output is correct |
41 |
Correct |
3 ms |
600 KB |
Output is correct |
42 |
Correct |
1 ms |
600 KB |
Output is correct |
43 |
Correct |
533 ms |
3156 KB |
Output is correct |
44 |
Correct |
812 ms |
4432 KB |
Output is correct |
45 |
Correct |
773 ms |
3664 KB |
Output is correct |
46 |
Correct |
909 ms |
7736 KB |
Output is correct |
47 |
Correct |
898 ms |
7752 KB |
Output is correct |
48 |
Correct |
927 ms |
7744 KB |
Output is correct |
49 |
Correct |
913 ms |
7756 KB |
Output is correct |
50 |
Correct |
913 ms |
7756 KB |
Output is correct |
51 |
Correct |
608 ms |
1368 KB |
Output is correct |
52 |
Correct |
624 ms |
1368 KB |
Output is correct |
53 |
Correct |
680 ms |
3672 KB |
Output is correct |
54 |
Correct |
898 ms |
7760 KB |
Output is correct |
55 |
Correct |
790 ms |
3804 KB |
Output is correct |
56 |
Correct |
692 ms |
2384 KB |
Output is correct |
57 |
Correct |
641 ms |
1368 KB |
Output is correct |
58 |
Correct |
866 ms |
7760 KB |
Output is correct |
59 |
Correct |
826 ms |
7736 KB |
Output is correct |
60 |
Correct |
788 ms |
7760 KB |
Output is correct |
61 |
Correct |
744 ms |
4176 KB |
Output is correct |
62 |
Correct |
739 ms |
2640 KB |
Output is correct |
63 |
Correct |
692 ms |
2052 KB |
Output is correct |
64 |
Correct |
626 ms |
1368 KB |
Output is correct |
65 |
Correct |
379 ms |
1872 KB |
Output is correct |
66 |
Correct |
840 ms |
5620 KB |
Output is correct |
67 |
Correct |
849 ms |
5456 KB |
Output is correct |
68 |
Correct |
808 ms |
5456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
600 KB |
Output is correct |
4 |
Correct |
0 ms |
600 KB |
Output is correct |
5 |
Correct |
0 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
0 ms |
600 KB |
Output is correct |
8 |
Correct |
0 ms |
600 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
3 ms |
600 KB |
Output is correct |
12 |
Correct |
4 ms |
600 KB |
Output is correct |
13 |
Correct |
3 ms |
564 KB |
Output is correct |
14 |
Correct |
6 ms |
600 KB |
Output is correct |
15 |
Correct |
11 ms |
824 KB |
Output is correct |
16 |
Correct |
11 ms |
856 KB |
Output is correct |
17 |
Correct |
11 ms |
824 KB |
Output is correct |
18 |
Correct |
10 ms |
856 KB |
Output is correct |
19 |
Correct |
9 ms |
820 KB |
Output is correct |
20 |
Correct |
8 ms |
600 KB |
Output is correct |
21 |
Correct |
7 ms |
600 KB |
Output is correct |
22 |
Correct |
6 ms |
640 KB |
Output is correct |
23 |
Correct |
5 ms |
600 KB |
Output is correct |
24 |
Correct |
11 ms |
824 KB |
Output is correct |
25 |
Correct |
11 ms |
856 KB |
Output is correct |
26 |
Correct |
11 ms |
856 KB |
Output is correct |
27 |
Correct |
11 ms |
816 KB |
Output is correct |
28 |
Correct |
11 ms |
856 KB |
Output is correct |
29 |
Correct |
1 ms |
600 KB |
Output is correct |
30 |
Correct |
1 ms |
600 KB |
Output is correct |
31 |
Correct |
4 ms |
608 KB |
Output is correct |
32 |
Correct |
11 ms |
832 KB |
Output is correct |
33 |
Correct |
5 ms |
612 KB |
Output is correct |
34 |
Correct |
3 ms |
612 KB |
Output is correct |
35 |
Correct |
0 ms |
612 KB |
Output is correct |
36 |
Correct |
10 ms |
868 KB |
Output is correct |
37 |
Correct |
8 ms |
868 KB |
Output is correct |
38 |
Correct |
8 ms |
868 KB |
Output is correct |
39 |
Correct |
4 ms |
620 KB |
Output is correct |
40 |
Correct |
5 ms |
600 KB |
Output is correct |
41 |
Correct |
3 ms |
600 KB |
Output is correct |
42 |
Correct |
1 ms |
600 KB |
Output is correct |
43 |
Execution timed out |
3086 ms |
267600 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |