#include "circuit.h"
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
const int N = 1e4 + 5;
const int oo = 1e18 + 7, mod = 1000002022;
int n, m;
vector<int> Adj[N];
int arr[N];
long long coor[N][N];
long long pref[N], suff[N];
void dfs(int u){
if(!Adj[u].size()) return;
for(auto v : Adj[u]) dfs(v);
pref[0] = coor[Adj[u][0]][m];
for(int i = 1; i < Adj[u].size(); i++) pref[i] = (pref[i - 1] * coor[Adj[u][i]][m]) % mod;
suff[Adj[u].size()] = 1;
for(int i = Adj[u].size() - 1; i >= 0; i--) suff[i] = (suff[i + 1] * coor[Adj[u][i]][m]) % mod;
//for(int i = 0; i < Adj[u].size(); i++) cout << pref[i] << " " << suff[i] << "\n";
coor[u][m] = (pref[Adj[u].size() - 1] * Adj[u].size()) % mod;
for(int i = 0; i < Adj[u].size(); i++){
int v = Adj[u][i];
long long temp1 = (!i ? 1 : pref[i - 1]);
temp1 = (temp1 * suff[i + 1]) % mod;
if(!temp1) continue;
for(int j = 0; j < m; j++){
if(!coor[v][j]) continue;
long long temp2 = (temp1 * coor[v][j]) % mod;
coor[u][j] += temp2;
}
}
for(int i = 0; i <= m; i++) coor[u][i] = ((coor[u][i] % mod) + mod) % mod;
//for(int i = 0; i <= m; i++) cout << u << " " << i << " " << coor[u][i] << "\n";
}
void init(int N, int M, vector<int> P, vector<int> A){
n = N, m = M;
for(int i = 1; i < n + m; i++) Adj[P[i]].pb(i);
for(int i = 0; i < m; i++) arr[i] = A[i];
for(int i = n; i < n + m; i++) coor[i][i - n] = coor[i][m] = 1;
dfs(0);
//for(int i = 0; i < m; i++) cout << coor[0][i] << " ";
//cout << "\n";
}
int count_ways(int L, int R){
L -= n, R -= n;
for(int i = L; i <= R; i++) arr[i] ^= 1;
long long ans = 0;
for(int i = 0; i < m; i++) if(arr[i]) ans += coor[0][i];
ans %= mod;
int ans2 = ans;
return ans2;
}
Compilation message
circuit.cpp:16:21: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
16 | const int oo = 1e18 + 7, mod = 1000002022;
| ~~~~~^~~
circuit.cpp: In function 'void dfs(int)':
circuit.cpp:30:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | for(int i = 1; i < Adj[u].size(); i++) pref[i] = (pref[i - 1] * coor[Adj[u][i]][m]) % mod;
| ~~^~~~~~~~~~~~~~~
circuit.cpp:35:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for(int i = 0; i < Adj[u].size(); i++){
| ~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
464 KB |
Output is correct |
2 |
Correct |
1 ms |
464 KB |
Output is correct |
3 |
Correct |
5 ms |
7504 KB |
Output is correct |
4 |
Correct |
6 ms |
7632 KB |
Output is correct |
5 |
Correct |
5 ms |
7620 KB |
Output is correct |
6 |
Correct |
5 ms |
7632 KB |
Output is correct |
7 |
Correct |
6 ms |
7632 KB |
Output is correct |
8 |
Correct |
5 ms |
7740 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
464 KB |
Output is correct |
2 |
Correct |
3 ms |
3408 KB |
Output is correct |
3 |
Correct |
5 ms |
7888 KB |
Output is correct |
4 |
Correct |
6 ms |
7832 KB |
Output is correct |
5 |
Correct |
5 ms |
7888 KB |
Output is correct |
6 |
Correct |
9 ms |
12524 KB |
Output is correct |
7 |
Correct |
15 ms |
19692 KB |
Output is correct |
8 |
Correct |
14 ms |
19664 KB |
Output is correct |
9 |
Correct |
15 ms |
19672 KB |
Output is correct |
10 |
Correct |
15 ms |
19712 KB |
Output is correct |
11 |
Correct |
15 ms |
19728 KB |
Output is correct |
12 |
Correct |
11 ms |
15608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
464 KB |
Output is correct |
2 |
Correct |
1 ms |
464 KB |
Output is correct |
3 |
Correct |
5 ms |
7504 KB |
Output is correct |
4 |
Correct |
6 ms |
7632 KB |
Output is correct |
5 |
Correct |
5 ms |
7620 KB |
Output is correct |
6 |
Correct |
5 ms |
7632 KB |
Output is correct |
7 |
Correct |
6 ms |
7632 KB |
Output is correct |
8 |
Correct |
5 ms |
7740 KB |
Output is correct |
9 |
Correct |
1 ms |
464 KB |
Output is correct |
10 |
Correct |
3 ms |
3408 KB |
Output is correct |
11 |
Correct |
5 ms |
7888 KB |
Output is correct |
12 |
Correct |
6 ms |
7832 KB |
Output is correct |
13 |
Correct |
5 ms |
7888 KB |
Output is correct |
14 |
Correct |
9 ms |
12524 KB |
Output is correct |
15 |
Correct |
15 ms |
19692 KB |
Output is correct |
16 |
Correct |
14 ms |
19664 KB |
Output is correct |
17 |
Correct |
15 ms |
19672 KB |
Output is correct |
18 |
Correct |
15 ms |
19712 KB |
Output is correct |
19 |
Correct |
15 ms |
19728 KB |
Output is correct |
20 |
Correct |
11 ms |
15608 KB |
Output is correct |
21 |
Correct |
11 ms |
15440 KB |
Output is correct |
22 |
Correct |
6 ms |
9900 KB |
Output is correct |
23 |
Correct |
6 ms |
9552 KB |
Output is correct |
24 |
Correct |
14 ms |
19652 KB |
Output is correct |
25 |
Correct |
13 ms |
19664 KB |
Output is correct |
26 |
Correct |
13 ms |
19596 KB |
Output is correct |
27 |
Correct |
16 ms |
19688 KB |
Output is correct |
28 |
Correct |
18 ms |
19684 KB |
Output is correct |
29 |
Correct |
5 ms |
7632 KB |
Output is correct |
30 |
Correct |
5 ms |
7688 KB |
Output is correct |
31 |
Correct |
2 ms |
4816 KB |
Output is correct |
32 |
Correct |
14 ms |
19676 KB |
Output is correct |
33 |
Correct |
11 ms |
13648 KB |
Output is correct |
34 |
Correct |
7 ms |
10576 KB |
Output is correct |
35 |
Correct |
5 ms |
6736 KB |
Output is correct |
36 |
Correct |
14 ms |
19784 KB |
Output is correct |
37 |
Correct |
13 ms |
19816 KB |
Output is correct |
38 |
Correct |
15 ms |
19716 KB |
Output is correct |
39 |
Correct |
5 ms |
8144 KB |
Output is correct |
40 |
Correct |
9 ms |
11600 KB |
Output is correct |
41 |
Correct |
7 ms |
10704 KB |
Output is correct |
42 |
Correct |
5 ms |
7716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
20 ms |
1680 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
20 ms |
1680 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
464 KB |
Output is correct |
2 |
Correct |
3 ms |
3408 KB |
Output is correct |
3 |
Correct |
5 ms |
7888 KB |
Output is correct |
4 |
Correct |
6 ms |
7832 KB |
Output is correct |
5 |
Correct |
5 ms |
7888 KB |
Output is correct |
6 |
Correct |
9 ms |
12524 KB |
Output is correct |
7 |
Correct |
15 ms |
19692 KB |
Output is correct |
8 |
Correct |
14 ms |
19664 KB |
Output is correct |
9 |
Correct |
15 ms |
19672 KB |
Output is correct |
10 |
Correct |
15 ms |
19712 KB |
Output is correct |
11 |
Correct |
15 ms |
19728 KB |
Output is correct |
12 |
Correct |
11 ms |
15608 KB |
Output is correct |
13 |
Runtime error |
20 ms |
1680 KB |
Execution killed with signal 11 |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
464 KB |
Output is correct |
2 |
Correct |
1 ms |
464 KB |
Output is correct |
3 |
Correct |
5 ms |
7504 KB |
Output is correct |
4 |
Correct |
6 ms |
7632 KB |
Output is correct |
5 |
Correct |
5 ms |
7620 KB |
Output is correct |
6 |
Correct |
5 ms |
7632 KB |
Output is correct |
7 |
Correct |
6 ms |
7632 KB |
Output is correct |
8 |
Correct |
5 ms |
7740 KB |
Output is correct |
9 |
Correct |
1 ms |
464 KB |
Output is correct |
10 |
Correct |
3 ms |
3408 KB |
Output is correct |
11 |
Correct |
5 ms |
7888 KB |
Output is correct |
12 |
Correct |
6 ms |
7832 KB |
Output is correct |
13 |
Correct |
5 ms |
7888 KB |
Output is correct |
14 |
Correct |
9 ms |
12524 KB |
Output is correct |
15 |
Correct |
15 ms |
19692 KB |
Output is correct |
16 |
Correct |
14 ms |
19664 KB |
Output is correct |
17 |
Correct |
15 ms |
19672 KB |
Output is correct |
18 |
Correct |
15 ms |
19712 KB |
Output is correct |
19 |
Correct |
15 ms |
19728 KB |
Output is correct |
20 |
Correct |
11 ms |
15608 KB |
Output is correct |
21 |
Correct |
11 ms |
15440 KB |
Output is correct |
22 |
Correct |
6 ms |
9900 KB |
Output is correct |
23 |
Correct |
6 ms |
9552 KB |
Output is correct |
24 |
Correct |
14 ms |
19652 KB |
Output is correct |
25 |
Correct |
13 ms |
19664 KB |
Output is correct |
26 |
Correct |
13 ms |
19596 KB |
Output is correct |
27 |
Correct |
16 ms |
19688 KB |
Output is correct |
28 |
Correct |
18 ms |
19684 KB |
Output is correct |
29 |
Correct |
5 ms |
7632 KB |
Output is correct |
30 |
Correct |
5 ms |
7688 KB |
Output is correct |
31 |
Correct |
2 ms |
4816 KB |
Output is correct |
32 |
Correct |
14 ms |
19676 KB |
Output is correct |
33 |
Correct |
11 ms |
13648 KB |
Output is correct |
34 |
Correct |
7 ms |
10576 KB |
Output is correct |
35 |
Correct |
5 ms |
6736 KB |
Output is correct |
36 |
Correct |
14 ms |
19784 KB |
Output is correct |
37 |
Correct |
13 ms |
19816 KB |
Output is correct |
38 |
Correct |
15 ms |
19716 KB |
Output is correct |
39 |
Correct |
5 ms |
8144 KB |
Output is correct |
40 |
Correct |
9 ms |
11600 KB |
Output is correct |
41 |
Correct |
7 ms |
10704 KB |
Output is correct |
42 |
Correct |
5 ms |
7716 KB |
Output is correct |
43 |
Correct |
1349 ms |
97372 KB |
Output is correct |
44 |
Correct |
1753 ms |
117420 KB |
Output is correct |
45 |
Correct |
1891 ms |
113128 KB |
Output is correct |
46 |
Correct |
2286 ms |
256584 KB |
Output is correct |
47 |
Correct |
2739 ms |
256564 KB |
Output is correct |
48 |
Correct |
2635 ms |
256536 KB |
Output is correct |
49 |
Correct |
2845 ms |
256536 KB |
Output is correct |
50 |
Correct |
1773 ms |
256636 KB |
Output is correct |
51 |
Correct |
2878 ms |
40520 KB |
Output is correct |
52 |
Correct |
2355 ms |
40528 KB |
Output is correct |
53 |
Correct |
736 ms |
21968 KB |
Output is correct |
54 |
Correct |
2664 ms |
256580 KB |
Output is correct |
55 |
Correct |
2657 ms |
148424 KB |
Output is correct |
56 |
Correct |
2403 ms |
94348 KB |
Output is correct |
57 |
Correct |
2578 ms |
40384 KB |
Output is correct |
58 |
Correct |
2725 ms |
257084 KB |
Output is correct |
59 |
Execution timed out |
3016 ms |
257236 KB |
Time limit exceeded |
60 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
464 KB |
Output is correct |
2 |
Correct |
1 ms |
464 KB |
Output is correct |
3 |
Correct |
5 ms |
7504 KB |
Output is correct |
4 |
Correct |
6 ms |
7632 KB |
Output is correct |
5 |
Correct |
5 ms |
7620 KB |
Output is correct |
6 |
Correct |
5 ms |
7632 KB |
Output is correct |
7 |
Correct |
6 ms |
7632 KB |
Output is correct |
8 |
Correct |
5 ms |
7740 KB |
Output is correct |
9 |
Correct |
1 ms |
464 KB |
Output is correct |
10 |
Correct |
3 ms |
3408 KB |
Output is correct |
11 |
Correct |
5 ms |
7888 KB |
Output is correct |
12 |
Correct |
6 ms |
7832 KB |
Output is correct |
13 |
Correct |
5 ms |
7888 KB |
Output is correct |
14 |
Correct |
9 ms |
12524 KB |
Output is correct |
15 |
Correct |
15 ms |
19692 KB |
Output is correct |
16 |
Correct |
14 ms |
19664 KB |
Output is correct |
17 |
Correct |
15 ms |
19672 KB |
Output is correct |
18 |
Correct |
15 ms |
19712 KB |
Output is correct |
19 |
Correct |
15 ms |
19728 KB |
Output is correct |
20 |
Correct |
11 ms |
15608 KB |
Output is correct |
21 |
Correct |
11 ms |
15440 KB |
Output is correct |
22 |
Correct |
6 ms |
9900 KB |
Output is correct |
23 |
Correct |
6 ms |
9552 KB |
Output is correct |
24 |
Correct |
14 ms |
19652 KB |
Output is correct |
25 |
Correct |
13 ms |
19664 KB |
Output is correct |
26 |
Correct |
13 ms |
19596 KB |
Output is correct |
27 |
Correct |
16 ms |
19688 KB |
Output is correct |
28 |
Correct |
18 ms |
19684 KB |
Output is correct |
29 |
Correct |
5 ms |
7632 KB |
Output is correct |
30 |
Correct |
5 ms |
7688 KB |
Output is correct |
31 |
Correct |
2 ms |
4816 KB |
Output is correct |
32 |
Correct |
14 ms |
19676 KB |
Output is correct |
33 |
Correct |
11 ms |
13648 KB |
Output is correct |
34 |
Correct |
7 ms |
10576 KB |
Output is correct |
35 |
Correct |
5 ms |
6736 KB |
Output is correct |
36 |
Correct |
14 ms |
19784 KB |
Output is correct |
37 |
Correct |
13 ms |
19816 KB |
Output is correct |
38 |
Correct |
15 ms |
19716 KB |
Output is correct |
39 |
Correct |
5 ms |
8144 KB |
Output is correct |
40 |
Correct |
9 ms |
11600 KB |
Output is correct |
41 |
Correct |
7 ms |
10704 KB |
Output is correct |
42 |
Correct |
5 ms |
7716 KB |
Output is correct |
43 |
Runtime error |
20 ms |
1680 KB |
Execution killed with signal 11 |
44 |
Halted |
0 ms |
0 KB |
- |