This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,sse,sse2,sse3,ssse3,sse4,abm,popcnt,mmx")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef complex<double> cd;
constexpr ll INF64 = 9'000'000'000'000'000'000, INF32 = 2'000'000'000, MOD = 1'000'000'007, p = 239;
constexpr db PI = acos(-1);
constexpr bool IS_FILE = false, IS_TEST_CASES = false;
random_device rd;
mt19937 rnd32(rd());
mt19937_64 rnd64(rd());
template<typename T>
bool assign_max(T& a, T b) {
if (b > a) {
a = b;
return true;
}
return false;
}
template<typename T>
bool assign_min(T& a, T b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template<typename T>
T square(T a) {
return a * a;
}
template<>
struct std::hash<pair<ll, ll>> {
ll operator() (pair<ll, ll> p) const {
return ((__int128)p.first * MOD + p.second) % INF64;
}
};
map<pair<char, char>, char> m;
set<ll> can;
string make(string& s1, string& s2) {
string ans(s1.size(), '.');
for (ll i = 0; i < s1.size(); i++) {
ans[i] = m[make_pair(s1[i], s2[i])];
}
return ans;
}
ll calc(string& s) {
ll ans = 0, now = 1;
for (auto i : s) {
ans += (i - 'A') * now;
ans %= MOD;
now *= p;
now %= MOD;
}
return ans;
}
void rec(string& s, string& s1, string& s2, string& s3) {
can.insert(calc(s));
s = make(s, s1);
if (can.find(calc(s)) == can.end()) {
rec(s, s1, s2, s3);
}
s = make(s, s1);
s = make(s, s2);
if (can.find(calc(s)) == can.end()) {
rec(s, s1, s2, s3);
}
s = make(s, s2);
s = make(s, s3);
if (can.find(calc(s)) == can.end()) {
rec(s, s1, s2, s3);
}
s = make(s, s3);
}
vector<ll> pp, ppref;
struct segment_tree {
vector<ll> tree, m;
ll size;
segment_tree(ll n) {
size = 1;
while (size < n) {
size *= 2;
}
tree.resize(size * 2, 0);
m.resize(size * 2, -1);
}
void set(ll v, ll l, ll r, ll x) {
m[v] = x;
tree[v] = x * ppref[r - l] % MOD;
}
void push(ll v, ll l, ll r) {
if (m[v] == -1) {
return;
}
ll mid = (l + r) / 2;
set(v * 2, l, mid, m[v]);
set(v * 2 + 1, mid, r, m[v]);
m[v] = -1;
}
ll get() {
return tree[1];
}
void set(ll l, ll r, ll x) {
set(1, 0, size, l, r, x);
}
void set(ll v, ll l, ll r, ll ql, ll qr, ll x) {
if (ql <= l && r <= qr) {
set(v, l, r, x);
return;
}
if (qr <= l || r <= ql) {
return;
}
push(v, l, r);
ll mid = (l + r) / 2;
set(v * 2, l, mid, ql, qr, x);
set(v * 2 + 1, mid, r, ql, qr, x);
tree[v] = (tree[v * 2] + (tree[v * 2 + 1] * pp[mid - l])) % MOD;
}
};
void solve() {
m[make_pair('O', 'O')] = 'O';
m[make_pair('O', 'I')] = 'J';
m[make_pair('O', 'J')] = 'I';
m[make_pair('I', 'O')] = 'J';
m[make_pair('I', 'I')] = 'I';
m[make_pair('I', 'J')] = 'O';
m[make_pair('J', 'O')] = 'I';
m[make_pair('J', 'I')] = 'O';
m[make_pair('J', 'J')] = 'J';
ll n;
cin >> n;
pp.push_back(1);
while (pp.size() < n * 2) {
pp.push_back(pp.back() * p % MOD);
}
ppref.push_back(0);
for (auto i : pp) {
ppref.push_back((ppref.back() + i) % MOD);
}
string s1, s2, s3;
cin >> s1 >> s2 >> s3;
string s = s1;
rec(s, s1, s2, s3);
segment_tree st(n);
ll q;
cin >> q;
cin >> s;
for (ll i = 0; i < n; i++) {
st.set(i, i + 1, s[i] - 'A');
}
cout << (can.find(st.get()) == can.end() ? "No" : "Yes") << '\n';
for (ll i = 0; i < q; i++) {
ll l, r;
char c;
cin >> l >> r >> c;
l--;
st.set(l, r, c - 'A');
cout << (can.find(st.get()) == can.end() ? "No" : "Yes") << '\n';
}
}
int main() {
if (IS_FILE) {
freopen("", "r", stdin);
freopen("", "w", stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll t = 1;
if (IS_TEST_CASES) {
cin >> t;
}
for (ll i = 0; i < t; i++) {
solve();
}
}
Compilation message (stderr)
Main.cpp: In function 'std::string make(std::string&, std::string&)':
Main.cpp:56:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for (ll i = 0; i < s1.size(); i++) {
| ~~^~~~~~~~~~~
Main.cpp: In function 'void solve()':
Main.cpp:153:26: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
153 | while (pp.size() < n * 2) {
| ~~~~~~~~~~^~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:184:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
184 | freopen("", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~
Main.cpp:185:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
185 | freopen("", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~
# | 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... |