#include <bits/stdc++.h>
using namespace std;
char other( char a, char b ) {
if ( a != 'J' && b != 'J' )
return 'J';
if ( a != 'O' && b != 'O' )
return 'O';
return 'I';
}
string combine( string a, string b ) {
string ans;
ans.resize( a.size() );
for ( int i = 0; i < a.size(); i++ )
ans[i] = (a[i] == b[i] ? a[i] : other( a[i], b[i] ) );
return ans;
}
const int MAX_N = 2e5;
const int undef = -1;
vector<string> ss;
string t;
struct AINT {
struct info {
bool ok;
int nrJ, nrO, nrI;
info operator + ( info x ) {
return { (ok && x.ok), nrJ + x.nrJ, nrO + x.nrO, nrI + x.nrI };
}
};
info aint[4 * MAX_N];
char lazy[4 * MAX_N];
void propag( int v, int l, int r ) {
if ( lazy[v] == undef )
return;
if ( lazy[v] == 'J' )
aint[v].ok = (aint[v].nrJ == r - l + 1);
else if ( lazy[v] == 'O' )
aint[v].ok = (aint[v].nrO == r - l + 1);
else
aint[v].ok = (aint[v].nrI == r - l + 1);
if ( l != r )
lazy[v * 2 + 1] = lazy[v * 2 + 2] = lazy[v];
lazy[v] = undef;
}
void init( int v, int l, int r, int i ) {
lazy[v] = undef;
if ( l == r ) {
aint[v] = { (ss[i][l] == t[l]), (ss[i][l] == 'J'), (ss[i][l] == 'O'), (ss[i][l] == 'I') };
return;
}
int mid = (l + r) / 2;
init( v * 2 + 1, l, mid, i );
init( v * 2 + 2, mid + 1, r, i );
aint[v] = aint[v * 2 + 1] + aint[v * 2 + 2];
}
void update( int v, int l, int r, int lu, int ru, char ch ) {
propag( v, l, r );
if ( l > ru || r < lu )
return;
if ( lu <= l && r <= ru ) {
lazy[v] = ch;
propag( v, l, r );
//printf( "%d %d %d\n", l, r, aint[v].ok );
return;
}
int mid = (l + r) / 2;
update( v * 2 + 1, l, mid, lu, ru, ch );
update( v * 2 + 2, mid + 1, r, lu, ru, ch );
aint[v] = aint[v * 2 + 1] + aint[v * 2 + 2];
//printf( "%d %d %d\n", l, r, aint[v].ok );
}
} coco[9];
int main() {
int n, q;
string s1, s2, s3;
cin >> n >> s1 >> s2 >> s3;
set<string> s;
s.insert( s1 );
s.insert( s2 );
s.insert( s3 );
bool isNew = true;
while ( isNew ) {
isNew = false;
set<string> newS;
for ( string x: s ) {
string y1 = combine( x, s1 );
string y2 = combine( x, s2 );
string y3 = combine( x, s3 );
if ( s.find( y1 ) == s.end() && newS.find( y1 ) == newS.end() ) {
isNew = true;
newS.insert( y1 );
}
if ( s.find( y2 ) == s.end() && newS.find( y2 ) == newS.end() ) {
isNew = true;
newS.insert( y2 );
}
if ( s.find( y3 ) == s.end() && newS.find( y3 ) == newS.end() ) {
isNew = true;
newS.insert( y3 );
}
}
for ( string x: newS )
s.insert( x );
}
if ( s.size() > 9 )
return 1;
for ( string x: s )
ss.push_back( x ), cout << x << "\n";
cin >> q >> t;
int m = ss.size();
for ( int i = 0; i < ss.size(); i++ )
coco[i].init( 0, 0, n - 1, i );
bool ok = false;
for ( int i = 0; i < m; i++ )
ok |= coco[i].aint[0].ok;
cout << (ok ? "Yes\n" : "No\n");
while ( q-- ) {
int l, r;
char ch;
cin >> l >> r >> ch;
l--;
r--;
for ( int i = 0; i < m; i++ )
coco[i].update( 0, 0, n - 1, l, r, ch );
bool ok = false;
for ( int i = 0; i < m; i++ )
ok |= coco[i].aint[0].ok;
cout << (ok ? "Yes\n" : "No\n");
}
return 0;
}
Compilation message
Main.cpp: In function 'std::string combine(std::string, std::string)':
Main.cpp:17:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | for ( int i = 0; i < a.size(); i++ )
| ~~^~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:140:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
140 | for ( int i = 0; i < ss.size(); i++ )
| ~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
358 ms |
3924 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
358 ms |
3924 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
358 ms |
3924 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
358 ms |
3924 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |