#include "circuit.h"
#include<bits/stdc++.h>
using namespace std;
long long l[800100], r[800100], v[800100], cont[800100], lz[800100], mod = 1000002022, po[200100], dep[200100], st[200100], nn;
void pd(int n) {
if(lz[n]){
v[n]=cont[n]-v[n];
lz[n]=0;
if(l[n]!=r[n]) lz[n*2]^=1,lz[n*2+1]^=1;
}
}
void build(int i, int L, int R) {
l[i] = L;
r[i] = R;
if(L==R) {
cont[i] = po[nn-dep[L+nn]];
v[i] = st[L]*cont[i];
} else {
build(i*2,L,L+R>>1);
build(i*2+1,L+R+2>>1, R);
cont[i] = cont[i*2]+cont[i*2+1];
v[i] = v[i*2]+v[i*2+1];
}
}
void update(int i, int tl, int tr) {
if(tl<=l[i]&&r[i]<=tr)
lz[i]^=1, tr=-1;
pd(i);
if(l[i]>tr||tl>r[i])
return;
update(i*2,tl,tr);
update(i*2+1,tl,tr);
v[i] = v[i*2]+v[i*2+1];
}
void init(int N, int M, vector<int> P, vector<int> A) {
nn=N;
for(int i = 0; i < M; i++)
st[i] = A[i];
for(int i = 1; i < N+M; i++)
dep[i] = 1+dep[P[i]];
po[0] = 1;
for(int i = 1; i <= N; i++)
po[i] = po[i-1]*2%mod;
build(1,0,M-1);
}
int count_ways(int L, int R) {
update(1,L-nn,R-nn);
return v[1]%mod;
}
Compilation message
circuit.cpp: In function 'void build(int, int, int)':
circuit.cpp:19:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
19 | build(i*2,L,L+R>>1);
| ~^~
circuit.cpp:20:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
20 | build(i*2+1,L+R+2>>1, R);
| ~~~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
10584 KB |
Output is correct |
2 |
Correct |
1 ms |
12632 KB |
Output is correct |
3 |
Correct |
2 ms |
10584 KB |
Output is correct |
4 |
Correct |
1 ms |
10584 KB |
Output is correct |
5 |
Correct |
1 ms |
10584 KB |
Output is correct |
6 |
Correct |
1 ms |
10584 KB |
Output is correct |
7 |
Correct |
1 ms |
10584 KB |
Output is correct |
8 |
Correct |
1 ms |
10584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
10584 KB |
Output is correct |
2 |
Correct |
1 ms |
10584 KB |
Output is correct |
3 |
Correct |
1 ms |
10584 KB |
Output is correct |
4 |
Correct |
1 ms |
10584 KB |
Output is correct |
5 |
Correct |
1 ms |
10584 KB |
Output is correct |
6 |
Correct |
1 ms |
10840 KB |
Output is correct |
7 |
Correct |
2 ms |
10740 KB |
Output is correct |
8 |
Correct |
2 ms |
10584 KB |
Output is correct |
9 |
Correct |
2 ms |
10584 KB |
Output is correct |
10 |
Correct |
2 ms |
10584 KB |
Output is correct |
11 |
Correct |
2 ms |
10584 KB |
Output is correct |
12 |
Correct |
1 ms |
10584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
10584 KB |
Output is correct |
2 |
Correct |
1 ms |
12632 KB |
Output is correct |
3 |
Correct |
2 ms |
10584 KB |
Output is correct |
4 |
Correct |
1 ms |
10584 KB |
Output is correct |
5 |
Correct |
1 ms |
10584 KB |
Output is correct |
6 |
Correct |
1 ms |
10584 KB |
Output is correct |
7 |
Correct |
1 ms |
10584 KB |
Output is correct |
8 |
Correct |
1 ms |
10584 KB |
Output is correct |
9 |
Correct |
1 ms |
10584 KB |
Output is correct |
10 |
Correct |
1 ms |
10584 KB |
Output is correct |
11 |
Correct |
1 ms |
10584 KB |
Output is correct |
12 |
Correct |
1 ms |
10584 KB |
Output is correct |
13 |
Correct |
1 ms |
10584 KB |
Output is correct |
14 |
Correct |
1 ms |
10840 KB |
Output is correct |
15 |
Correct |
2 ms |
10740 KB |
Output is correct |
16 |
Correct |
2 ms |
10584 KB |
Output is correct |
17 |
Correct |
2 ms |
10584 KB |
Output is correct |
18 |
Correct |
2 ms |
10584 KB |
Output is correct |
19 |
Correct |
2 ms |
10584 KB |
Output is correct |
20 |
Correct |
1 ms |
10584 KB |
Output is correct |
21 |
Incorrect |
2 ms |
10584 KB |
1st lines differ - on the 1st token, expected: '759476520', found: '833967706' |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
399 ms |
13776 KB |
Output is correct |
2 |
Correct |
542 ms |
14496 KB |
Output is correct |
3 |
Correct |
550 ms |
14276 KB |
Output is correct |
4 |
Correct |
534 ms |
14448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
399 ms |
13776 KB |
Output is correct |
2 |
Correct |
542 ms |
14496 KB |
Output is correct |
3 |
Correct |
550 ms |
14276 KB |
Output is correct |
4 |
Correct |
534 ms |
14448 KB |
Output is correct |
5 |
Correct |
447 ms |
13832 KB |
Output is correct |
6 |
Correct |
604 ms |
15176 KB |
Output is correct |
7 |
Correct |
592 ms |
15076 KB |
Output is correct |
8 |
Correct |
544 ms |
14272 KB |
Output is correct |
9 |
Correct |
261 ms |
10840 KB |
Output is correct |
10 |
Correct |
558 ms |
10840 KB |
Output is correct |
11 |
Correct |
537 ms |
10840 KB |
Output is correct |
12 |
Correct |
506 ms |
10840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
10584 KB |
Output is correct |
2 |
Correct |
1 ms |
10584 KB |
Output is correct |
3 |
Correct |
1 ms |
10584 KB |
Output is correct |
4 |
Correct |
1 ms |
10584 KB |
Output is correct |
5 |
Correct |
1 ms |
10584 KB |
Output is correct |
6 |
Correct |
1 ms |
10840 KB |
Output is correct |
7 |
Correct |
2 ms |
10740 KB |
Output is correct |
8 |
Correct |
2 ms |
10584 KB |
Output is correct |
9 |
Correct |
2 ms |
10584 KB |
Output is correct |
10 |
Correct |
2 ms |
10584 KB |
Output is correct |
11 |
Correct |
2 ms |
10584 KB |
Output is correct |
12 |
Correct |
1 ms |
10584 KB |
Output is correct |
13 |
Correct |
399 ms |
13776 KB |
Output is correct |
14 |
Correct |
542 ms |
14496 KB |
Output is correct |
15 |
Correct |
550 ms |
14276 KB |
Output is correct |
16 |
Correct |
534 ms |
14448 KB |
Output is correct |
17 |
Correct |
447 ms |
13832 KB |
Output is correct |
18 |
Correct |
604 ms |
15176 KB |
Output is correct |
19 |
Correct |
592 ms |
15076 KB |
Output is correct |
20 |
Correct |
544 ms |
14272 KB |
Output is correct |
21 |
Correct |
261 ms |
10840 KB |
Output is correct |
22 |
Correct |
558 ms |
10840 KB |
Output is correct |
23 |
Correct |
537 ms |
10840 KB |
Output is correct |
24 |
Correct |
506 ms |
10840 KB |
Output is correct |
25 |
Correct |
616 ms |
26572 KB |
Output is correct |
26 |
Correct |
629 ms |
26072 KB |
Output is correct |
27 |
Correct |
620 ms |
26000 KB |
Output is correct |
28 |
Correct |
480 ms |
24400 KB |
Output is correct |
29 |
Correct |
596 ms |
26028 KB |
Output is correct |
30 |
Correct |
573 ms |
24404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
10584 KB |
Output is correct |
2 |
Correct |
1 ms |
12632 KB |
Output is correct |
3 |
Correct |
2 ms |
10584 KB |
Output is correct |
4 |
Correct |
1 ms |
10584 KB |
Output is correct |
5 |
Correct |
1 ms |
10584 KB |
Output is correct |
6 |
Correct |
1 ms |
10584 KB |
Output is correct |
7 |
Correct |
1 ms |
10584 KB |
Output is correct |
8 |
Correct |
1 ms |
10584 KB |
Output is correct |
9 |
Correct |
1 ms |
10584 KB |
Output is correct |
10 |
Correct |
1 ms |
10584 KB |
Output is correct |
11 |
Correct |
1 ms |
10584 KB |
Output is correct |
12 |
Correct |
1 ms |
10584 KB |
Output is correct |
13 |
Correct |
1 ms |
10584 KB |
Output is correct |
14 |
Correct |
1 ms |
10840 KB |
Output is correct |
15 |
Correct |
2 ms |
10740 KB |
Output is correct |
16 |
Correct |
2 ms |
10584 KB |
Output is correct |
17 |
Correct |
2 ms |
10584 KB |
Output is correct |
18 |
Correct |
2 ms |
10584 KB |
Output is correct |
19 |
Correct |
2 ms |
10584 KB |
Output is correct |
20 |
Correct |
1 ms |
10584 KB |
Output is correct |
21 |
Incorrect |
2 ms |
10584 KB |
1st lines differ - on the 1st token, expected: '759476520', found: '833967706' |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
10584 KB |
Output is correct |
2 |
Correct |
1 ms |
12632 KB |
Output is correct |
3 |
Correct |
2 ms |
10584 KB |
Output is correct |
4 |
Correct |
1 ms |
10584 KB |
Output is correct |
5 |
Correct |
1 ms |
10584 KB |
Output is correct |
6 |
Correct |
1 ms |
10584 KB |
Output is correct |
7 |
Correct |
1 ms |
10584 KB |
Output is correct |
8 |
Correct |
1 ms |
10584 KB |
Output is correct |
9 |
Correct |
1 ms |
10584 KB |
Output is correct |
10 |
Correct |
1 ms |
10584 KB |
Output is correct |
11 |
Correct |
1 ms |
10584 KB |
Output is correct |
12 |
Correct |
1 ms |
10584 KB |
Output is correct |
13 |
Correct |
1 ms |
10584 KB |
Output is correct |
14 |
Correct |
1 ms |
10840 KB |
Output is correct |
15 |
Correct |
2 ms |
10740 KB |
Output is correct |
16 |
Correct |
2 ms |
10584 KB |
Output is correct |
17 |
Correct |
2 ms |
10584 KB |
Output is correct |
18 |
Correct |
2 ms |
10584 KB |
Output is correct |
19 |
Correct |
2 ms |
10584 KB |
Output is correct |
20 |
Correct |
1 ms |
10584 KB |
Output is correct |
21 |
Incorrect |
2 ms |
10584 KB |
1st lines differ - on the 1st token, expected: '759476520', found: '833967706' |
22 |
Halted |
0 ms |
0 KB |
- |