#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pll pair<long long, long long>
#define MOD 1000002022ll
#define xx first
#define yy second
using namespace std;
typedef long long ll;
struct node {
ll l, r, sum;
bool flip;
node *left, *right;
node(ll l, ll r): l(l), r(r), sum(0), flip(false), left(nullptr), right(nullptr) {};
};
vector<ll> p, prd, w, cmw, makew;
vector<vector<ll>> ch;
ll pref[200200], n;
node *tree;
ll zbir(ll l, ll r) {
return (pref[r]-(l==0?0:pref[l-1])+MOD)%MOD;
}
void flip(node *cur) {
if(cur==nullptr) return;
cur->flip=!cur->flip;
cur->sum=zbir(cur->l, cur->r)-cur->sum;
}
void flipprop(node *cur) {
if(cur->flip) {
cur->flip=false;
flip(cur->left);
flip(cur->right);
}
}
void fix(node *cur) {
flipprop(cur);
if(cur->l!=cur->r) {
flipprop(cur->left);
flipprop(cur->right);
cur->sum=(cur->left->sum+cur->right->sum)%MOD;
}
}
node *build(ll l, ll r) {
node *cur=new node(l, r);
if(l!=r) {
ll m=(l+r)/2;
cur->left=build(l, m);
cur->right=build(m+1, r);
}
return cur;
}
void flipi(node *cur, ll l, ll r) {
//cout<<l<<' '<<r<<" "<<cur->l<<' '<<cur->r<<'\n';
if(l>r) return;
if(cur->l==l&&cur->r==r) {
flip(cur);
return;
}
flipi(cur->left, l, min(r, cur->left->r));
flipi(cur->right, max(l, cur->right->l), r);
fix(cur);
//cout<<cur->l<<' '<<cur->r<<' '<<cur->sum<<'\n';
}
ll saberisve() {
return tree->sum;
}
void solvew(ll l, ll r, ll mul) {
if(l>r) exit(-1);
if(l!=r) {
ll m=(l+r)/2;
ll nml=mul;
for(ll i=l; i<=m; i++) {
nml*=prd[makew[i]];
nml%=MOD;
}
solvew(m+1, r, nml);
nml=mul;
for(ll i=m+1; i<=r; i++) {
nml*=prd[makew[i]];
nml%=MOD;
}
solvew(l, m, nml);
return;
}
w[makew[l]]=mul;
}
void init(int N, int M, vector<int> P, vector<int> A) {
n=N;
for(auto i:P) ch.pb(p);
for(auto i:P) {
p.pb(i);
if(i>=0) ch[i].pb(p.size()-1);
prd.pb(1);
w.pb(1);
cmw.pb(1);
}
for(ll i=N-1; i>=0; i--) {
prd[i]=ch[i].size();
for(ll j:ch[i]) {
prd[i]*=prd[j];
prd[i]%=MOD;
}
}
for(ll i=N-1; i>=0; i--) {
makew=ch[i];
solvew(0, makew.size()-1, 1);
}
for(int i=1; i<N+M; i++) {
cmw[i]=w[i]*cmw[p[i]];
cmw[i]%=MOD;
}
pref[0]=cmw[N];
for(int i=1; i<M; i++) {
pref[i]=pref[i-1]+cmw[N+i];
pref[i]%=MOD;
}
tree=build(0, M-1);
for(int i=0; i<M; i++) {
//cout<<i<<'\n';
if(A[i]) flipi(tree, i, i);
}
//for(ll i=0; i<N+M; i++) cout<<prd[i]<<' '<<w[i]<<'\n';
}
int count_ways(int L, int R) {
flipi(tree, L-n, R-n);
return (saberisve()+MOD)%MOD;
}
Compilation message
circuit.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>)':
circuit.cpp:100:14: warning: unused variable 'i' [-Wunused-variable]
100 | for(auto i:P) ch.pb(p);
| ^
# |
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 |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
1 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 |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
684 KB |
Output is correct |
12 |
Correct |
1 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 |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
1 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 |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
1 ms |
600 KB |
Output is correct |
17 |
Correct |
1 ms |
600 KB |
Output is correct |
18 |
Correct |
1 ms |
600 KB |
Output is correct |
19 |
Correct |
1 ms |
684 KB |
Output is correct |
20 |
Correct |
1 ms |
600 KB |
Output is correct |
21 |
Correct |
1 ms |
600 KB |
Output is correct |
22 |
Correct |
0 ms |
600 KB |
Output is correct |
23 |
Correct |
1 ms |
600 KB |
Output is correct |
24 |
Correct |
1 ms |
600 KB |
Output is correct |
25 |
Correct |
1 ms |
600 KB |
Output is correct |
26 |
Correct |
1 ms |
600 KB |
Output is correct |
27 |
Correct |
1 ms |
600 KB |
Output is correct |
28 |
Correct |
1 ms |
708 KB |
Output is correct |
29 |
Correct |
1 ms |
600 KB |
Output is correct |
30 |
Correct |
1 ms |
600 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
1 ms |
600 KB |
Output is correct |
33 |
Correct |
1 ms |
600 KB |
Output is correct |
34 |
Correct |
1 ms |
600 KB |
Output is correct |
35 |
Correct |
0 ms |
600 KB |
Output is correct |
36 |
Correct |
1 ms |
600 KB |
Output is correct |
37 |
Correct |
1 ms |
600 KB |
Output is correct |
38 |
Correct |
1 ms |
600 KB |
Output is correct |
39 |
Correct |
0 ms |
600 KB |
Output is correct |
40 |
Correct |
1 ms |
600 KB |
Output is correct |
41 |
Correct |
1 ms |
600 KB |
Output is correct |
42 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
446 ms |
10188 KB |
Output is correct |
2 |
Correct |
580 ms |
19904 KB |
Output is correct |
3 |
Correct |
592 ms |
19940 KB |
Output is correct |
4 |
Correct |
557 ms |
19912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
446 ms |
10188 KB |
Output is correct |
2 |
Correct |
580 ms |
19904 KB |
Output is correct |
3 |
Correct |
592 ms |
19940 KB |
Output is correct |
4 |
Correct |
557 ms |
19912 KB |
Output is correct |
5 |
Correct |
558 ms |
10188 KB |
Output is correct |
6 |
Correct |
806 ms |
19904 KB |
Output is correct |
7 |
Correct |
759 ms |
19912 KB |
Output is correct |
8 |
Correct |
703 ms |
19912 KB |
Output is correct |
9 |
Correct |
335 ms |
856 KB |
Output is correct |
10 |
Correct |
698 ms |
1560 KB |
Output is correct |
11 |
Correct |
670 ms |
1560 KB |
Output is correct |
12 |
Correct |
673 ms |
1560 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 |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
9 |
Correct |
1 ms |
600 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
684 KB |
Output is correct |
12 |
Correct |
1 ms |
600 KB |
Output is correct |
13 |
Correct |
446 ms |
10188 KB |
Output is correct |
14 |
Correct |
580 ms |
19904 KB |
Output is correct |
15 |
Correct |
592 ms |
19940 KB |
Output is correct |
16 |
Correct |
557 ms |
19912 KB |
Output is correct |
17 |
Correct |
558 ms |
10188 KB |
Output is correct |
18 |
Correct |
806 ms |
19904 KB |
Output is correct |
19 |
Correct |
759 ms |
19912 KB |
Output is correct |
20 |
Correct |
703 ms |
19912 KB |
Output is correct |
21 |
Correct |
335 ms |
856 KB |
Output is correct |
22 |
Correct |
698 ms |
1560 KB |
Output is correct |
23 |
Correct |
670 ms |
1560 KB |
Output is correct |
24 |
Correct |
673 ms |
1560 KB |
Output is correct |
25 |
Correct |
799 ms |
31412 KB |
Output is correct |
26 |
Correct |
838 ms |
30648 KB |
Output is correct |
27 |
Correct |
863 ms |
31912 KB |
Output is correct |
28 |
Correct |
662 ms |
30644 KB |
Output is correct |
29 |
Correct |
735 ms |
30688 KB |
Output is correct |
30 |
Correct |
816 ms |
31528 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 |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
1 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 |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
1 ms |
600 KB |
Output is correct |
17 |
Correct |
1 ms |
600 KB |
Output is correct |
18 |
Correct |
1 ms |
600 KB |
Output is correct |
19 |
Correct |
1 ms |
684 KB |
Output is correct |
20 |
Correct |
1 ms |
600 KB |
Output is correct |
21 |
Correct |
1 ms |
600 KB |
Output is correct |
22 |
Correct |
0 ms |
600 KB |
Output is correct |
23 |
Correct |
1 ms |
600 KB |
Output is correct |
24 |
Correct |
1 ms |
600 KB |
Output is correct |
25 |
Correct |
1 ms |
600 KB |
Output is correct |
26 |
Correct |
1 ms |
600 KB |
Output is correct |
27 |
Correct |
1 ms |
600 KB |
Output is correct |
28 |
Correct |
1 ms |
708 KB |
Output is correct |
29 |
Correct |
1 ms |
600 KB |
Output is correct |
30 |
Correct |
1 ms |
600 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
1 ms |
600 KB |
Output is correct |
33 |
Correct |
1 ms |
600 KB |
Output is correct |
34 |
Correct |
1 ms |
600 KB |
Output is correct |
35 |
Correct |
0 ms |
600 KB |
Output is correct |
36 |
Correct |
1 ms |
600 KB |
Output is correct |
37 |
Correct |
1 ms |
600 KB |
Output is correct |
38 |
Correct |
1 ms |
600 KB |
Output is correct |
39 |
Correct |
0 ms |
600 KB |
Output is correct |
40 |
Correct |
1 ms |
600 KB |
Output is correct |
41 |
Correct |
1 ms |
600 KB |
Output is correct |
42 |
Correct |
1 ms |
600 KB |
Output is correct |
43 |
Correct |
474 ms |
1308 KB |
Output is correct |
44 |
Correct |
681 ms |
1556 KB |
Output is correct |
45 |
Correct |
700 ms |
1304 KB |
Output is correct |
46 |
Correct |
611 ms |
1880 KB |
Output is correct |
47 |
Correct |
684 ms |
1880 KB |
Output is correct |
48 |
Correct |
673 ms |
1880 KB |
Output is correct |
49 |
Correct |
734 ms |
1880 KB |
Output is correct |
50 |
Correct |
662 ms |
1880 KB |
Output is correct |
51 |
Correct |
500 ms |
1560 KB |
Output is correct |
52 |
Correct |
537 ms |
1504 KB |
Output is correct |
53 |
Correct |
500 ms |
904 KB |
Output is correct |
54 |
Correct |
557 ms |
1976 KB |
Output is correct |
55 |
Correct |
625 ms |
1564 KB |
Output is correct |
56 |
Correct |
587 ms |
1648 KB |
Output is correct |
57 |
Correct |
590 ms |
1308 KB |
Output is correct |
58 |
Correct |
580 ms |
1960 KB |
Output is correct |
59 |
Correct |
619 ms |
1880 KB |
Output is correct |
60 |
Correct |
523 ms |
2032 KB |
Output is correct |
61 |
Correct |
516 ms |
1140 KB |
Output is correct |
62 |
Correct |
491 ms |
1304 KB |
Output is correct |
63 |
Correct |
519 ms |
1304 KB |
Output is correct |
64 |
Correct |
528 ms |
1560 KB |
Output is correct |
65 |
Correct |
270 ms |
856 KB |
Output is correct |
66 |
Correct |
681 ms |
1560 KB |
Output is correct |
67 |
Correct |
611 ms |
1560 KB |
Output is correct |
68 |
Correct |
573 ms |
1560 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 |
1 ms |
600 KB |
Output is correct |
4 |
Correct |
1 ms |
600 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
1 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 |
1 ms |
600 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
600 KB |
Output is correct |
15 |
Correct |
1 ms |
600 KB |
Output is correct |
16 |
Correct |
1 ms |
600 KB |
Output is correct |
17 |
Correct |
1 ms |
600 KB |
Output is correct |
18 |
Correct |
1 ms |
600 KB |
Output is correct |
19 |
Correct |
1 ms |
684 KB |
Output is correct |
20 |
Correct |
1 ms |
600 KB |
Output is correct |
21 |
Correct |
1 ms |
600 KB |
Output is correct |
22 |
Correct |
0 ms |
600 KB |
Output is correct |
23 |
Correct |
1 ms |
600 KB |
Output is correct |
24 |
Correct |
1 ms |
600 KB |
Output is correct |
25 |
Correct |
1 ms |
600 KB |
Output is correct |
26 |
Correct |
1 ms |
600 KB |
Output is correct |
27 |
Correct |
1 ms |
600 KB |
Output is correct |
28 |
Correct |
1 ms |
708 KB |
Output is correct |
29 |
Correct |
1 ms |
600 KB |
Output is correct |
30 |
Correct |
1 ms |
600 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
1 ms |
600 KB |
Output is correct |
33 |
Correct |
1 ms |
600 KB |
Output is correct |
34 |
Correct |
1 ms |
600 KB |
Output is correct |
35 |
Correct |
0 ms |
600 KB |
Output is correct |
36 |
Correct |
1 ms |
600 KB |
Output is correct |
37 |
Correct |
1 ms |
600 KB |
Output is correct |
38 |
Correct |
1 ms |
600 KB |
Output is correct |
39 |
Correct |
0 ms |
600 KB |
Output is correct |
40 |
Correct |
1 ms |
600 KB |
Output is correct |
41 |
Correct |
1 ms |
600 KB |
Output is correct |
42 |
Correct |
1 ms |
600 KB |
Output is correct |
43 |
Correct |
446 ms |
10188 KB |
Output is correct |
44 |
Correct |
580 ms |
19904 KB |
Output is correct |
45 |
Correct |
592 ms |
19940 KB |
Output is correct |
46 |
Correct |
557 ms |
19912 KB |
Output is correct |
47 |
Correct |
558 ms |
10188 KB |
Output is correct |
48 |
Correct |
806 ms |
19904 KB |
Output is correct |
49 |
Correct |
759 ms |
19912 KB |
Output is correct |
50 |
Correct |
703 ms |
19912 KB |
Output is correct |
51 |
Correct |
335 ms |
856 KB |
Output is correct |
52 |
Correct |
698 ms |
1560 KB |
Output is correct |
53 |
Correct |
670 ms |
1560 KB |
Output is correct |
54 |
Correct |
673 ms |
1560 KB |
Output is correct |
55 |
Correct |
799 ms |
31412 KB |
Output is correct |
56 |
Correct |
838 ms |
30648 KB |
Output is correct |
57 |
Correct |
863 ms |
31912 KB |
Output is correct |
58 |
Correct |
662 ms |
30644 KB |
Output is correct |
59 |
Correct |
735 ms |
30688 KB |
Output is correct |
60 |
Correct |
816 ms |
31528 KB |
Output is correct |
61 |
Correct |
474 ms |
1308 KB |
Output is correct |
62 |
Correct |
681 ms |
1556 KB |
Output is correct |
63 |
Correct |
700 ms |
1304 KB |
Output is correct |
64 |
Correct |
611 ms |
1880 KB |
Output is correct |
65 |
Correct |
684 ms |
1880 KB |
Output is correct |
66 |
Correct |
673 ms |
1880 KB |
Output is correct |
67 |
Correct |
734 ms |
1880 KB |
Output is correct |
68 |
Correct |
662 ms |
1880 KB |
Output is correct |
69 |
Correct |
500 ms |
1560 KB |
Output is correct |
70 |
Correct |
537 ms |
1504 KB |
Output is correct |
71 |
Correct |
500 ms |
904 KB |
Output is correct |
72 |
Correct |
557 ms |
1976 KB |
Output is correct |
73 |
Correct |
625 ms |
1564 KB |
Output is correct |
74 |
Correct |
587 ms |
1648 KB |
Output is correct |
75 |
Correct |
590 ms |
1308 KB |
Output is correct |
76 |
Correct |
580 ms |
1960 KB |
Output is correct |
77 |
Correct |
619 ms |
1880 KB |
Output is correct |
78 |
Correct |
523 ms |
2032 KB |
Output is correct |
79 |
Correct |
516 ms |
1140 KB |
Output is correct |
80 |
Correct |
491 ms |
1304 KB |
Output is correct |
81 |
Correct |
519 ms |
1304 KB |
Output is correct |
82 |
Correct |
528 ms |
1560 KB |
Output is correct |
83 |
Correct |
270 ms |
856 KB |
Output is correct |
84 |
Correct |
681 ms |
1560 KB |
Output is correct |
85 |
Correct |
611 ms |
1560 KB |
Output is correct |
86 |
Correct |
573 ms |
1560 KB |
Output is correct |
87 |
Correct |
0 ms |
344 KB |
Output is correct |
88 |
Correct |
473 ms |
27064 KB |
Output is correct |
89 |
Correct |
729 ms |
17692 KB |
Output is correct |
90 |
Correct |
726 ms |
18632 KB |
Output is correct |
91 |
Correct |
777 ms |
31316 KB |
Output is correct |
92 |
Correct |
789 ms |
31668 KB |
Output is correct |
93 |
Correct |
813 ms |
30656 KB |
Output is correct |
94 |
Correct |
832 ms |
30584 KB |
Output is correct |
95 |
Correct |
630 ms |
31320 KB |
Output is correct |
96 |
Correct |
576 ms |
22804 KB |
Output is correct |
97 |
Correct |
730 ms |
22720 KB |
Output is correct |
98 |
Correct |
505 ms |
9928 KB |
Output is correct |
99 |
Correct |
745 ms |
32428 KB |
Output is correct |
100 |
Correct |
861 ms |
29184 KB |
Output is correct |
101 |
Correct |
801 ms |
24260 KB |
Output is correct |
102 |
Correct |
855 ms |
21960 KB |
Output is correct |
103 |
Correct |
808 ms |
31720 KB |
Output is correct |
104 |
Correct |
798 ms |
32444 KB |
Output is correct |
105 |
Correct |
720 ms |
32440 KB |
Output is correct |
106 |
Correct |
763 ms |
16328 KB |
Output is correct |
107 |
Correct |
797 ms |
18376 KB |
Output is correct |
108 |
Correct |
797 ms |
19720 KB |
Output is correct |
109 |
Correct |
795 ms |
22072 KB |
Output is correct |