#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define fr first
#define sc second
#define int long long
#define rc(s) return cout<<s,0
#define rcc(s) cout<<s,exit(0)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int nmax = 200005;
const int mod = 1e9 + 7;
const int p = 101;
int n, q, pw[nmax], tree[4*nmax], lazy[4*nmax], sump[nmax];
string Sa, Sb, Sc, T0;
int generatehash(string aux){
int hsh = 0;
for(int i=0;i<(int)aux.size();i++){
hsh = (hsh + pw[i] * (aux[i] - '0') % mod) % mod;
}
return hsh;
}
vector<int>vecc;
string comb(string a, string b){
string aux = "";
for(int t=0;t<n;t++){
if(a[t] == b[t]){
aux += a[t];
}
else if(a[t] != '1' && b[t] != '1'){
aux += '1';
}
else if(a[t] != '0' && b[t] != '0'){
aux += '0';
}
else{
aux += '2';
}
}
return aux;
}
void calc(){
string aux = comb(Sa, Sb);
vecc.push_back(generatehash(aux));
aux = comb(Sa, Sc);
vecc.push_back(generatehash(aux));
aux = comb(Sb, Sc);
vecc.push_back(generatehash(aux));
aux = comb(Sa, Sb);
aux = comb(aux, Sc);
vecc.push_back(generatehash(aux));
aux = comb(Sb, Sc);
aux = comb(aux, Sa);
vecc.push_back(generatehash(aux));
aux = comb(Sa, Sc);
aux = comb(aux, Sb);
vecc.push_back(generatehash(aux));
}
void build(int l, int r, int nod){
if(l == r){
tree[nod] = (T0[l - 1] - '0');
}
else{
int mid = l + (r - l) / 2;
build(l, mid, 2*nod);
build(mid+1, r, 2*nod+1);
tree[nod] = (tree[2*nod] + pw[(mid - l + 1)] * tree[2*nod + 1] % mod) % mod;
}
}
void push(int l, int r, int nod){
if(lazy[nod] >= 1){
tree[nod] = (lazy[nod] - 1LL) * sump[r - l] % mod;
if(l != r){
lazy[2*nod] = lazy[nod];
lazy[2*nod+1] = lazy[nod];
}
lazy[nod] = 0;
}
}
void update(int l, int r, int le, int ri, int val, int nod){
push(l, r, nod);
if(l > ri || r < le){
return;
}
else if(l >= le && r <= ri){
lazy[nod] = val;
push(l, r, nod);
}
else{
int mid = l + (r - l) / 2;
update(l, mid, le, ri, val, 2*nod);
update(mid + 1, r, le, ri, val, 2*nod + 1);
tree[nod] = (tree[2*nod] + pw[(mid - l + 1)] * tree[2*nod + 1] % mod) % mod;
}
}
bool check(){
push(1, n, 1);
for(auto it : vecc){
if(it == tree[1]){
return true;
}
}
return false;
}
int32_t main(){
//ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
freopen("input.in", "r", stdin);
pw[0] = 1;
sump[0] = 1;
for(int i=1;i<nmax;i++){
pw[i] = pw[i-1] * p % mod;
sump[i] = (sump[i-1] + pw[i]) % mod;
}
cin >> n >> Sa >> Sb >> Sc >> q >> T0;
for(auto &it : Sa){
if(it == 'J') it = '0';
else if(it == 'O') it = '1';
else it = '2';
}
for(auto &it : Sb){
if(it == 'J') it = '0';
else if(it == 'O') it = '1';
else it = '2';
}
for(auto &it : Sc){
if(it == 'J') it = '0';
else if(it == 'O') it = '1';
else it = '2';
}
for(auto &it : T0){
if(it == 'J') it = '0';
else if(it == 'O') it = '1';
else it = '2';
}
vecc.push_back(generatehash(Sa));
vecc.push_back(generatehash(Sb));
vecc.push_back(generatehash(Sc));
calc();
build(1, n, 1);
cout << (check() == true ? "Yes" : "No") << '\n';
for(int i=1;i<=q;i++){
int l, r;
char c;
cin >> l >> r >> c;
int val;
if(c == 'J') val = 1;
else if(c == 'O') val = 2;
else val = 3;
update(1, n, l, r, val, 1);
cout << (check() == true ? "Yes" : "No") << '\n';
}
}
// 1. Solve the problem
// 2. ???
// 3. Profit
Compilation message
Main.cpp: In function 'int32_t main()':
Main.cpp:123:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
123 | freopen("input.in", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
8 ms |
6732 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
8 ms |
6732 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
8 ms |
6732 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
8 ms |
6732 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |