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>
using namespace std;
#define ll long long
#define int ll
#define ld long double
#define pii pair<int, int>
#define f first
#define s second
#define boost() cin.tie(0), cin.sync_with_stdio(0)
#define mid ((l + r) / 2)
const int MN = 200005;
int n, a[MN], b[MN], c[MN], d[MN], q, l, r, lzy[MN * 4], st[MN * 4][3][3];
char ch;
int g(char x) {
if (x == 'J') return 0;
if (x == 'O') return 1;
return 2;
}
void push_down(int l, int r, int idx) {
if (lzy[idx] == -1) return;
for (int i = 0; i < 3; i++) {
int cnt = 0;
for (int j = 0; j < 3; j++) {
cnt += st[idx][i][j];
st[idx][i][j] = 0;
}
st[idx][i][lzy[idx]] = cnt;
}
if (l != r) lzy[idx * 2] = lzy[idx * 2 + 1] = lzy[idx];
lzy[idx] = -1;
}
void build(int l, int r, int idx) {
lzy[idx] = -1;
if (l == r) {
st[idx][a[l]][d[l]]++;
return;
}
build(l, mid, idx * 2), build(mid + 1, r, idx * 2 + 1);
for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) st[idx][i][j] = st[idx * 2][i][j] + st[idx * 2 + 1][i][j];
}
void upd(int l, int r, int x, int y, int val, int idx) {
push_down(l, r, idx);
if (r < x || l > y) return;
if (r <= y && l >= x) {
lzy[idx] = val;
push_down(l, r, idx);
return;
}
upd(l, mid, x, y, val, idx * 2), upd(mid + 1, r, x, y, val, idx * 2 + 1);
for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++) st[idx][i][j] = st[idx * 2][i][j] + st[idx * 2 + 1][i][j];
}
void check() {
if (st[1][0][0] + st[1][1][1] + st[1][2][2] == n) printf("Yes\n");
else printf("No\n");
}
int32_t main() {
boost();
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> ch;
a[i] = g(ch);
}
for (int i = 1; i <= n; i++) {
cin >> ch;
b[i] = g(ch);
}
for (int i = 1; i <= n; i++) {
cin >> ch;
c[i] = g(ch);
}
cin >> q;
for (int i = 1; i <= n; i++) {
cin >> ch;
d[i] = g(ch);
}
build(1, n, 1);
check();
while (q--) {
cin >> l >> r >> ch;
int val = g(ch);
upd(1, n, l, r, val, 1);
check();
}
return 0;
}
# | 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... |