This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "circuit.h"
typedef long long int64;
using namespace std;
const int64 mod = 1000002022;
const int maxn = 2e5 + 2;
// vector <int> ad [maxn];
int64 dp[4 * maxn][2];
int64 lazy[4 * maxn];
int n,m;
void build (int x) {
if (x >= n) return;
int l = x * 2 + 1, r = x * 2 + 2;
build(l); build(r);
dp[x][0] = ((dp[l][0] * dp[r][0] * 2 % mod) + (dp[l][0] * dp[r][1] % mod) + (dp[l][1] * dp[r][0] % mod)) % mod;
dp[x][1] = ((dp[l][1] * dp[r][1] * 2 % mod) + (dp[l][0] * dp[r][1] % mod) + (dp[l][1] * dp[r][0] % mod)) % mod;
}
void init(int N, int M, vector<int> P, vector<int> A) {
n = N, m = M;
for (int i = 0; i < M; i++){
dp[N+i][A[i]] = 1;
}
build(0);
}
void push (int x, int nl, int nr) {
if (!lazy[x]) return;
swap(dp[nl][0], dp[nl][1]);
swap(dp[nr][0], dp[nr][1]);
lazy[nl] = !lazy[nl];
lazy[nr] = !lazy[nr];
lazy[x] = 0;
}
void upd (int x, int l, int r, int il, int ir) {
// cout << x << " " << l << " " << r << " " << il << " " << ir << "\n";
int nl = x * 2 + 1, nr = x * 2 + 2;
if (il <= l && r <= ir) {
lazy[x] = !lazy[x];
swap(dp[x][0], dp[x][1]);
return;
}
if (l > ir || r < il) return;
int mid = (l + r) / 2;
push(x, nl, nr);
upd(nl, l, mid, il, ir); upd(nr, mid + 1, r, il, ir);
dp[x][0] = ((dp[nl][0] * dp[nr][0] * 2 % mod) + (dp[nl][0] * dp[nr][1] % mod) + (dp[nl][1] * dp[nr][0] % mod)) % mod;
dp[x][1] = ((dp[nl][1] * dp[nr][1] * 2 % mod) + (dp[nl][0] * dp[nr][1] % mod) + (dp[nl][1] * dp[nr][0] % mod)) % mod;
}
int count_ways(int L, int R) {
// for (int i = L; i <= R; i++){
// swap(dp[i][0], dp[i][1]);
// }
upd(0, n, n + m - 1, L, R);
return dp[0][1];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |