#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 69;
const int mod = 1e9 + 2022;
vector <int> adj[N];
int n, m;
int w1[N], tot[N], ok[N], aa[N];
int power(int x, int y){
if (y==0) return 1;
int v = power(x, y/2);
v *= v; v %= mod;
if (y & 1) return v * x % mod;
else return v;
}
void dfs(int u){
int cnt = 0;
for (int v : adj[u]){
dfs(v);
cnt++;
}
if (u >= n) return;
int curr = 1;
w1[u] = 0;
for (int v : adj[u]){
ok[v] = curr;
curr *= tot[v];
curr %= mod;
}
tot[u] = curr * cnt % mod;
curr = 1;
for (int i = adj[u].size() - 1; i >= 0; i--){
int v = adj[u][i];
ok[v] *= curr;
ok[v] %= mod;
curr *= tot[v];
curr %= mod;
}
for (int v : adj[u]){
w1[u] += w1[v] * ok[v] % mod;
w1[u] %= mod;
}
}
void init(int32_t N, int32_t M, vector<int32_t> p, vector<int32_t> a) {
n = N;
m = M;
for (int i = 1; i < n + m; i++){
adj[p[i]].push_back(i);
}
for (int i = n; i < n + m; i++){
for (int j = n; j < n + m; j++){
tot[j] = 1;
if (j == i) w1[j] = 1;
else w1[j] = 0;
}
dfs(0);
aa[i] = w1[0];
}
for (int i = 0; i < m; i++){
if (a[i] == 1)
w1[i + n] = 1;
else w1[i + n] = 0;
tot[i + n] = 1;
}
}
int32_t count_ways(int32_t l, int32_t r) {
for (int i = l; i <= r; i++){
w1[i] ^= 1;
}
int32_t ans = 0;
for (int i = n; i < n + m; i++){
if (w1[i]) ans += aa[i], ans %= mod;
}
return ans;
}
// int32_t main(){
// int32_t n, m; cin >> n >> m;
// vector <int32_t> p(n + m), a(m);
// for (auto &x : p) cin >> x;
// for (auto &x : a) cin >> x;
// init(n, m, p, a);
// int q; cin >> q;
// while(q--){
// int32_t l, r;
// cin >> l >> r;
// cout << count_ways(l, r) << "\n";
// }
// return 0;
// }
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
2 ms |
4944 KB |
Output is correct |
3 |
Correct |
18 ms |
5076 KB |
Output is correct |
4 |
Correct |
18 ms |
5072 KB |
Output is correct |
5 |
Correct |
18 ms |
5072 KB |
Output is correct |
6 |
Correct |
18 ms |
5088 KB |
Output is correct |
7 |
Correct |
19 ms |
5080 KB |
Output is correct |
8 |
Correct |
18 ms |
5072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
4 ms |
5052 KB |
Output is correct |
3 |
Correct |
10 ms |
5072 KB |
Output is correct |
4 |
Correct |
9 ms |
5008 KB |
Output is correct |
5 |
Correct |
12 ms |
5072 KB |
Output is correct |
6 |
Correct |
19 ms |
5096 KB |
Output is correct |
7 |
Correct |
34 ms |
5132 KB |
Output is correct |
8 |
Correct |
33 ms |
5072 KB |
Output is correct |
9 |
Correct |
34 ms |
5136 KB |
Output is correct |
10 |
Correct |
31 ms |
5192 KB |
Output is correct |
11 |
Correct |
31 ms |
5188 KB |
Output is correct |
12 |
Correct |
24 ms |
5072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
2 ms |
4944 KB |
Output is correct |
3 |
Correct |
18 ms |
5076 KB |
Output is correct |
4 |
Correct |
18 ms |
5072 KB |
Output is correct |
5 |
Correct |
18 ms |
5072 KB |
Output is correct |
6 |
Correct |
18 ms |
5088 KB |
Output is correct |
7 |
Correct |
19 ms |
5080 KB |
Output is correct |
8 |
Correct |
18 ms |
5072 KB |
Output is correct |
9 |
Correct |
2 ms |
4944 KB |
Output is correct |
10 |
Correct |
4 ms |
5052 KB |
Output is correct |
11 |
Correct |
10 ms |
5072 KB |
Output is correct |
12 |
Correct |
9 ms |
5008 KB |
Output is correct |
13 |
Correct |
12 ms |
5072 KB |
Output is correct |
14 |
Correct |
19 ms |
5096 KB |
Output is correct |
15 |
Correct |
34 ms |
5132 KB |
Output is correct |
16 |
Correct |
33 ms |
5072 KB |
Output is correct |
17 |
Correct |
34 ms |
5136 KB |
Output is correct |
18 |
Correct |
31 ms |
5192 KB |
Output is correct |
19 |
Correct |
31 ms |
5188 KB |
Output is correct |
20 |
Correct |
24 ms |
5072 KB |
Output is correct |
21 |
Correct |
32 ms |
5200 KB |
Output is correct |
22 |
Correct |
15 ms |
5072 KB |
Output is correct |
23 |
Correct |
13 ms |
5096 KB |
Output is correct |
24 |
Correct |
35 ms |
5136 KB |
Output is correct |
25 |
Correct |
34 ms |
5120 KB |
Output is correct |
26 |
Correct |
34 ms |
5132 KB |
Output is correct |
27 |
Correct |
35 ms |
5072 KB |
Output is correct |
28 |
Correct |
34 ms |
5136 KB |
Output is correct |
29 |
Correct |
18 ms |
5072 KB |
Output is correct |
30 |
Correct |
18 ms |
5072 KB |
Output is correct |
31 |
Correct |
3 ms |
5072 KB |
Output is correct |
32 |
Correct |
34 ms |
5072 KB |
Output is correct |
33 |
Correct |
30 ms |
5096 KB |
Output is correct |
34 |
Correct |
22 ms |
5104 KB |
Output is correct |
35 |
Correct |
15 ms |
5072 KB |
Output is correct |
36 |
Correct |
35 ms |
5072 KB |
Output is correct |
37 |
Correct |
37 ms |
5248 KB |
Output is correct |
38 |
Correct |
36 ms |
5208 KB |
Output is correct |
39 |
Correct |
9 ms |
5072 KB |
Output is correct |
40 |
Correct |
18 ms |
5092 KB |
Output is correct |
41 |
Correct |
18 ms |
5104 KB |
Output is correct |
42 |
Correct |
18 ms |
5080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3052 ms |
8632 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3052 ms |
8632 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
4 ms |
5052 KB |
Output is correct |
3 |
Correct |
10 ms |
5072 KB |
Output is correct |
4 |
Correct |
9 ms |
5008 KB |
Output is correct |
5 |
Correct |
12 ms |
5072 KB |
Output is correct |
6 |
Correct |
19 ms |
5096 KB |
Output is correct |
7 |
Correct |
34 ms |
5132 KB |
Output is correct |
8 |
Correct |
33 ms |
5072 KB |
Output is correct |
9 |
Correct |
34 ms |
5136 KB |
Output is correct |
10 |
Correct |
31 ms |
5192 KB |
Output is correct |
11 |
Correct |
31 ms |
5188 KB |
Output is correct |
12 |
Correct |
24 ms |
5072 KB |
Output is correct |
13 |
Execution timed out |
3052 ms |
8632 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
2 ms |
4944 KB |
Output is correct |
3 |
Correct |
18 ms |
5076 KB |
Output is correct |
4 |
Correct |
18 ms |
5072 KB |
Output is correct |
5 |
Correct |
18 ms |
5072 KB |
Output is correct |
6 |
Correct |
18 ms |
5088 KB |
Output is correct |
7 |
Correct |
19 ms |
5080 KB |
Output is correct |
8 |
Correct |
18 ms |
5072 KB |
Output is correct |
9 |
Correct |
2 ms |
4944 KB |
Output is correct |
10 |
Correct |
4 ms |
5052 KB |
Output is correct |
11 |
Correct |
10 ms |
5072 KB |
Output is correct |
12 |
Correct |
9 ms |
5008 KB |
Output is correct |
13 |
Correct |
12 ms |
5072 KB |
Output is correct |
14 |
Correct |
19 ms |
5096 KB |
Output is correct |
15 |
Correct |
34 ms |
5132 KB |
Output is correct |
16 |
Correct |
33 ms |
5072 KB |
Output is correct |
17 |
Correct |
34 ms |
5136 KB |
Output is correct |
18 |
Correct |
31 ms |
5192 KB |
Output is correct |
19 |
Correct |
31 ms |
5188 KB |
Output is correct |
20 |
Correct |
24 ms |
5072 KB |
Output is correct |
21 |
Correct |
32 ms |
5200 KB |
Output is correct |
22 |
Correct |
15 ms |
5072 KB |
Output is correct |
23 |
Correct |
13 ms |
5096 KB |
Output is correct |
24 |
Correct |
35 ms |
5136 KB |
Output is correct |
25 |
Correct |
34 ms |
5120 KB |
Output is correct |
26 |
Correct |
34 ms |
5132 KB |
Output is correct |
27 |
Correct |
35 ms |
5072 KB |
Output is correct |
28 |
Correct |
34 ms |
5136 KB |
Output is correct |
29 |
Correct |
18 ms |
5072 KB |
Output is correct |
30 |
Correct |
18 ms |
5072 KB |
Output is correct |
31 |
Correct |
3 ms |
5072 KB |
Output is correct |
32 |
Correct |
34 ms |
5072 KB |
Output is correct |
33 |
Correct |
30 ms |
5096 KB |
Output is correct |
34 |
Correct |
22 ms |
5104 KB |
Output is correct |
35 |
Correct |
15 ms |
5072 KB |
Output is correct |
36 |
Correct |
35 ms |
5072 KB |
Output is correct |
37 |
Correct |
37 ms |
5248 KB |
Output is correct |
38 |
Correct |
36 ms |
5208 KB |
Output is correct |
39 |
Correct |
9 ms |
5072 KB |
Output is correct |
40 |
Correct |
18 ms |
5092 KB |
Output is correct |
41 |
Correct |
18 ms |
5104 KB |
Output is correct |
42 |
Correct |
18 ms |
5080 KB |
Output is correct |
43 |
Correct |
1413 ms |
5376 KB |
Output is correct |
44 |
Correct |
1692 ms |
5380 KB |
Output is correct |
45 |
Correct |
1940 ms |
5364 KB |
Output is correct |
46 |
Execution timed out |
3005 ms |
5704 KB |
Time limit exceeded |
47 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
2 ms |
4944 KB |
Output is correct |
3 |
Correct |
18 ms |
5076 KB |
Output is correct |
4 |
Correct |
18 ms |
5072 KB |
Output is correct |
5 |
Correct |
18 ms |
5072 KB |
Output is correct |
6 |
Correct |
18 ms |
5088 KB |
Output is correct |
7 |
Correct |
19 ms |
5080 KB |
Output is correct |
8 |
Correct |
18 ms |
5072 KB |
Output is correct |
9 |
Correct |
2 ms |
4944 KB |
Output is correct |
10 |
Correct |
4 ms |
5052 KB |
Output is correct |
11 |
Correct |
10 ms |
5072 KB |
Output is correct |
12 |
Correct |
9 ms |
5008 KB |
Output is correct |
13 |
Correct |
12 ms |
5072 KB |
Output is correct |
14 |
Correct |
19 ms |
5096 KB |
Output is correct |
15 |
Correct |
34 ms |
5132 KB |
Output is correct |
16 |
Correct |
33 ms |
5072 KB |
Output is correct |
17 |
Correct |
34 ms |
5136 KB |
Output is correct |
18 |
Correct |
31 ms |
5192 KB |
Output is correct |
19 |
Correct |
31 ms |
5188 KB |
Output is correct |
20 |
Correct |
24 ms |
5072 KB |
Output is correct |
21 |
Correct |
32 ms |
5200 KB |
Output is correct |
22 |
Correct |
15 ms |
5072 KB |
Output is correct |
23 |
Correct |
13 ms |
5096 KB |
Output is correct |
24 |
Correct |
35 ms |
5136 KB |
Output is correct |
25 |
Correct |
34 ms |
5120 KB |
Output is correct |
26 |
Correct |
34 ms |
5132 KB |
Output is correct |
27 |
Correct |
35 ms |
5072 KB |
Output is correct |
28 |
Correct |
34 ms |
5136 KB |
Output is correct |
29 |
Correct |
18 ms |
5072 KB |
Output is correct |
30 |
Correct |
18 ms |
5072 KB |
Output is correct |
31 |
Correct |
3 ms |
5072 KB |
Output is correct |
32 |
Correct |
34 ms |
5072 KB |
Output is correct |
33 |
Correct |
30 ms |
5096 KB |
Output is correct |
34 |
Correct |
22 ms |
5104 KB |
Output is correct |
35 |
Correct |
15 ms |
5072 KB |
Output is correct |
36 |
Correct |
35 ms |
5072 KB |
Output is correct |
37 |
Correct |
37 ms |
5248 KB |
Output is correct |
38 |
Correct |
36 ms |
5208 KB |
Output is correct |
39 |
Correct |
9 ms |
5072 KB |
Output is correct |
40 |
Correct |
18 ms |
5092 KB |
Output is correct |
41 |
Correct |
18 ms |
5104 KB |
Output is correct |
42 |
Correct |
18 ms |
5080 KB |
Output is correct |
43 |
Execution timed out |
3052 ms |
8632 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |