| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 684057 | piOOE | Crossing (JOI21_crossing) | C++17 | 0 ms | 0 KiB | 
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;
using ll = long long;
 
string cross(string &a, string &b) {
    string res(a.size(), 'a');
    for (int i = 0; i < a.size(); ++i) {
        if (a[i] == b[i]) {
            res[i] = a[i];
        } else {
            res[i] = 'J' ^ 'O' ^ 'I' ^ a[i] ^ b[i];
        }
    }
    return res;
}
 
constexpr int MOD = 1e9 + 9;
constexpr int P = 239;
 
struct Info {
    int h, power, sum;
 
    Info() = default;
    Info(int a, int b) : h(a), power(b) {}
};
 
vector<Info> t;
vector<int> tag;
int sz;
 
void apply(int x, int y) {
    if (y != -1) {
        t[x].h = 1LL * t[x].sum * y % MOD;
        tag[x] = y;
    }
}
 
void push(int x) {
    apply(x << 1, tag[x]);
    apply(x << 1 | 1, tag[x]);
    tag[x] = -1;
}
 
void pull(int x) {
    t[x].h = (t[x << 1].h + 1LL * t[x << 1].power * P % MOD * t[x << 1 | 1].h) % MOD;
    t[x].power = 1LL * t[x << 1].power * t[x << 1 | 1].power % MOD * P % MOD;
    t[x].sum = (t[x << 1].sum + 1LL * t[x << 1].power * P % MOD * t[x << 1 | 1].sum) % MOD;
}
 
int to_int(char c) {
    return c == 'J' ? 0 : 1 + (c != 'O');
}
 
void init(int n, string T) {
    sz = 1 << __lg(n) + bool(n & (n - 1));
    tag.assign(sz << 1, -1), t.resize(sz << 1);
 
    for (int i = 0; i < n; ++i) {
        t[i + sz].sum = t[i + sz].power = 1;
        t[i + sz].h = to_int(T[i]);
    }
    for (int i = sz - 1; i > 0; --i) {
        pull(i);
    }
}
 
void rangeApply(int l, int r, int tg, int x = 1, int lx = 0, int rx = sz) {
    if (l >= rx || lx >= r) {
        return;
    }
    if (l <= lx && rx <= r) {
        apply(x, tg);
        return;
    }
 
    push(x);
 
    int mid = (lx + rx) >> 1;
 
    rangeApply(l, r, tg, x << 1, lx, mid), rangeApply(l, r, tg, x << 1 | 1, mid, rx);
 
    pull(x);
}
 
int hashed(string &s) {
    int ans = 0;
    for (int i = int(s.size()) - 1; i >= 0; --i) {
        ans = (1LL * ans * P + to_int(s[i])) % MOD;
    }
    return ans;
}
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
 
    int n;
    cin >> n;
 
    string A, B, C;
    cin >> A >> B >> C;
 
    unordered_set<string> every{A, B, C};
 
    queue<string> qu;
    qu.push(A), qu.push(B), qu.push(C);
 
    while (!qu.empty()) {
        string s = qu.front();
        qu.pop();
 
        for (string to : every) {
            string res = cross(s, to);
 
            if (!every.count(res)) {
                qu.push(res);
                every.insert(res);
            }
        }
    }
 
    unordered_set<int> st;
    for (string s : every) {
        st.insert(hashed(s));
    }
 
    int q;
    cin >> q;
 
    string T;
    cin >> T;
 
    init(n, T);
 
    cout << (st.count(t[1].h) ? "Yes\n" : "No\n");
 
    while (q--) {
        int l, r;
        char c;
        cin >> l >> r >> c;
 
        rangeApply(l - 1, r, to_int(c));
 
        cout << (st.count(t[1].h) ? "Yes\n" : "No\n");
    }
 
    return 0;
}
