#include "circuit.h"
#include<bits/stdc++.h>
using namespace std;
long long tm = 1, l[400100], r[400100], v[400100], cont[400100], lz[400100], mod = 1000002022, po[100100], dep[100100], st[100100], nn;
void pd(int n) {
if(lz[n]){
v[n]=cont[n]-v[n];
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[dep[L+nn]];
v[i] = st[i]*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; 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);
| ~~~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
2nd lines differ - on the 1st token, expected: '2', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
2nd lines differ - on the 1st token, expected: '2', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
2nd lines differ - on the 1st token, expected: '2', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
443 ms |
3888 KB |
1st lines differ - on the 1st token, expected: '431985922', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
443 ms |
3888 KB |
1st lines differ - on the 1st token, expected: '431985922', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
2nd lines differ - on the 1st token, expected: '2', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
2nd lines differ - on the 1st token, expected: '2', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
2nd lines differ - on the 1st token, expected: '2', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |