#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], Cont[200100];
set<int> nansc;
vector<int> adj[200100];
void dfs(int n) {
if(n>=nn) {
Cont[n-nn]=1;
for(auto i: nansc)
Cont[n-nn]=Cont[n-nn]*deg[i]%mod;
return;
}
nansc.erase(n);
for(auto i: adj[n])
dfs(i);
nansc.insert(n);
}
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] = Cont[L];
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.insert(i);
nn=N;
for(int i = 0; i < M; i++)
st[i] = A[i];
for(int i = 1; i < N+M; i++)
adj[P[i]].push_back(i), deg[P[i]]++;
dfs(0);
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:34:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
34 | build(i*2,L,L+R>>1);
| ~^~
circuit.cpp:35:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
35 | build(i*2+1,L+R+2>>1, R);
| ~~~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4944 KB |
Output is correct |
2 |
Correct |
2 ms |
4944 KB |
Output is correct |
3 |
Correct |
3 ms |
5164 KB |
Output is correct |
4 |
Correct |
3 ms |
5072 KB |
Output is correct |
5 |
Correct |
2 ms |
5172 KB |
Output is correct |
6 |
Correct |
2 ms |
5072 KB |
Output is correct |
7 |
Correct |
2 ms |
5072 KB |
Output is correct |
8 |
Correct |
2 ms |
5072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
3 ms |
5072 KB |
Output is correct |
3 |
Correct |
4 ms |
5072 KB |
Output is correct |
4 |
Correct |
4 ms |
5072 KB |
Output is correct |
5 |
Correct |
4 ms |
5072 KB |
Output is correct |
6 |
Correct |
5 ms |
5200 KB |
Output is correct |
7 |
Correct |
8 ms |
5252 KB |
Output is correct |
8 |
Correct |
8 ms |
5144 KB |
Output is correct |
9 |
Correct |
7 ms |
5152 KB |
Output is correct |
10 |
Correct |
5 ms |
5216 KB |
Output is correct |
11 |
Correct |
5 ms |
5216 KB |
Output is correct |
12 |
Correct |
6 ms |
5244 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4944 KB |
Output is correct |
2 |
Correct |
2 ms |
4944 KB |
Output is correct |
3 |
Correct |
3 ms |
5164 KB |
Output is correct |
4 |
Correct |
3 ms |
5072 KB |
Output is correct |
5 |
Correct |
2 ms |
5172 KB |
Output is correct |
6 |
Correct |
2 ms |
5072 KB |
Output is correct |
7 |
Correct |
2 ms |
5072 KB |
Output is correct |
8 |
Correct |
2 ms |
5072 KB |
Output is correct |
9 |
Correct |
2 ms |
4944 KB |
Output is correct |
10 |
Correct |
3 ms |
5072 KB |
Output is correct |
11 |
Correct |
4 ms |
5072 KB |
Output is correct |
12 |
Correct |
4 ms |
5072 KB |
Output is correct |
13 |
Correct |
4 ms |
5072 KB |
Output is correct |
14 |
Correct |
5 ms |
5200 KB |
Output is correct |
15 |
Correct |
8 ms |
5252 KB |
Output is correct |
16 |
Correct |
8 ms |
5144 KB |
Output is correct |
17 |
Correct |
7 ms |
5152 KB |
Output is correct |
18 |
Correct |
5 ms |
5216 KB |
Output is correct |
19 |
Correct |
5 ms |
5216 KB |
Output is correct |
20 |
Correct |
6 ms |
5244 KB |
Output is correct |
21 |
Correct |
6 ms |
5232 KB |
Output is correct |
22 |
Correct |
4 ms |
5120 KB |
Output is correct |
23 |
Correct |
4 ms |
5072 KB |
Output is correct |
24 |
Correct |
8 ms |
5200 KB |
Output is correct |
25 |
Correct |
7 ms |
5260 KB |
Output is correct |
26 |
Correct |
8 ms |
5200 KB |
Output is correct |
27 |
Correct |
7 ms |
5148 KB |
Output is correct |
28 |
Correct |
8 ms |
5140 KB |
Output is correct |
29 |
Correct |
2 ms |
5072 KB |
Output is correct |
30 |
Correct |
2 ms |
5072 KB |
Output is correct |
31 |
Correct |
2 ms |
5124 KB |
Output is correct |
32 |
Correct |
7 ms |
5140 KB |
Output is correct |
33 |
Correct |
5 ms |
5208 KB |
Output is correct |
34 |
Correct |
4 ms |
5072 KB |
Output is correct |
35 |
Correct |
2 ms |
5072 KB |
Output is correct |
36 |
Correct |
5 ms |
5328 KB |
Output is correct |
37 |
Correct |
3 ms |
5344 KB |
Output is correct |
38 |
Correct |
3 ms |
5264 KB |
Output is correct |
39 |
Correct |
4 ms |
5192 KB |
Output is correct |
40 |
Correct |
5 ms |
5200 KB |
Output is correct |
41 |
Correct |
4 ms |
5076 KB |
Output is correct |
42 |
Correct |
4 ms |
5072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3026 ms |
9056 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3026 ms |
9056 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
3 ms |
5072 KB |
Output is correct |
3 |
Correct |
4 ms |
5072 KB |
Output is correct |
4 |
Correct |
4 ms |
5072 KB |
Output is correct |
5 |
Correct |
4 ms |
5072 KB |
Output is correct |
6 |
Correct |
5 ms |
5200 KB |
Output is correct |
7 |
Correct |
8 ms |
5252 KB |
Output is correct |
8 |
Correct |
8 ms |
5144 KB |
Output is correct |
9 |
Correct |
7 ms |
5152 KB |
Output is correct |
10 |
Correct |
5 ms |
5216 KB |
Output is correct |
11 |
Correct |
5 ms |
5216 KB |
Output is correct |
12 |
Correct |
6 ms |
5244 KB |
Output is correct |
13 |
Execution timed out |
3026 ms |
9056 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4944 KB |
Output is correct |
2 |
Correct |
2 ms |
4944 KB |
Output is correct |
3 |
Correct |
3 ms |
5164 KB |
Output is correct |
4 |
Correct |
3 ms |
5072 KB |
Output is correct |
5 |
Correct |
2 ms |
5172 KB |
Output is correct |
6 |
Correct |
2 ms |
5072 KB |
Output is correct |
7 |
Correct |
2 ms |
5072 KB |
Output is correct |
8 |
Correct |
2 ms |
5072 KB |
Output is correct |
9 |
Correct |
2 ms |
4944 KB |
Output is correct |
10 |
Correct |
3 ms |
5072 KB |
Output is correct |
11 |
Correct |
4 ms |
5072 KB |
Output is correct |
12 |
Correct |
4 ms |
5072 KB |
Output is correct |
13 |
Correct |
4 ms |
5072 KB |
Output is correct |
14 |
Correct |
5 ms |
5200 KB |
Output is correct |
15 |
Correct |
8 ms |
5252 KB |
Output is correct |
16 |
Correct |
8 ms |
5144 KB |
Output is correct |
17 |
Correct |
7 ms |
5152 KB |
Output is correct |
18 |
Correct |
5 ms |
5216 KB |
Output is correct |
19 |
Correct |
5 ms |
5216 KB |
Output is correct |
20 |
Correct |
6 ms |
5244 KB |
Output is correct |
21 |
Correct |
6 ms |
5232 KB |
Output is correct |
22 |
Correct |
4 ms |
5120 KB |
Output is correct |
23 |
Correct |
4 ms |
5072 KB |
Output is correct |
24 |
Correct |
8 ms |
5200 KB |
Output is correct |
25 |
Correct |
7 ms |
5260 KB |
Output is correct |
26 |
Correct |
8 ms |
5200 KB |
Output is correct |
27 |
Correct |
7 ms |
5148 KB |
Output is correct |
28 |
Correct |
8 ms |
5140 KB |
Output is correct |
29 |
Correct |
2 ms |
5072 KB |
Output is correct |
30 |
Correct |
2 ms |
5072 KB |
Output is correct |
31 |
Correct |
2 ms |
5124 KB |
Output is correct |
32 |
Correct |
7 ms |
5140 KB |
Output is correct |
33 |
Correct |
5 ms |
5208 KB |
Output is correct |
34 |
Correct |
4 ms |
5072 KB |
Output is correct |
35 |
Correct |
2 ms |
5072 KB |
Output is correct |
36 |
Correct |
5 ms |
5328 KB |
Output is correct |
37 |
Correct |
3 ms |
5344 KB |
Output is correct |
38 |
Correct |
3 ms |
5264 KB |
Output is correct |
39 |
Correct |
4 ms |
5192 KB |
Output is correct |
40 |
Correct |
5 ms |
5200 KB |
Output is correct |
41 |
Correct |
4 ms |
5076 KB |
Output is correct |
42 |
Correct |
4 ms |
5072 KB |
Output is correct |
43 |
Correct |
493 ms |
5704 KB |
Output is correct |
44 |
Correct |
707 ms |
5724 KB |
Output is correct |
45 |
Correct |
726 ms |
5668 KB |
Output is correct |
46 |
Correct |
786 ms |
6152 KB |
Output is correct |
47 |
Correct |
934 ms |
6204 KB |
Output is correct |
48 |
Correct |
736 ms |
6280 KB |
Output is correct |
49 |
Correct |
746 ms |
6280 KB |
Output is correct |
50 |
Correct |
859 ms |
6088 KB |
Output is correct |
51 |
Correct |
767 ms |
5712 KB |
Output is correct |
52 |
Correct |
730 ms |
5840 KB |
Output is correct |
53 |
Correct |
533 ms |
5840 KB |
Output is correct |
54 |
Correct |
950 ms |
6280 KB |
Output is correct |
55 |
Correct |
754 ms |
6040 KB |
Output is correct |
56 |
Correct |
739 ms |
5944 KB |
Output is correct |
57 |
Correct |
544 ms |
5840 KB |
Output is correct |
58 |
Correct |
727 ms |
6768 KB |
Output is correct |
59 |
Correct |
806 ms |
6736 KB |
Output is correct |
60 |
Correct |
711 ms |
6600 KB |
Output is correct |
61 |
Correct |
737 ms |
5796 KB |
Output is correct |
62 |
Correct |
793 ms |
5576 KB |
Output is correct |
63 |
Correct |
707 ms |
5532 KB |
Output is correct |
64 |
Correct |
748 ms |
5840 KB |
Output is correct |
65 |
Correct |
304 ms |
5396 KB |
Output is correct |
66 |
Correct |
718 ms |
5872 KB |
Output is correct |
67 |
Correct |
668 ms |
5868 KB |
Output is correct |
68 |
Correct |
758 ms |
5760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4944 KB |
Output is correct |
2 |
Correct |
2 ms |
4944 KB |
Output is correct |
3 |
Correct |
3 ms |
5164 KB |
Output is correct |
4 |
Correct |
3 ms |
5072 KB |
Output is correct |
5 |
Correct |
2 ms |
5172 KB |
Output is correct |
6 |
Correct |
2 ms |
5072 KB |
Output is correct |
7 |
Correct |
2 ms |
5072 KB |
Output is correct |
8 |
Correct |
2 ms |
5072 KB |
Output is correct |
9 |
Correct |
2 ms |
4944 KB |
Output is correct |
10 |
Correct |
3 ms |
5072 KB |
Output is correct |
11 |
Correct |
4 ms |
5072 KB |
Output is correct |
12 |
Correct |
4 ms |
5072 KB |
Output is correct |
13 |
Correct |
4 ms |
5072 KB |
Output is correct |
14 |
Correct |
5 ms |
5200 KB |
Output is correct |
15 |
Correct |
8 ms |
5252 KB |
Output is correct |
16 |
Correct |
8 ms |
5144 KB |
Output is correct |
17 |
Correct |
7 ms |
5152 KB |
Output is correct |
18 |
Correct |
5 ms |
5216 KB |
Output is correct |
19 |
Correct |
5 ms |
5216 KB |
Output is correct |
20 |
Correct |
6 ms |
5244 KB |
Output is correct |
21 |
Correct |
6 ms |
5232 KB |
Output is correct |
22 |
Correct |
4 ms |
5120 KB |
Output is correct |
23 |
Correct |
4 ms |
5072 KB |
Output is correct |
24 |
Correct |
8 ms |
5200 KB |
Output is correct |
25 |
Correct |
7 ms |
5260 KB |
Output is correct |
26 |
Correct |
8 ms |
5200 KB |
Output is correct |
27 |
Correct |
7 ms |
5148 KB |
Output is correct |
28 |
Correct |
8 ms |
5140 KB |
Output is correct |
29 |
Correct |
2 ms |
5072 KB |
Output is correct |
30 |
Correct |
2 ms |
5072 KB |
Output is correct |
31 |
Correct |
2 ms |
5124 KB |
Output is correct |
32 |
Correct |
7 ms |
5140 KB |
Output is correct |
33 |
Correct |
5 ms |
5208 KB |
Output is correct |
34 |
Correct |
4 ms |
5072 KB |
Output is correct |
35 |
Correct |
2 ms |
5072 KB |
Output is correct |
36 |
Correct |
5 ms |
5328 KB |
Output is correct |
37 |
Correct |
3 ms |
5344 KB |
Output is correct |
38 |
Correct |
3 ms |
5264 KB |
Output is correct |
39 |
Correct |
4 ms |
5192 KB |
Output is correct |
40 |
Correct |
5 ms |
5200 KB |
Output is correct |
41 |
Correct |
4 ms |
5076 KB |
Output is correct |
42 |
Correct |
4 ms |
5072 KB |
Output is correct |
43 |
Execution timed out |
3026 ms |
9056 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |