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>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <vector>
#include <cmath>
#include <assert.h>
#include <ctime>
#include <math.h>
#include <queue>
#include <string>
#include <numeric>
#include <fstream>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <stack>
#include <random>
#include <list>
#include <bitset>
#include <algorithm>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define pll pair<ll, ll>
#define pii pair<int, int>
#define pdd pair<ld, ld>
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
typedef tree<
pii,
null_type,
less<pii>,
rb_tree_tag,
tree_order_statistics_node_update> ordset;
#pragma GCC optimize("-O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-Os")
ll INF = 2e18;
//mt19937 gen(time(0));
ll gcd(ll n, ll m){
while(n != 0 && m != 0){
if(n > m) n %= m;
else m %= n;
}
return n + m;
}
ll lcm(ll n, ll m){
ll nod = gcd(n, m);
return n / nod * m;
}
ll mod = 1e9 + 7;
ll binpow(ll n, ll m){
if(m == 0) return 1;
if(m % 2ll == 1) {
return (binpow(n, m - 1ll) * 1ll * n) % mod;
}
ll b = binpow(n, m / 2);
return (b * 1ll * b) % mod;
}
int n;
vector<vector<int>> ch;
vector<int> t;
vector<char> t_add;
string cur;
struct str{
int l, r;
string s;
};
inline bool check(int l, int r, char x){
return ch[r][x - 'A'] - (l ? ch[l - 1][x - 'A'] : 0) == r - l + 1;
}
void push(int v, int l, int r){
if(t_add[v] == '.') return;
int m = (l + r) / 2;
t[2*v] = check(l, m - 1, t_add[v]);
t[2*v + 1] = check(m, r - 1, t_add[v]);
t_add[2*v] = t_add[2*v+1] = t_add[v];
t_add[v] = '.';
}
void build(int v, int l, int r){
if(l == r - 1){
t[v] = check(l, l, cur[l]);
return;
}
int m = (l + r) / 2;
build(2*v,l,m);
build(2*v+1,m,r);
t[v] = t[2*v] & t[2*v + 1];
}
void upd(int v, int l, int r, int askl, int askr, char c){
if(l >= askl && r <= askr){
t_add[v] = c;
t[v] = check(l, r - 1, c);
return;
}
if(l >= askr || r <= askl) return;
push(v,l,r);
int m = (l + r) / 2;
upd(2*v,l,m,askl,askr,c);
upd(2*v+1,m,r,askl,askr,c);
t[v] = t[2*v] & t[2*v+1];
}
void solve(){
cin >> n;
ch.resize(n, vector<int>(27, 0));
vector<string> a(3);
unordered_map<string, int> st;
for(int i = 0; i < 3; i++){
cin >> a[i];
st[a[i]] = 1;
}
while(true){
int u = (int)st.size();
int n1 = (int)a.size();
for(int i = 0; i < n1; i++){
for(int j = 0; j < n1; j++){
string s = "";
for(int k = 0; k < n; k++){
if(a[i][k] == a[j][k]) s += a[i][k];
else if (a[i][k] != 'J' && a[j][k] != 'J') s += "J";
else if (a[i][k] != 'O' && a[j][k] != 'O') s += "O";
else if (a[i][k] != 'I' && a[j][k] != 'I') s += "I";
}
if(st.find(s) != st.end()) continue;
else{
a.push_back(s);
st[s] = 1;
}
}
}
if(u == (int)st.size()) break;
}
int q;
cin >> q;
string s;
cin >> s;
vector<str> qq(q);
for(int i = 0; i < q; i++) cin >> qq[i].l >> qq[i].r >> qq[i].s;
vector<int> res(q + 1, 0);
t.resize(4*n);
t_add.resize(4*n);
for(auto& u : st){
ch.assign(n, vector<int>(27, 0));
for(int i = 0; i < n; i++){
if(!i){
ch[i][u.ff[i] - 'A'] = 1;
continue;
}
ch[i] = ch[i - 1];
ch[i][u.ff[i] - 'A']++;
}
t_add.assign(4*n, '.');
cur = s;
build(1, 0, n);
//cout << u.ff << " " << cur << " " << t[1] << '\n';
res[0] |= t[1];
for(int i = 0; i < q; i++){
upd(1, 0, n, qq[i].l - 1, qq[i].r, qq[i].s[0]);
res[i + 1] |= t[1];
}
}
for(int u : res) cout << (u ? "Yes\n" : "No\n");
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int tt;
//cin >> tt;
tt = 1;
while (tt--) {
solve();
}
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... |