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];
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 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)}; }
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 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));
while (q--) {
cin >> u >> v >> ch;
for (int i=u-1; i<v; i++) T[i] = ch;
check(get_hash(T));
}
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... |