#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 );
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++ )
| ~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
299 ms |
3108 KB |
Output is correct |
2 |
Correct |
319 ms |
4188 KB |
Output is correct |
3 |
Correct |
318 ms |
4088 KB |
Output is correct |
4 |
Correct |
300 ms |
4180 KB |
Output is correct |
5 |
Correct |
300 ms |
3924 KB |
Output is correct |
6 |
Correct |
293 ms |
3924 KB |
Output is correct |
7 |
Correct |
333 ms |
3988 KB |
Output is correct |
8 |
Correct |
315 ms |
4208 KB |
Output is correct |
9 |
Correct |
316 ms |
3916 KB |
Output is correct |
10 |
Correct |
328 ms |
3988 KB |
Output is correct |
11 |
Correct |
320 ms |
4048 KB |
Output is correct |
12 |
Correct |
315 ms |
4028 KB |
Output is correct |
13 |
Correct |
313 ms |
4092 KB |
Output is correct |
14 |
Correct |
339 ms |
4040 KB |
Output is correct |
15 |
Correct |
327 ms |
3920 KB |
Output is correct |
16 |
Correct |
316 ms |
4000 KB |
Output is correct |
17 |
Correct |
309 ms |
3940 KB |
Output is correct |
18 |
Correct |
329 ms |
3984 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
299 ms |
3108 KB |
Output is correct |
2 |
Correct |
319 ms |
4188 KB |
Output is correct |
3 |
Correct |
318 ms |
4088 KB |
Output is correct |
4 |
Correct |
300 ms |
4180 KB |
Output is correct |
5 |
Correct |
300 ms |
3924 KB |
Output is correct |
6 |
Correct |
293 ms |
3924 KB |
Output is correct |
7 |
Correct |
333 ms |
3988 KB |
Output is correct |
8 |
Correct |
315 ms |
4208 KB |
Output is correct |
9 |
Correct |
316 ms |
3916 KB |
Output is correct |
10 |
Correct |
328 ms |
3988 KB |
Output is correct |
11 |
Correct |
320 ms |
4048 KB |
Output is correct |
12 |
Correct |
315 ms |
4028 KB |
Output is correct |
13 |
Correct |
313 ms |
4092 KB |
Output is correct |
14 |
Correct |
339 ms |
4040 KB |
Output is correct |
15 |
Correct |
327 ms |
3920 KB |
Output is correct |
16 |
Correct |
316 ms |
4000 KB |
Output is correct |
17 |
Correct |
309 ms |
3940 KB |
Output is correct |
18 |
Correct |
329 ms |
3984 KB |
Output is correct |
19 |
Correct |
464 ms |
14996 KB |
Output is correct |
20 |
Correct |
462 ms |
15812 KB |
Output is correct |
21 |
Correct |
390 ms |
16304 KB |
Output is correct |
22 |
Correct |
388 ms |
16024 KB |
Output is correct |
23 |
Correct |
365 ms |
7924 KB |
Output is correct |
24 |
Correct |
363 ms |
7576 KB |
Output is correct |
25 |
Correct |
421 ms |
16588 KB |
Output is correct |
26 |
Correct |
427 ms |
16476 KB |
Output is correct |
27 |
Correct |
421 ms |
16596 KB |
Output is correct |
28 |
Correct |
430 ms |
16548 KB |
Output is correct |
29 |
Correct |
403 ms |
16260 KB |
Output is correct |
30 |
Correct |
368 ms |
7736 KB |
Output is correct |
31 |
Correct |
418 ms |
16588 KB |
Output is correct |
32 |
Correct |
446 ms |
16220 KB |
Output is correct |
33 |
Correct |
371 ms |
7660 KB |
Output is correct |
34 |
Correct |
423 ms |
16496 KB |
Output is correct |
35 |
Correct |
389 ms |
15792 KB |
Output is correct |
36 |
Correct |
365 ms |
7704 KB |
Output is correct |
37 |
Correct |
363 ms |
7588 KB |
Output is correct |
38 |
Correct |
439 ms |
16308 KB |
Output is correct |
39 |
Correct |
384 ms |
16480 KB |
Output is correct |
40 |
Correct |
395 ms |
11540 KB |
Output is correct |
41 |
Correct |
484 ms |
16924 KB |
Output is correct |
42 |
Correct |
320 ms |
16080 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
299 ms |
3108 KB |
Output is correct |
2 |
Correct |
319 ms |
4188 KB |
Output is correct |
3 |
Correct |
318 ms |
4088 KB |
Output is correct |
4 |
Correct |
300 ms |
4180 KB |
Output is correct |
5 |
Correct |
300 ms |
3924 KB |
Output is correct |
6 |
Correct |
293 ms |
3924 KB |
Output is correct |
7 |
Correct |
333 ms |
3988 KB |
Output is correct |
8 |
Correct |
315 ms |
4208 KB |
Output is correct |
9 |
Correct |
316 ms |
3916 KB |
Output is correct |
10 |
Correct |
328 ms |
3988 KB |
Output is correct |
11 |
Correct |
320 ms |
4048 KB |
Output is correct |
12 |
Correct |
315 ms |
4028 KB |
Output is correct |
13 |
Correct |
313 ms |
4092 KB |
Output is correct |
14 |
Correct |
339 ms |
4040 KB |
Output is correct |
15 |
Correct |
327 ms |
3920 KB |
Output is correct |
16 |
Correct |
316 ms |
4000 KB |
Output is correct |
17 |
Correct |
309 ms |
3940 KB |
Output is correct |
18 |
Correct |
329 ms |
3984 KB |
Output is correct |
19 |
Correct |
489 ms |
26616 KB |
Output is correct |
20 |
Correct |
543 ms |
26664 KB |
Output is correct |
21 |
Correct |
355 ms |
8104 KB |
Output is correct |
22 |
Correct |
320 ms |
7928 KB |
Output is correct |
23 |
Correct |
372 ms |
8172 KB |
Output is correct |
24 |
Correct |
345 ms |
8112 KB |
Output is correct |
25 |
Correct |
368 ms |
8404 KB |
Output is correct |
26 |
Correct |
341 ms |
8028 KB |
Output is correct |
27 |
Correct |
365 ms |
8276 KB |
Output is correct |
28 |
Correct |
324 ms |
8140 KB |
Output is correct |
29 |
Correct |
359 ms |
8352 KB |
Output is correct |
30 |
Correct |
329 ms |
8032 KB |
Output is correct |
31 |
Correct |
465 ms |
26852 KB |
Output is correct |
32 |
Correct |
496 ms |
26648 KB |
Output is correct |
33 |
Correct |
483 ms |
26636 KB |
Output is correct |
34 |
Correct |
446 ms |
26488 KB |
Output is correct |
35 |
Correct |
473 ms |
26620 KB |
Output is correct |
36 |
Correct |
475 ms |
26604 KB |
Output is correct |
37 |
Correct |
464 ms |
27112 KB |
Output is correct |
38 |
Correct |
464 ms |
26740 KB |
Output is correct |
39 |
Correct |
466 ms |
26536 KB |
Output is correct |
40 |
Correct |
462 ms |
26508 KB |
Output is correct |
41 |
Correct |
475 ms |
26440 KB |
Output is correct |
42 |
Correct |
470 ms |
26552 KB |
Output is correct |
43 |
Correct |
461 ms |
26704 KB |
Output is correct |
44 |
Correct |
462 ms |
26448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
299 ms |
3108 KB |
Output is correct |
2 |
Correct |
319 ms |
4188 KB |
Output is correct |
3 |
Correct |
318 ms |
4088 KB |
Output is correct |
4 |
Correct |
300 ms |
4180 KB |
Output is correct |
5 |
Correct |
300 ms |
3924 KB |
Output is correct |
6 |
Correct |
293 ms |
3924 KB |
Output is correct |
7 |
Correct |
333 ms |
3988 KB |
Output is correct |
8 |
Correct |
315 ms |
4208 KB |
Output is correct |
9 |
Correct |
316 ms |
3916 KB |
Output is correct |
10 |
Correct |
328 ms |
3988 KB |
Output is correct |
11 |
Correct |
320 ms |
4048 KB |
Output is correct |
12 |
Correct |
315 ms |
4028 KB |
Output is correct |
13 |
Correct |
313 ms |
4092 KB |
Output is correct |
14 |
Correct |
339 ms |
4040 KB |
Output is correct |
15 |
Correct |
327 ms |
3920 KB |
Output is correct |
16 |
Correct |
316 ms |
4000 KB |
Output is correct |
17 |
Correct |
309 ms |
3940 KB |
Output is correct |
18 |
Correct |
329 ms |
3984 KB |
Output is correct |
19 |
Correct |
464 ms |
14996 KB |
Output is correct |
20 |
Correct |
462 ms |
15812 KB |
Output is correct |
21 |
Correct |
390 ms |
16304 KB |
Output is correct |
22 |
Correct |
388 ms |
16024 KB |
Output is correct |
23 |
Correct |
365 ms |
7924 KB |
Output is correct |
24 |
Correct |
363 ms |
7576 KB |
Output is correct |
25 |
Correct |
421 ms |
16588 KB |
Output is correct |
26 |
Correct |
427 ms |
16476 KB |
Output is correct |
27 |
Correct |
421 ms |
16596 KB |
Output is correct |
28 |
Correct |
430 ms |
16548 KB |
Output is correct |
29 |
Correct |
403 ms |
16260 KB |
Output is correct |
30 |
Correct |
368 ms |
7736 KB |
Output is correct |
31 |
Correct |
418 ms |
16588 KB |
Output is correct |
32 |
Correct |
446 ms |
16220 KB |
Output is correct |
33 |
Correct |
371 ms |
7660 KB |
Output is correct |
34 |
Correct |
423 ms |
16496 KB |
Output is correct |
35 |
Correct |
389 ms |
15792 KB |
Output is correct |
36 |
Correct |
365 ms |
7704 KB |
Output is correct |
37 |
Correct |
363 ms |
7588 KB |
Output is correct |
38 |
Correct |
439 ms |
16308 KB |
Output is correct |
39 |
Correct |
384 ms |
16480 KB |
Output is correct |
40 |
Correct |
395 ms |
11540 KB |
Output is correct |
41 |
Correct |
484 ms |
16924 KB |
Output is correct |
42 |
Correct |
320 ms |
16080 KB |
Output is correct |
43 |
Correct |
489 ms |
26616 KB |
Output is correct |
44 |
Correct |
543 ms |
26664 KB |
Output is correct |
45 |
Correct |
355 ms |
8104 KB |
Output is correct |
46 |
Correct |
320 ms |
7928 KB |
Output is correct |
47 |
Correct |
372 ms |
8172 KB |
Output is correct |
48 |
Correct |
345 ms |
8112 KB |
Output is correct |
49 |
Correct |
368 ms |
8404 KB |
Output is correct |
50 |
Correct |
341 ms |
8028 KB |
Output is correct |
51 |
Correct |
365 ms |
8276 KB |
Output is correct |
52 |
Correct |
324 ms |
8140 KB |
Output is correct |
53 |
Correct |
359 ms |
8352 KB |
Output is correct |
54 |
Correct |
329 ms |
8032 KB |
Output is correct |
55 |
Correct |
465 ms |
26852 KB |
Output is correct |
56 |
Correct |
496 ms |
26648 KB |
Output is correct |
57 |
Correct |
483 ms |
26636 KB |
Output is correct |
58 |
Correct |
446 ms |
26488 KB |
Output is correct |
59 |
Correct |
473 ms |
26620 KB |
Output is correct |
60 |
Correct |
475 ms |
26604 KB |
Output is correct |
61 |
Correct |
464 ms |
27112 KB |
Output is correct |
62 |
Correct |
464 ms |
26740 KB |
Output is correct |
63 |
Correct |
466 ms |
26536 KB |
Output is correct |
64 |
Correct |
462 ms |
26508 KB |
Output is correct |
65 |
Correct |
475 ms |
26440 KB |
Output is correct |
66 |
Correct |
470 ms |
26552 KB |
Output is correct |
67 |
Correct |
461 ms |
26704 KB |
Output is correct |
68 |
Correct |
462 ms |
26448 KB |
Output is correct |
69 |
Correct |
1512 ms |
107100 KB |
Output is correct |
70 |
Correct |
1443 ms |
108304 KB |
Output is correct |
71 |
Correct |
446 ms |
15952 KB |
Output is correct |
72 |
Correct |
454 ms |
15768 KB |
Output is correct |
73 |
Correct |
449 ms |
15956 KB |
Output is correct |
74 |
Correct |
538 ms |
39204 KB |
Output is correct |
75 |
Correct |
452 ms |
16004 KB |
Output is correct |
76 |
Correct |
605 ms |
40000 KB |
Output is correct |
77 |
Correct |
576 ms |
39192 KB |
Output is correct |
78 |
Correct |
455 ms |
16056 KB |
Output is correct |
79 |
Correct |
460 ms |
16208 KB |
Output is correct |
80 |
Correct |
1148 ms |
106456 KB |
Output is correct |
81 |
Correct |
691 ms |
38484 KB |
Output is correct |
82 |
Correct |
1317 ms |
108412 KB |
Output is correct |
83 |
Correct |
1284 ms |
108268 KB |
Output is correct |
84 |
Correct |
684 ms |
38528 KB |
Output is correct |
85 |
Correct |
683 ms |
38612 KB |
Output is correct |
86 |
Correct |
1279 ms |
106824 KB |
Output is correct |
87 |
Correct |
1363 ms |
108148 KB |
Output is correct |
88 |
Correct |
714 ms |
38440 KB |
Output is correct |
89 |
Correct |
1263 ms |
107740 KB |
Output is correct |
90 |
Correct |
1386 ms |
108232 KB |
Output is correct |
91 |
Correct |
756 ms |
38564 KB |
Output is correct |
92 |
Correct |
1143 ms |
106876 KB |
Output is correct |
93 |
Correct |
675 ms |
38628 KB |
Output is correct |
94 |
Correct |
679 ms |
38592 KB |
Output is correct |
95 |
Correct |
692 ms |
38928 KB |
Output is correct |
96 |
Correct |
421 ms |
16208 KB |
Output is correct |
97 |
Correct |
784 ms |
108328 KB |
Output is correct |
98 |
Correct |
1194 ms |
68992 KB |
Output is correct |
99 |
Correct |
1881 ms |
109044 KB |
Output is correct |
100 |
Correct |
410 ms |
107828 KB |
Output is correct |