#include <bits/stdc++.h>
#include <fstream>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template<class A, class B>
ostream& operator<<(ostream& o, const pair<A, B>& p) {return o << '(' << p.first << ", " << p.second << ')';}
template<size_t Index = 0, typename... Types>
ostream& printTupleElements(ostream& o, const tuple<Types...>& t) {if constexpr (Index < sizeof...(Types)){if(Index > 0){o << ", ";}o << get<Index>(t);printTupleElements<Index + 1>(o, t);}return o;}
template<typename... Types>
ostream& operator<<(ostream& o, const tuple<Types...>& t){o << "(";printTupleElements(o, t);return o << ")";}
template<class T>
auto operator<<(ostream& o, const T& x) -> decltype(x.end(), o){o << '{';bool first = true;for (const auto& e : x){if (!first){o << ", ";}o << e;first = false;} return o << '}';}
#define DEBUG
#ifdef DEBUG
#define fastio()
#define debug(x...) cerr << "[" #x "]: ", [](auto... $) {((cerr << $ << "; "), ...); }(x), cerr << '\n'
#define check(x) if (!(x)) { cerr << "Check failed: " << #x << " in line " << __LINE__ << endl; exit(1); }
#else
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0);
#define debug(...)
#define check(x)
#endif
typedef long long ll;
#define pi pair<int, int>
#define pll pair<ll, ll>
#define st first
#define nd second
#define vi vector<int>
#define vll vector<ll>
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
void wypisz(string a) {
for(auto x : a) {
cout << x;
}
cout << '\n';
}
vector<char>lit = {'J', 'O', 'I'};
string comb(string a, string b) {
string res = "";
for(int i = 0; i < sz(a); i++) {
if(a[i] == b[i]) {
res += a[i];
}
else {
for(auto x : lit) {
if(x != a[i] && x != b[i]) {
res += x;
}
}
}
}
return res;
}
set<tuple<int, int, char> > getprz(string a) {
set<tuple<int, int, char> >res;
for(int i = 0; i < sz(a); i++) {
int r = i;
while(r + 1 < sz(a) && a[r + 1] == a[i]) {
r++;
}
res.insert(make_tuple(i, r, a[i]));
i = r;
}
return res;
}
void solve() {
//ifstream cin("nazwa.in");
//ofstream cout("nazwa.out");
int n;
cin >> n;
string a, b, c;
cin >> a >> b >> c;
set<string>kt1;
for(int mask = 1; mask < (1 << 3); mask++) {
vector<string>per;
if(mask & (1 << 0)) {
per.eb(a);
}
if(mask & (1 << 1)) {
per.eb(b);
}
if(mask & (1 << 2)) {
per.eb(c);
}
sort(all(per));
do {
string akt = per[0];
for(int i = 1; i < sz(per); i++) {
akt = comb(akt, per[i]);
}
kt1.insert(akt);
}while(next_permutation(all(per)));
}
vector<string>kt;
for(auto x : kt1) {
kt.eb(x);
}
vector<set<tuple<int, int, char> > >prz(sz(kt));
vector<set<tuple<int, int, char> > >przroz(sz(kt));
for(int i = 0; i < sz(kt); i++) {
prz[i] = getprz(kt[i]);
//wypisz(kt[i]);
//debug(prz[i]);
}
int t;
cin >> t;
string s;
cin >> s;
set<tuple<int, int, char> >przs = getprz(s);
for(int i = 0; i < sz(kt); i++) {
for(auto x : przs) {
if(prz[i].find(x) == prz[i].end()) {
przroz[i].insert(x);
}
}
}
while(t >= 0) {
bool czy = 0;
//debug(przs);
for(int i = 0; i < sz(kt); i++) {
//debug(prz[i], przroz[i]);
if(!sz(przroz[i])) {
czy = 1;
}
}
if(czy) {
cout << "Yes\n";
}
else {
cout << "No\n";
}
if(t > 0) {
int l, r;
char zn;
cin >> l >> r >> zn;
l--, r--;
auto it = przs.upper_bound(make_tuple(l, 1e9, 1e9));
it--;
set<tuple<int, int, char> >dod;
set<tuple<int, int, char> >us;
while(it != przs.end()) {
auto [lp, rp, z] = (*it);
if(lp > r) {
break;
}
if(lp < l) {
dod.insert(make_tuple(lp, l - 1, z));
}
if(rp > r) {
dod.insert(make_tuple(r + 1, rp, z));
}
us.insert(*it);
for(int i = 0; i < sz(kt); i++) {
if(przroz[i].find(*it) != przroz[i].end()) {
przroz[i].erase(*it);
}
}
it++;
}
dod.insert(make_tuple(l, r, zn));
for(auto x : us) {
przs.erase(x);
}
for(auto x : dod) {
przs.insert(x);
for(int i = 0; i < sz(kt); i++) {
if(prz[i].find(x) == prz[i].end()) {
przroz[i].insert(x);
}
}
}
}
t--;
}
}
int main() {
fastio();
int t = 1;
//cin >> t;
while(t--) {
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
510 ms |
948 KB |
Output is correct |
2 |
Correct |
560 ms |
852 KB |
Output is correct |
3 |
Correct |
471 ms |
1000 KB |
Output is correct |
4 |
Incorrect |
495 ms |
956 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
510 ms |
948 KB |
Output is correct |
2 |
Correct |
560 ms |
852 KB |
Output is correct |
3 |
Correct |
471 ms |
1000 KB |
Output is correct |
4 |
Incorrect |
495 ms |
956 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
510 ms |
948 KB |
Output is correct |
2 |
Correct |
560 ms |
852 KB |
Output is correct |
3 |
Correct |
471 ms |
1000 KB |
Output is correct |
4 |
Incorrect |
495 ms |
956 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
510 ms |
948 KB |
Output is correct |
2 |
Correct |
560 ms |
852 KB |
Output is correct |
3 |
Correct |
471 ms |
1000 KB |
Output is correct |
4 |
Incorrect |
495 ms |
956 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |