#include "circuit.h"
#include<bits/stdc++.h>
using namespace std;
long long tm = 1, l[800100], r[800100], v[800100], cont[800100], lz[800100], mod = 1000002022, st[200100], nn, deg[200100];
set<int> nansc[200100];
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) {
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) {
for(int i = 0; i < N; i++)
nansc[0].insert(i);
nn=N;
for(int i = 0; i < M; i++)
st[i] = A[i];
for(int i = 1; i < N+M; i++){
deg[P[i]]++;
nansc[i] = nansc[P[i]];
nansc[i].erase(P[i]);
}
for(int i = N; i < N+M; i++) {
cont[i+1] = 1;
for(auto j: nansc[i])
cont[i+1] = (cont[i+1]*deg[j])%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:20:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
20 | build(i*2,L,L+R>>1);
| ~^~
circuit.cpp:21:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
21 | build(i*2+1,L+R+2>>1, R);
| ~~~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9680 KB |
Output is correct |
2 |
Incorrect |
5 ms |
9680 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9680 KB |
Output is correct |
2 |
Correct |
10 ms |
15696 KB |
Output is correct |
3 |
Correct |
32 ms |
33888 KB |
Output is correct |
4 |
Correct |
32 ms |
33872 KB |
Output is correct |
5 |
Correct |
31 ms |
33872 KB |
Output is correct |
6 |
Incorrect |
64 ms |
58528 KB |
1st lines differ - on the 1st token, expected: '706880838', found: '983215586' |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9680 KB |
Output is correct |
2 |
Incorrect |
5 ms |
9680 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1955 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1955 ms |
2097152 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9680 KB |
Output is correct |
2 |
Correct |
10 ms |
15696 KB |
Output is correct |
3 |
Correct |
32 ms |
33888 KB |
Output is correct |
4 |
Correct |
32 ms |
33872 KB |
Output is correct |
5 |
Correct |
31 ms |
33872 KB |
Output is correct |
6 |
Incorrect |
64 ms |
58528 KB |
1st lines differ - on the 1st token, expected: '706880838', found: '983215586' |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9680 KB |
Output is correct |
2 |
Incorrect |
5 ms |
9680 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9680 KB |
Output is correct |
2 |
Incorrect |
5 ms |
9680 KB |
1st lines differ - on the 1st token, expected: '1', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |