#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1000002022;
const int MAXN = 100007;
int ar[MAXN];
int n,m;
vector<int> ch[2*MAXN];
int mlt[2*MAXN];
int sgt[4*MAXN];
int rel[MAXN];
int res = 0;
void update(int i, int v) {
for (sgt[i+=2*MAXN]=v; i>1; i>>=1) sgt[i>>1] = (sgt[i] * sgt[i^1]) % mod;
}
int query(int l, int r) {
int res = 1;
for (l+=2*MAXN, r+=2*MAXN+1; l<r; l>>=1, r>>=1) {
if (l&1) res *= sgt[l++], res %= mod;
if (r&1) res *= sgt[--r], res %= mod;
}
return res;
}
int dfs0(int i) {
vector<int> vl;
for (int c: ch[i]) vl.push_back(dfs0(c));
if (vl.size() == 0) return 1;
int ans = vl.size(); for (int i=0; i<vl.size(); i++) ans *= vl[i], ans%=mod;
for (int i=0; i<vl.size(); i++) update(i, vl[i]);
for (int j=0; j<vl.size(); j++) {
mlt[ch[i][j]] = ((query(0, j-1)) * query(j+1, vl.size()-1)) % mod;
}
return ans;
}
void dfs1(int i, int p) {
if (ch[i].size() == 0) {
rel[i-n] = (p*mlt[i]) % mod;
} else {
for (int c: ch[i]) {
dfs1(c, (p*mlt[i]) % mod);
}
}
}
void init(signed N, signed M, std::vector<signed> P, std::vector<signed> A) {
for (int i=0; i<M; i++) ar[i] = A[i]; n= N;m=M;
for (int i=1; i<M+N; i++) ch[P[i]].push_back(i);
for (int i=0; i<4*MAXN; i++) sgt[i] = 1;
for (int i=0; i<2*MAXN; i++) mlt[i] = 1;
dfs0(0); dfs1(0,1);
for (int i=0; i<M; i++) if (A[i]) res += rel[i], res %= mod;
}
signed count_ways(signed L, signed R) {
L-=n; R-=n;
for (int i=L; i<=R; i++) {
if (ar[i]) {
res -= rel[i]; res %= mod; res += mod; res %= mod;
ar[i] = 0;
} else {
res += rel[i]; res %= mod;
ar[i] = 1;
}
}
return res;
}
Compilation message
circuit.cpp: In function 'long long int dfs0(long long int)':
circuit.cpp:33:41: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | int ans = vl.size(); for (int i=0; i<vl.size(); i++) ans *= vl[i], ans%=mod;
| ~^~~~~~~~~~
circuit.cpp:34:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for (int i=0; i<vl.size(); i++) update(i, vl[i]);
| ~^~~~~~~~~~
circuit.cpp:35:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for (int j=0; j<vl.size(); j++) {
| ~^~~~~~~~~~
circuit.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>)':
circuit.cpp:52:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
52 | for (int i=0; i<M; i++) ar[i] = A[i]; n= N;m=M;
| ^~~
circuit.cpp:52:43: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
52 | for (int i=0; i<M; i++) ar[i] = A[i]; n= N;m=M;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9816 KB |
Output is correct |
2 |
Correct |
4 ms |
9816 KB |
Output is correct |
3 |
Correct |
5 ms |
9816 KB |
Output is correct |
4 |
Correct |
4 ms |
9816 KB |
Output is correct |
5 |
Correct |
4 ms |
9816 KB |
Output is correct |
6 |
Correct |
4 ms |
9816 KB |
Output is correct |
7 |
Correct |
5 ms |
9816 KB |
Output is correct |
8 |
Correct |
5 ms |
9644 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9816 KB |
Output is correct |
2 |
Correct |
5 ms |
9768 KB |
Output is correct |
3 |
Correct |
5 ms |
10068 KB |
Output is correct |
4 |
Correct |
5 ms |
9816 KB |
Output is correct |
5 |
Correct |
4 ms |
9816 KB |
Output is correct |
6 |
Correct |
5 ms |
9816 KB |
Output is correct |
7 |
Correct |
5 ms |
9820 KB |
Output is correct |
8 |
Correct |
5 ms |
9816 KB |
Output is correct |
9 |
Correct |
4 ms |
9748 KB |
Output is correct |
10 |
Correct |
5 ms |
9968 KB |
Output is correct |
11 |
Correct |
8 ms |
9816 KB |
Output is correct |
12 |
Correct |
5 ms |
9816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9816 KB |
Output is correct |
2 |
Correct |
4 ms |
9816 KB |
Output is correct |
3 |
Correct |
5 ms |
9816 KB |
Output is correct |
4 |
Correct |
4 ms |
9816 KB |
Output is correct |
5 |
Correct |
4 ms |
9816 KB |
Output is correct |
6 |
Correct |
4 ms |
9816 KB |
Output is correct |
7 |
Correct |
5 ms |
9816 KB |
Output is correct |
8 |
Correct |
5 ms |
9644 KB |
Output is correct |
9 |
Correct |
5 ms |
9816 KB |
Output is correct |
10 |
Correct |
5 ms |
9768 KB |
Output is correct |
11 |
Correct |
5 ms |
10068 KB |
Output is correct |
12 |
Correct |
5 ms |
9816 KB |
Output is correct |
13 |
Correct |
4 ms |
9816 KB |
Output is correct |
14 |
Correct |
5 ms |
9816 KB |
Output is correct |
15 |
Correct |
5 ms |
9820 KB |
Output is correct |
16 |
Correct |
5 ms |
9816 KB |
Output is correct |
17 |
Correct |
4 ms |
9748 KB |
Output is correct |
18 |
Correct |
5 ms |
9968 KB |
Output is correct |
19 |
Correct |
8 ms |
9816 KB |
Output is correct |
20 |
Correct |
5 ms |
9816 KB |
Output is correct |
21 |
Correct |
5 ms |
9796 KB |
Output is correct |
22 |
Correct |
4 ms |
9816 KB |
Output is correct |
23 |
Correct |
5 ms |
9816 KB |
Output is correct |
24 |
Correct |
5 ms |
9816 KB |
Output is correct |
25 |
Correct |
5 ms |
9816 KB |
Output is correct |
26 |
Correct |
5 ms |
9816 KB |
Output is correct |
27 |
Correct |
5 ms |
9816 KB |
Output is correct |
28 |
Correct |
4 ms |
9816 KB |
Output is correct |
29 |
Correct |
5 ms |
9816 KB |
Output is correct |
30 |
Correct |
5 ms |
9816 KB |
Output is correct |
31 |
Correct |
5 ms |
9816 KB |
Output is correct |
32 |
Correct |
5 ms |
9816 KB |
Output is correct |
33 |
Correct |
4 ms |
9816 KB |
Output is correct |
34 |
Correct |
5 ms |
9816 KB |
Output is correct |
35 |
Correct |
4 ms |
9816 KB |
Output is correct |
36 |
Correct |
5 ms |
9816 KB |
Output is correct |
37 |
Correct |
5 ms |
9816 KB |
Output is correct |
38 |
Correct |
4 ms |
9816 KB |
Output is correct |
39 |
Correct |
4 ms |
9816 KB |
Output is correct |
40 |
Correct |
4 ms |
9816 KB |
Output is correct |
41 |
Correct |
5 ms |
9816 KB |
Output is correct |
42 |
Correct |
5 ms |
9816 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
416 ms |
11912 KB |
Output is correct |
2 |
Correct |
622 ms |
14424 KB |
Output is correct |
3 |
Correct |
648 ms |
14424 KB |
Output is correct |
4 |
Correct |
651 ms |
14424 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
416 ms |
11912 KB |
Output is correct |
2 |
Correct |
622 ms |
14424 KB |
Output is correct |
3 |
Correct |
648 ms |
14424 KB |
Output is correct |
4 |
Correct |
651 ms |
14424 KB |
Output is correct |
5 |
Execution timed out |
3042 ms |
12120 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9816 KB |
Output is correct |
2 |
Correct |
5 ms |
9768 KB |
Output is correct |
3 |
Correct |
5 ms |
10068 KB |
Output is correct |
4 |
Correct |
5 ms |
9816 KB |
Output is correct |
5 |
Correct |
4 ms |
9816 KB |
Output is correct |
6 |
Correct |
5 ms |
9816 KB |
Output is correct |
7 |
Correct |
5 ms |
9820 KB |
Output is correct |
8 |
Correct |
5 ms |
9816 KB |
Output is correct |
9 |
Correct |
4 ms |
9748 KB |
Output is correct |
10 |
Correct |
5 ms |
9968 KB |
Output is correct |
11 |
Correct |
8 ms |
9816 KB |
Output is correct |
12 |
Correct |
5 ms |
9816 KB |
Output is correct |
13 |
Correct |
416 ms |
11912 KB |
Output is correct |
14 |
Correct |
622 ms |
14424 KB |
Output is correct |
15 |
Correct |
648 ms |
14424 KB |
Output is correct |
16 |
Correct |
651 ms |
14424 KB |
Output is correct |
17 |
Execution timed out |
3042 ms |
12120 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9816 KB |
Output is correct |
2 |
Correct |
4 ms |
9816 KB |
Output is correct |
3 |
Correct |
5 ms |
9816 KB |
Output is correct |
4 |
Correct |
4 ms |
9816 KB |
Output is correct |
5 |
Correct |
4 ms |
9816 KB |
Output is correct |
6 |
Correct |
4 ms |
9816 KB |
Output is correct |
7 |
Correct |
5 ms |
9816 KB |
Output is correct |
8 |
Correct |
5 ms |
9644 KB |
Output is correct |
9 |
Correct |
5 ms |
9816 KB |
Output is correct |
10 |
Correct |
5 ms |
9768 KB |
Output is correct |
11 |
Correct |
5 ms |
10068 KB |
Output is correct |
12 |
Correct |
5 ms |
9816 KB |
Output is correct |
13 |
Correct |
4 ms |
9816 KB |
Output is correct |
14 |
Correct |
5 ms |
9816 KB |
Output is correct |
15 |
Correct |
5 ms |
9820 KB |
Output is correct |
16 |
Correct |
5 ms |
9816 KB |
Output is correct |
17 |
Correct |
4 ms |
9748 KB |
Output is correct |
18 |
Correct |
5 ms |
9968 KB |
Output is correct |
19 |
Correct |
8 ms |
9816 KB |
Output is correct |
20 |
Correct |
5 ms |
9816 KB |
Output is correct |
21 |
Correct |
5 ms |
9796 KB |
Output is correct |
22 |
Correct |
4 ms |
9816 KB |
Output is correct |
23 |
Correct |
5 ms |
9816 KB |
Output is correct |
24 |
Correct |
5 ms |
9816 KB |
Output is correct |
25 |
Correct |
5 ms |
9816 KB |
Output is correct |
26 |
Correct |
5 ms |
9816 KB |
Output is correct |
27 |
Correct |
5 ms |
9816 KB |
Output is correct |
28 |
Correct |
4 ms |
9816 KB |
Output is correct |
29 |
Correct |
5 ms |
9816 KB |
Output is correct |
30 |
Correct |
5 ms |
9816 KB |
Output is correct |
31 |
Correct |
5 ms |
9816 KB |
Output is correct |
32 |
Correct |
5 ms |
9816 KB |
Output is correct |
33 |
Correct |
4 ms |
9816 KB |
Output is correct |
34 |
Correct |
5 ms |
9816 KB |
Output is correct |
35 |
Correct |
4 ms |
9816 KB |
Output is correct |
36 |
Correct |
5 ms |
9816 KB |
Output is correct |
37 |
Correct |
5 ms |
9816 KB |
Output is correct |
38 |
Correct |
4 ms |
9816 KB |
Output is correct |
39 |
Correct |
4 ms |
9816 KB |
Output is correct |
40 |
Correct |
4 ms |
9816 KB |
Output is correct |
41 |
Correct |
5 ms |
9816 KB |
Output is correct |
42 |
Correct |
5 ms |
9816 KB |
Output is correct |
43 |
Correct |
801 ms |
9816 KB |
Output is correct |
44 |
Correct |
1109 ms |
10072 KB |
Output is correct |
45 |
Correct |
1169 ms |
10072 KB |
Output is correct |
46 |
Correct |
564 ms |
10072 KB |
Output is correct |
47 |
Correct |
1579 ms |
10072 KB |
Output is correct |
48 |
Correct |
1575 ms |
10072 KB |
Output is correct |
49 |
Correct |
1600 ms |
10068 KB |
Output is correct |
50 |
Execution timed out |
3036 ms |
10072 KB |
Time limit exceeded |
51 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
9816 KB |
Output is correct |
2 |
Correct |
4 ms |
9816 KB |
Output is correct |
3 |
Correct |
5 ms |
9816 KB |
Output is correct |
4 |
Correct |
4 ms |
9816 KB |
Output is correct |
5 |
Correct |
4 ms |
9816 KB |
Output is correct |
6 |
Correct |
4 ms |
9816 KB |
Output is correct |
7 |
Correct |
5 ms |
9816 KB |
Output is correct |
8 |
Correct |
5 ms |
9644 KB |
Output is correct |
9 |
Correct |
5 ms |
9816 KB |
Output is correct |
10 |
Correct |
5 ms |
9768 KB |
Output is correct |
11 |
Correct |
5 ms |
10068 KB |
Output is correct |
12 |
Correct |
5 ms |
9816 KB |
Output is correct |
13 |
Correct |
4 ms |
9816 KB |
Output is correct |
14 |
Correct |
5 ms |
9816 KB |
Output is correct |
15 |
Correct |
5 ms |
9820 KB |
Output is correct |
16 |
Correct |
5 ms |
9816 KB |
Output is correct |
17 |
Correct |
4 ms |
9748 KB |
Output is correct |
18 |
Correct |
5 ms |
9968 KB |
Output is correct |
19 |
Correct |
8 ms |
9816 KB |
Output is correct |
20 |
Correct |
5 ms |
9816 KB |
Output is correct |
21 |
Correct |
5 ms |
9796 KB |
Output is correct |
22 |
Correct |
4 ms |
9816 KB |
Output is correct |
23 |
Correct |
5 ms |
9816 KB |
Output is correct |
24 |
Correct |
5 ms |
9816 KB |
Output is correct |
25 |
Correct |
5 ms |
9816 KB |
Output is correct |
26 |
Correct |
5 ms |
9816 KB |
Output is correct |
27 |
Correct |
5 ms |
9816 KB |
Output is correct |
28 |
Correct |
4 ms |
9816 KB |
Output is correct |
29 |
Correct |
5 ms |
9816 KB |
Output is correct |
30 |
Correct |
5 ms |
9816 KB |
Output is correct |
31 |
Correct |
5 ms |
9816 KB |
Output is correct |
32 |
Correct |
5 ms |
9816 KB |
Output is correct |
33 |
Correct |
4 ms |
9816 KB |
Output is correct |
34 |
Correct |
5 ms |
9816 KB |
Output is correct |
35 |
Correct |
4 ms |
9816 KB |
Output is correct |
36 |
Correct |
5 ms |
9816 KB |
Output is correct |
37 |
Correct |
5 ms |
9816 KB |
Output is correct |
38 |
Correct |
4 ms |
9816 KB |
Output is correct |
39 |
Correct |
4 ms |
9816 KB |
Output is correct |
40 |
Correct |
4 ms |
9816 KB |
Output is correct |
41 |
Correct |
5 ms |
9816 KB |
Output is correct |
42 |
Correct |
5 ms |
9816 KB |
Output is correct |
43 |
Correct |
416 ms |
11912 KB |
Output is correct |
44 |
Correct |
622 ms |
14424 KB |
Output is correct |
45 |
Correct |
648 ms |
14424 KB |
Output is correct |
46 |
Correct |
651 ms |
14424 KB |
Output is correct |
47 |
Execution timed out |
3042 ms |
12120 KB |
Time limit exceeded |
48 |
Halted |
0 ms |
0 KB |
- |