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>
#define int long long
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define kill(x) cout << x << "\n", exit(0);
#define pii pair<int, int>
#define pll pair<long long, long long>
#define endl "\n"
using namespace std;
typedef long long ll;
// typedef __int128_t lll;
typedef long double ld;
const int MAXN = (int)1e6 + 7;
const int MOD[] = {(int)1e9 + 11, 998244853};
const int B[] = {34, 9};
const ll INF = (ll)1e9 + 7;
int n, m, k, tmp, t, tmp2, tmp3, tmp4, u, v, w, flag, q, ans, N, X, Y, inv2;
int arr[MAXN], p[2][MAXN], ps[2][3][MAXN];
string Ss[3], T; char ch;
set<pii> st;
inline void check(pii x) {
if (st.find(x) == st.end()) cout << "No\n";
else cout << "Yes\n";
}
inline int f(char ch) {
if (ch == 'J') return 0;
if (ch == 'O') return 1;
return 2;
}
inline string cross(string u, string v) {
string res = "";
for (int i=0; i<n; i++) {
if (u[i] == v[i]) res.pb(u[i]);
else if (u[i] != 'I' && v[i] != 'I') res.pb('I');
else if (u[i] != 'O' && v[i] != 'O') res.pb('O');
else res.pb('J');
}
return res;
}
inline int _get_hash(string s, int ind) {
int res = 0;
for (int i=0; i<n; i++) {
if (s[i] == 'J') res = (res*B[ind] + 0)%MOD[ind];
else if (s[i] == 'O') res = (res*B[ind] + 1)%MOD[ind];
else res = (res*B[ind] + 2)%MOD[ind];
}
return res;
}
inline pii get_hash(string s) { return {_get_hash(s, 0), _get_hash(s, 1)}; }
/* Segment Tree */
#define mid ((l+r)>>1)
#define lid (id<<1)
#define rid (lid|1)
struct Node {
pii hsh; int sz;
Node () {}
} seg[MAXN<<2];
int lazy[MAXN<<2];
inline void set_val(int l, int r, int id, int x) {
seg[id].hsh.F = ps[0][x][r-l];
seg[id].hsh.S = ps[1][x][r-l];
}
inline void relax(int l, int r, int id) {
if (lazy[id] == -1) return;
set_val(l, mid, lid, lazy[id]); lazy[lid] = lazy[id];
set_val(mid, r, rid, lazy[id]); lazy[rid] = lazy[id];
lazy[id] = -1;
}
inline Node merge(Node x, Node y) {
Node res;
res.sz = x.sz + y.sz;
res.hsh.F = (x.hsh.F*p[0][y.sz]%MOD[0] + y.hsh.F)%MOD[0];
res.hsh.S = (x.hsh.S*p[1][y.sz]%MOD[1] + y.hsh.S)%MOD[1];
return res;
}
void build(int l=0, int r=n, int id=1) {
lazy[id] = -1;
if (l+1 == r) {
seg[id].sz = 1; set_val(l, r, id, f(T[l]));
return;
}
build(l, mid, lid);
build(mid, r, rid);
seg[id] = merge(seg[lid], seg[rid]);
}
void upd(int s, int t, int x, int l=0, int r=n, int id=1) {
if (s >= t) return;
if (s <= l && t >= r) {
set_val(l, r, id, x); lazy[id] = x;
return;
}
relax(l, r, id);
if (s < mid) upd(s, t, x, l, mid, lid);
if (t > mid) upd(s, t, x, mid, r, rid);
seg[id] = merge(seg[lid], seg[rid]);
}
/* Segment Tree */
int32_t main() {
#ifdef LOCAL
freopen("inp.in", "r", stdin);
freopen("res.out", "w", stdout);
#else
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#endif
cin >> n;
cin >> Ss[0] >> Ss[1] >> Ss[2];
for (int j=0; j<2; j++) {
p[j][0] = 1;
for (int i=1; i<MAXN; i++) p[j][i] = p[j][i-1]*B[j]%MOD[j];
}
for (int o=0; o<2; o++) {
for (int j=0; j<3; j++) {
ps[o][j][0] = 0;
for (int i=1; i<MAXN; i++) ps[o][j][i] = (ps[o][j][i-1]*B[o] + j)%MOD[o];
}
}
for (int i=0; i<3; i++) {
st.insert(get_hash(Ss[i]));
for (int j=0; j<3; j++) st.insert(get_hash(cross(Ss[i], Ss[j])));
for (int j=0; j<3; j++) for (int k=0; k<3; k++) st.insert(get_hash(cross(cross(Ss[i], Ss[j]), Ss[k])));
}
cin >> q >> T; check(get_hash(T)); build();
while (q--) {
cin >> u >> v >> ch;
upd(u-1, v, f(ch));
check(seg[1].hsh);
}
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... |