#include <bits/stdc++.h>
using namespace std;
#define int long long // a.k.a. TLE creator
#define all(x) x.begin(), x.end()
template<class A, class B> istream& operator >>(istream &o, pair<A, B> &x){return o >> x.first >> x.second;}
template<class A, class B> ostream& operator <<(ostream &o, pair<A, B> &x){return o << x.first << ' ' << x.second << ' ';}
void setIO(){ios::sync_with_stdio(false); cin.tie(0);}
const int INF = 2e18, MOD = 998244353, N = 2e5 + 2;
int pw[N]{}, p = 9973;
void init(){
pw[0] = 1;
for(int i = 1; i < N; i++)pw[i] = pw[i - 1] * p % MOD;
}
struct Hash{
vector<int> h;
Hash(string s){
h.resize(s.size() + 1);
for(int i = 0; i < s.size(); i++){
h[i + 1] = (h[i] * p + s[i]) % MOD;
}
}
int get(int l, int r){
int ans = h[r + 1] - h[l] * pw[r - l + 1] % MOD;
if(ans < 0)ans += MOD;
return ans;
}
}J(string(N, 'J')), O(string(N, 'O')), I(string(N, 'I'));
int get(char c, int sz){
if(c == 'J')return J.get(0, sz - 1);
else if(c == 'O')return O.get(0, sz - 1);
else return I.get(0, sz - 1);
}
#define lc (p << 1)
#define rc (p << 1 | 1)
struct node{
int h, sz;
char lz = 'a';
void push(char c){
lz = c;
h = get(c, sz);
}
}seg[N << 2];
void pull(int p){seg[p].h = (seg[lc].h * pw[seg[rc].sz] + seg[rc].h) % MOD;}
void push(int p){
if(seg[p].lz != 'a'){
char &c = seg[p].lz;
seg[lc].push(c);
seg[rc].push(c);
c = 'a';
}
}
string t;
int n;
void build(int p = 1, int l = 0, int r = n){
seg[p].sz = r - l;
if(r - l == 1)return void(seg[p].h = t[l]);
int m = l + r >> 1;
build(lc, l, m);
build(rc, m, r);
pull(p);
}
void chg(int a, int b, char c, int p = 1, int l = 0, int r = n){
if(a <= l && b >= r)return void(seg[p].push(c));
push(p);
int m = l + r >> 1;
if(a < m)chg(a, b, c, lc, l, m);
if(b > m)chg(a, b, c, rc, m, r);
pull(p);
}
int qry(){return seg[1].h;}
vector<int> val;
bool good(int h){
for(int i : val)if(i == h)return true;
return false;
}
string joi = "JOI";
string cross(string i, string j){
string ans;
for(int k = 0; k < n; k++){
if(i[k] != j[k]){
for(char c : joi)if(i[k] != c && j[k] != c){
ans[k] = c;
break;
}
}else ans[k] = i[k];
}
return ans;
}
int oneHash(string s){
int v = 0;
for(int j = 0; j < n; j++){
v = (v * p + s[j]) % MOD;
}
return v;
}
signed main(){
setIO();
init();
cin >> n;
string s[3];
for(auto &i : s)cin >> i;
val.push_back(oneHash(s[0]));
val.push_back(oneHash(s[1]));
val.push_back(oneHash(s[2]));
val.push_back(oneHash(cross(s[0], s[1])));
val.push_back(oneHash(cross(s[0], s[2])));
val.push_back(oneHash(cross(s[1], s[2])));
val.push_back(oneHash(cross(s[0], cross(s[1], s[2]))));
val.push_back(oneHash(cross(s[1], cross(s[0], s[2]))));
val.push_back(oneHash(cross(s[2], cross(s[0], s[1]))));
int q;
cin >> q >> t;
build();
cout << (good(qry()) ? "YES\n" : "NO\n");
for(int i = 0; i < q; i++){
int l, r;
char c;
cin >> l >> r >> c;
--l;
chg(l, r, c);
cout << (good(qry()) ? "YES\n" : "NO\n");
}
}
Compilation message
Main.cpp: In constructor 'Hash::Hash(std::string)':
Main.cpp:21:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | for(int i = 0; i < s.size(); i++){
| ~~^~~~~~~~~~
Main.cpp: In function 'void build(long long int, long long int, long long int)':
Main.cpp:67:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
67 | int m = l + r >> 1;
| ~~^~~
Main.cpp: In function 'void chg(long long int, long long int, char, long long int, long long int, long long int)':
Main.cpp:76:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
76 | int m = l + r >> 1;
| ~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
36 ms |
51656 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
36 ms |
51656 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
36 ms |
51656 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
36 ms |
51656 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |