#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int Max = 2e5 + 1;
const int Mod = 1e9 + 2022;
ll n, m, dp[Max][2];
void update(int node, int left, int right, int idx) {
if (left == idx && right == idx) {
swap(dp[node][0], dp[node][1]);
return;
}
int mid = (left + right) / 2;
int l = node * 2 + 1;
int r = node * 2 + 2;
if (idx <= mid) {
update(l, left, mid, idx);
}
else {
update(r, mid + 1, right, idx);
}
dp[node][0] = dp[l][1] * dp[r][0] + dp[l][0] * dp[r][1] + 2 * dp[l][0] * dp[r][0];
dp[node][1] = dp[l][1] * dp[r][0] + dp[l][0] * dp[r][1] + 2 * dp[l][1] * dp[r][1];
dp[node][0] %= Mod;
dp[node][1] %= Mod;
}
void build(int node, int left, int right, vector<int>& a) {
if (left == right) {
dp[node][a[left]] = 1;
return;
}
int mid = (left + right) / 2;
int l = node * 2 + 1;
int r = node * 2 + 2;
build(l, left, mid, a);
build(r, mid + 1, right, a);
dp[node][0] = dp[l][1] * dp[r][0] + dp[l][0] * dp[r][1] + 2 * dp[l][0] * dp[r][0];
dp[node][1] = dp[l][1] * dp[r][0] + dp[l][0] * dp[r][1] + 2 * dp[l][1] * dp[r][1];
dp[node][0] %= Mod;
dp[node][1] %= Mod;
}
void init(int N, int M, vector<int> P, vector<int> A) {
n = N, m = M;
build(0, 0, M - 1, A);
}
int count_ways(int L, int R) {
update(0, 0, m - 1, L - n);
return dp[0][1];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
386 ms |
3400 KB |
Output is correct |
2 |
Correct |
534 ms |
4044 KB |
Output is correct |
3 |
Correct |
541 ms |
4044 KB |
Output is correct |
4 |
Correct |
604 ms |
4116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
386 ms |
3400 KB |
Output is correct |
2 |
Correct |
534 ms |
4044 KB |
Output is correct |
3 |
Correct |
541 ms |
4044 KB |
Output is correct |
4 |
Correct |
604 ms |
4116 KB |
Output is correct |
5 |
Incorrect |
485 ms |
3404 KB |
1st lines differ - on the 1st token, expected: '105182172', found: '2777846' |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
3rd lines differ - on the 1st token, expected: '0', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |