#include "circuit.h"
#include <vector>
#include <array>
#include <iostream>
using namespace std;
constexpr int P = 1E9 + 2022;
int norm(int x) {
if (x < 0) x += P;
if (x >= P) x -= P;
return x;
}
struct Z {
int x;
Z(int x = 0) : x(norm(x)) {}
int val() { return x; }
friend Z operator+(const Z &a, const Z &b) {
return Z(a.x + b.x);
}
friend Z operator-(const Z &a, const Z &b) {
return Z(a.x - b.x);
}
friend Z operator*(const Z &a, const Z &b) {
return Z(int(a.x * 1LL * b.x % P));
}
void operator += (const Z &o) {
*this = *this + o;
}
};
int n, m;
vector<int> a;
vector<vector<int>> e;
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
n = N;
m = M;
e.resize(n);
a = A;
for (int i = 1; i < n + m; i++) {
e[P[i]].push_back(i);
}
}
int count_ways(int L, int R) {
R++;
L -= n;
R -= n;
for (int i = L; i < R; i++) {
a[i] ^= 1;
}
// for (int i = 0; i < m; i++) cout << a[i];
// cout << "\n";
vector<array<Z, 2>> res(n + m);
for (int i = 0; i < m; i++) {
res[n + i][a[i]] = 1;
}
for (int i = n - 1; i >= 0; i--) {
vector<Z> dp(e[i].size() + 1);
dp[0] = 1;
for (int j : e[i]) {
vector<Z> ndp(e[i].size() + 1);
for (int k = e[i].size(); k >= 0; k--) {
if (k < int(e[i].size())) {
ndp[k + 1] += dp[k] * res[j][1];
}
ndp[k] += dp[k] * res[j][0];
}
dp = ndp;
}
// cout << "node " << i << ": ";
// for (int i = 0; i < int(dp.size()); i++) {
// cout << dp[i].val() << " ";
// }
// cout << "\n";
int c = e[i].size();
res[i][0] += dp[0] * c;
for (int j = 1; j < int(dp.size()); j++) {
res[i][1] += dp[j] * j;
res[i][0] += dp[j] * (c - j);
}
}
return res[0][1].val();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
23 ms |
328 KB |
Output is correct |
4 |
Correct |
25 ms |
336 KB |
Output is correct |
5 |
Correct |
26 ms |
336 KB |
Output is correct |
6 |
Correct |
25 ms |
336 KB |
Output is correct |
7 |
Correct |
25 ms |
336 KB |
Output is correct |
8 |
Correct |
25 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
23 ms |
328 KB |
Output is correct |
4 |
Correct |
25 ms |
336 KB |
Output is correct |
5 |
Correct |
26 ms |
336 KB |
Output is correct |
6 |
Correct |
25 ms |
336 KB |
Output is correct |
7 |
Correct |
25 ms |
336 KB |
Output is correct |
8 |
Correct |
25 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
292 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
292 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
25 ms |
208 KB |
Output is correct |
30 |
Correct |
25 ms |
324 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
2 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
5 ms |
208 KB |
Output is correct |
36 |
Correct |
1 ms |
336 KB |
Output is correct |
37 |
Correct |
25 ms |
336 KB |
Output is correct |
38 |
Correct |
26 ms |
396 KB |
Output is correct |
39 |
Correct |
1 ms |
336 KB |
Output is correct |
40 |
Correct |
1 ms |
336 KB |
Output is correct |
41 |
Correct |
1 ms |
336 KB |
Output is correct |
42 |
Correct |
1 ms |
208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3088 ms |
3096 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3088 ms |
3096 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Execution timed out |
3088 ms |
3096 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
23 ms |
328 KB |
Output is correct |
4 |
Correct |
25 ms |
336 KB |
Output is correct |
5 |
Correct |
26 ms |
336 KB |
Output is correct |
6 |
Correct |
25 ms |
336 KB |
Output is correct |
7 |
Correct |
25 ms |
336 KB |
Output is correct |
8 |
Correct |
25 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
292 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
292 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
25 ms |
208 KB |
Output is correct |
30 |
Correct |
25 ms |
324 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
2 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
5 ms |
208 KB |
Output is correct |
36 |
Correct |
1 ms |
336 KB |
Output is correct |
37 |
Correct |
25 ms |
336 KB |
Output is correct |
38 |
Correct |
26 ms |
396 KB |
Output is correct |
39 |
Correct |
1 ms |
336 KB |
Output is correct |
40 |
Correct |
1 ms |
336 KB |
Output is correct |
41 |
Correct |
1 ms |
336 KB |
Output is correct |
42 |
Correct |
1 ms |
208 KB |
Output is correct |
43 |
Execution timed out |
3092 ms |
544 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
23 ms |
328 KB |
Output is correct |
4 |
Correct |
25 ms |
336 KB |
Output is correct |
5 |
Correct |
26 ms |
336 KB |
Output is correct |
6 |
Correct |
25 ms |
336 KB |
Output is correct |
7 |
Correct |
25 ms |
336 KB |
Output is correct |
8 |
Correct |
25 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
292 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
292 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
25 ms |
208 KB |
Output is correct |
30 |
Correct |
25 ms |
324 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
2 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
5 ms |
208 KB |
Output is correct |
36 |
Correct |
1 ms |
336 KB |
Output is correct |
37 |
Correct |
25 ms |
336 KB |
Output is correct |
38 |
Correct |
26 ms |
396 KB |
Output is correct |
39 |
Correct |
1 ms |
336 KB |
Output is correct |
40 |
Correct |
1 ms |
336 KB |
Output is correct |
41 |
Correct |
1 ms |
336 KB |
Output is correct |
42 |
Correct |
1 ms |
208 KB |
Output is correct |
43 |
Execution timed out |
3088 ms |
3096 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |