#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
const str joi = "JOI";
struct joi_segtree{
struct node{
bool ok;
char c, cc;
node(){
c = 'J';
cc = 'J';
ok = 1;
}
node operator+(node a){
node rt;
rt.ok = ok&a.ok;
if(c == a.c) rt.c = c;
else rt.c = 'X';
if(cc == a.cc) rt.cc = cc;
else rt.cc = 'X';
return rt;
}
void pushdown(node a){
if(a.cc != cc && a.cc != 'X'){
cc = a.cc;
if(cc != 'X' && cc == c) ok = 1;
else ok = 0;
}
}
};
int k;
vector<node> v;
joi_segtree(str s){
int n = s.size();
k = 1;
while(k < n) k*=2;
while(n < k) s+='J', n++;
k*=2;
v.resize(k, node());
for(int i = k/2; i < k; i++){
v[i].c = s[i-k/2];
if(v[i].c != v[i].cc) v[i].ok = 0;
}
for(int i = k/2-1; i > 0; i--) v[i] = v[2*i] + v[2*i+1];
}
joi_segtree(){
}
void query(int l, int r, int nd, int a, int b, char _cc){
if(a > r || b < l) return;
if(a >= l && b <= r){
v[nd].cc = _cc;
if(v[nd].cc != 'X' && v[nd].c == v[nd].cc) v[nd].ok = 1;
else v[nd].ok = 0;
return;
}
int md = (a+b)/2;
v[2*nd].pushdown(v[nd]);
v[2*nd+1].pushdown(v[nd]);
query(l, r, 2*nd, a, md, _cc);
query(l, r, 2*nd+1, md+1, b, _cc);
v[nd] = v[2*nd] + v[2*nd+1];
}
bool query(int l, int r, char C){
query(l, r, 1, 0, k/2-1, C);
return v[1].ok;
}
};
struct Query{
str s;
joi_segtree seg;
bool bulid(str _s, str ss){
s = _s;
seg = joi_segtree(s);
for(int i = 0; i < ss.size(); i++) seg.query(i, i, ss[i]);
return seg.v[1].ok;
}
bool query(int l, int r, char c){
return seg.query(l, r, c);
}
};
str cross(str a, str b){
int n = a.size();
str crs;
for(int i = 0; i < n; i++){
if(a[i] == b[i]) crs+=a[i];
else for(char c: joi) if(c != a[i] && c != b[i]) crs+=c;
}
return crs;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, q; cin >> n;
int m = 3;
vector<str> v(3);
for(str &s: v) cin >> s;
int cur = 1;
while(1){
for(int i = cur-1; i >= 0; i--){
str s = cross(v[cur], v[i]);
bool bl = 0;
for(str ss: v) if(ss == s) bl = 1;
if(!bl) v.pb(s);
}
if(m == v.size() && cur == m-1) break;
m = v.size();
cur++;
}
str ss; cin >> q >> ss;
vector<Query> qq(m);
bool bl = 0;
for(int i = 0; i < m; i++) bl|=qq[i].bulid(v[i], ss);
cout << (bl ? "Yes\n":"No\n");
while(q--){
int l, r; char c; cin >> l >> r >> c; l--, r--;
bl = 0;
for(int i = 0; i < m; i++) bl|=qq[i].query(l, r, c);
cout << (bl ? "Yes\n":"No\n");
}
}
Compilation message
Main.cpp: In member function 'bool Query::bulid(str, str)':
Main.cpp:79:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
79 | for(int i = 0; i < ss.size(); i++) seg.query(i, i, ss[i]);
| ~~^~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:110:14: 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]
110 | if(m == v.size() && cur == m-1) break;
| ~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
174 ms |
848 KB |
Output is correct |
2 |
Correct |
192 ms |
868 KB |
Output is correct |
3 |
Correct |
201 ms |
896 KB |
Output is correct |
4 |
Correct |
162 ms |
976 KB |
Output is correct |
5 |
Correct |
156 ms |
824 KB |
Output is correct |
6 |
Correct |
155 ms |
840 KB |
Output is correct |
7 |
Correct |
182 ms |
868 KB |
Output is correct |
8 |
Correct |
164 ms |
900 KB |
Output is correct |
9 |
Correct |
168 ms |
884 KB |
Output is correct |
10 |
Correct |
171 ms |
848 KB |
Output is correct |
11 |
Correct |
166 ms |
836 KB |
Output is correct |
12 |
Correct |
165 ms |
844 KB |
Output is correct |
13 |
Correct |
172 ms |
836 KB |
Output is correct |
14 |
Correct |
164 ms |
880 KB |
Output is correct |
15 |
Correct |
166 ms |
852 KB |
Output is correct |
16 |
Correct |
167 ms |
804 KB |
Output is correct |
17 |
Correct |
167 ms |
880 KB |
Output is correct |
18 |
Correct |
185 ms |
928 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
174 ms |
848 KB |
Output is correct |
2 |
Correct |
192 ms |
868 KB |
Output is correct |
3 |
Correct |
201 ms |
896 KB |
Output is correct |
4 |
Correct |
162 ms |
976 KB |
Output is correct |
5 |
Correct |
156 ms |
824 KB |
Output is correct |
6 |
Correct |
155 ms |
840 KB |
Output is correct |
7 |
Correct |
182 ms |
868 KB |
Output is correct |
8 |
Correct |
164 ms |
900 KB |
Output is correct |
9 |
Correct |
168 ms |
884 KB |
Output is correct |
10 |
Correct |
171 ms |
848 KB |
Output is correct |
11 |
Correct |
166 ms |
836 KB |
Output is correct |
12 |
Correct |
165 ms |
844 KB |
Output is correct |
13 |
Correct |
172 ms |
836 KB |
Output is correct |
14 |
Correct |
164 ms |
880 KB |
Output is correct |
15 |
Correct |
166 ms |
852 KB |
Output is correct |
16 |
Correct |
167 ms |
804 KB |
Output is correct |
17 |
Correct |
167 ms |
880 KB |
Output is correct |
18 |
Correct |
185 ms |
928 KB |
Output is correct |
19 |
Correct |
892 ms |
9992 KB |
Output is correct |
20 |
Correct |
875 ms |
11460 KB |
Output is correct |
21 |
Correct |
614 ms |
11068 KB |
Output is correct |
22 |
Correct |
596 ms |
10752 KB |
Output is correct |
23 |
Correct |
306 ms |
3708 KB |
Output is correct |
24 |
Correct |
321 ms |
3768 KB |
Output is correct |
25 |
Correct |
673 ms |
11696 KB |
Output is correct |
26 |
Correct |
686 ms |
11648 KB |
Output is correct |
27 |
Correct |
762 ms |
11468 KB |
Output is correct |
28 |
Correct |
730 ms |
11504 KB |
Output is correct |
29 |
Correct |
803 ms |
11320 KB |
Output is correct |
30 |
Correct |
338 ms |
3592 KB |
Output is correct |
31 |
Correct |
731 ms |
11516 KB |
Output is correct |
32 |
Correct |
681 ms |
11044 KB |
Output is correct |
33 |
Correct |
328 ms |
3668 KB |
Output is correct |
34 |
Correct |
738 ms |
11408 KB |
Output is correct |
35 |
Correct |
560 ms |
10488 KB |
Output is correct |
36 |
Correct |
305 ms |
3652 KB |
Output is correct |
37 |
Correct |
303 ms |
3668 KB |
Output is correct |
38 |
Correct |
816 ms |
11204 KB |
Output is correct |
39 |
Correct |
548 ms |
11432 KB |
Output is correct |
40 |
Correct |
533 ms |
7940 KB |
Output is correct |
41 |
Correct |
862 ms |
11644 KB |
Output is correct |
42 |
Correct |
451 ms |
10932 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
174 ms |
848 KB |
Output is correct |
2 |
Correct |
192 ms |
868 KB |
Output is correct |
3 |
Correct |
201 ms |
896 KB |
Output is correct |
4 |
Correct |
162 ms |
976 KB |
Output is correct |
5 |
Correct |
156 ms |
824 KB |
Output is correct |
6 |
Correct |
155 ms |
840 KB |
Output is correct |
7 |
Correct |
182 ms |
868 KB |
Output is correct |
8 |
Correct |
164 ms |
900 KB |
Output is correct |
9 |
Correct |
168 ms |
884 KB |
Output is correct |
10 |
Correct |
171 ms |
848 KB |
Output is correct |
11 |
Correct |
166 ms |
836 KB |
Output is correct |
12 |
Correct |
165 ms |
844 KB |
Output is correct |
13 |
Correct |
172 ms |
836 KB |
Output is correct |
14 |
Correct |
164 ms |
880 KB |
Output is correct |
15 |
Correct |
166 ms |
852 KB |
Output is correct |
16 |
Correct |
167 ms |
804 KB |
Output is correct |
17 |
Correct |
167 ms |
880 KB |
Output is correct |
18 |
Correct |
185 ms |
928 KB |
Output is correct |
19 |
Correct |
414 ms |
848 KB |
Output is correct |
20 |
Correct |
479 ms |
1004 KB |
Output is correct |
21 |
Correct |
201 ms |
836 KB |
Output is correct |
22 |
Correct |
188 ms |
2228 KB |
Output is correct |
23 |
Correct |
204 ms |
2540 KB |
Output is correct |
24 |
Correct |
196 ms |
2264 KB |
Output is correct |
25 |
Correct |
205 ms |
2496 KB |
Output is correct |
26 |
Correct |
198 ms |
2332 KB |
Output is correct |
27 |
Correct |
166 ms |
2372 KB |
Output is correct |
28 |
Correct |
159 ms |
2128 KB |
Output is correct |
29 |
Correct |
174 ms |
2368 KB |
Output is correct |
30 |
Correct |
154 ms |
2144 KB |
Output is correct |
31 |
Correct |
369 ms |
2492 KB |
Output is correct |
32 |
Correct |
393 ms |
2368 KB |
Output is correct |
33 |
Correct |
378 ms |
2540 KB |
Output is correct |
34 |
Correct |
344 ms |
2284 KB |
Output is correct |
35 |
Correct |
361 ms |
2428 KB |
Output is correct |
36 |
Correct |
373 ms |
2380 KB |
Output is correct |
37 |
Correct |
381 ms |
2376 KB |
Output is correct |
38 |
Correct |
372 ms |
2368 KB |
Output is correct |
39 |
Correct |
367 ms |
2400 KB |
Output is correct |
40 |
Correct |
391 ms |
2460 KB |
Output is correct |
41 |
Correct |
369 ms |
2368 KB |
Output is correct |
42 |
Correct |
375 ms |
2372 KB |
Output is correct |
43 |
Correct |
361 ms |
2372 KB |
Output is correct |
44 |
Correct |
370 ms |
2428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
174 ms |
848 KB |
Output is correct |
2 |
Correct |
192 ms |
868 KB |
Output is correct |
3 |
Correct |
201 ms |
896 KB |
Output is correct |
4 |
Correct |
162 ms |
976 KB |
Output is correct |
5 |
Correct |
156 ms |
824 KB |
Output is correct |
6 |
Correct |
155 ms |
840 KB |
Output is correct |
7 |
Correct |
182 ms |
868 KB |
Output is correct |
8 |
Correct |
164 ms |
900 KB |
Output is correct |
9 |
Correct |
168 ms |
884 KB |
Output is correct |
10 |
Correct |
171 ms |
848 KB |
Output is correct |
11 |
Correct |
166 ms |
836 KB |
Output is correct |
12 |
Correct |
165 ms |
844 KB |
Output is correct |
13 |
Correct |
172 ms |
836 KB |
Output is correct |
14 |
Correct |
164 ms |
880 KB |
Output is correct |
15 |
Correct |
166 ms |
852 KB |
Output is correct |
16 |
Correct |
167 ms |
804 KB |
Output is correct |
17 |
Correct |
167 ms |
880 KB |
Output is correct |
18 |
Correct |
185 ms |
928 KB |
Output is correct |
19 |
Correct |
892 ms |
9992 KB |
Output is correct |
20 |
Correct |
875 ms |
11460 KB |
Output is correct |
21 |
Correct |
614 ms |
11068 KB |
Output is correct |
22 |
Correct |
596 ms |
10752 KB |
Output is correct |
23 |
Correct |
306 ms |
3708 KB |
Output is correct |
24 |
Correct |
321 ms |
3768 KB |
Output is correct |
25 |
Correct |
673 ms |
11696 KB |
Output is correct |
26 |
Correct |
686 ms |
11648 KB |
Output is correct |
27 |
Correct |
762 ms |
11468 KB |
Output is correct |
28 |
Correct |
730 ms |
11504 KB |
Output is correct |
29 |
Correct |
803 ms |
11320 KB |
Output is correct |
30 |
Correct |
338 ms |
3592 KB |
Output is correct |
31 |
Correct |
731 ms |
11516 KB |
Output is correct |
32 |
Correct |
681 ms |
11044 KB |
Output is correct |
33 |
Correct |
328 ms |
3668 KB |
Output is correct |
34 |
Correct |
738 ms |
11408 KB |
Output is correct |
35 |
Correct |
560 ms |
10488 KB |
Output is correct |
36 |
Correct |
305 ms |
3652 KB |
Output is correct |
37 |
Correct |
303 ms |
3668 KB |
Output is correct |
38 |
Correct |
816 ms |
11204 KB |
Output is correct |
39 |
Correct |
548 ms |
11432 KB |
Output is correct |
40 |
Correct |
533 ms |
7940 KB |
Output is correct |
41 |
Correct |
862 ms |
11644 KB |
Output is correct |
42 |
Correct |
451 ms |
10932 KB |
Output is correct |
43 |
Correct |
414 ms |
848 KB |
Output is correct |
44 |
Correct |
479 ms |
1004 KB |
Output is correct |
45 |
Correct |
201 ms |
836 KB |
Output is correct |
46 |
Correct |
188 ms |
2228 KB |
Output is correct |
47 |
Correct |
204 ms |
2540 KB |
Output is correct |
48 |
Correct |
196 ms |
2264 KB |
Output is correct |
49 |
Correct |
205 ms |
2496 KB |
Output is correct |
50 |
Correct |
198 ms |
2332 KB |
Output is correct |
51 |
Correct |
166 ms |
2372 KB |
Output is correct |
52 |
Correct |
159 ms |
2128 KB |
Output is correct |
53 |
Correct |
174 ms |
2368 KB |
Output is correct |
54 |
Correct |
154 ms |
2144 KB |
Output is correct |
55 |
Correct |
369 ms |
2492 KB |
Output is correct |
56 |
Correct |
393 ms |
2368 KB |
Output is correct |
57 |
Correct |
378 ms |
2540 KB |
Output is correct |
58 |
Correct |
344 ms |
2284 KB |
Output is correct |
59 |
Correct |
361 ms |
2428 KB |
Output is correct |
60 |
Correct |
373 ms |
2380 KB |
Output is correct |
61 |
Correct |
381 ms |
2376 KB |
Output is correct |
62 |
Correct |
372 ms |
2368 KB |
Output is correct |
63 |
Correct |
367 ms |
2400 KB |
Output is correct |
64 |
Correct |
391 ms |
2460 KB |
Output is correct |
65 |
Correct |
369 ms |
2368 KB |
Output is correct |
66 |
Correct |
375 ms |
2372 KB |
Output is correct |
67 |
Correct |
361 ms |
2372 KB |
Output is correct |
68 |
Correct |
370 ms |
2428 KB |
Output is correct |
69 |
Correct |
2342 ms |
21920 KB |
Output is correct |
70 |
Correct |
2622 ms |
22988 KB |
Output is correct |
71 |
Correct |
406 ms |
4052 KB |
Output is correct |
72 |
Correct |
388 ms |
3816 KB |
Output is correct |
73 |
Correct |
391 ms |
3812 KB |
Output is correct |
74 |
Correct |
586 ms |
10784 KB |
Output is correct |
75 |
Correct |
325 ms |
3672 KB |
Output is correct |
76 |
Correct |
731 ms |
11540 KB |
Output is correct |
77 |
Correct |
612 ms |
10820 KB |
Output is correct |
78 |
Correct |
314 ms |
3652 KB |
Output is correct |
79 |
Correct |
311 ms |
3712 KB |
Output is correct |
80 |
Correct |
1861 ms |
21352 KB |
Output is correct |
81 |
Correct |
815 ms |
4332 KB |
Output is correct |
82 |
Correct |
2233 ms |
23092 KB |
Output is correct |
83 |
Correct |
2100 ms |
22776 KB |
Output is correct |
84 |
Correct |
833 ms |
4420 KB |
Output is correct |
85 |
Correct |
806 ms |
4432 KB |
Output is correct |
86 |
Correct |
2068 ms |
21736 KB |
Output is correct |
87 |
Correct |
2328 ms |
22992 KB |
Output is correct |
88 |
Correct |
902 ms |
4592 KB |
Output is correct |
89 |
Correct |
2103 ms |
22208 KB |
Output is correct |
90 |
Correct |
2308 ms |
23156 KB |
Output is correct |
91 |
Correct |
861 ms |
4404 KB |
Output is correct |
92 |
Correct |
1755 ms |
21468 KB |
Output is correct |
93 |
Correct |
786 ms |
4532 KB |
Output is correct |
94 |
Correct |
789 ms |
4408 KB |
Output is correct |
95 |
Correct |
802 ms |
4488 KB |
Output is correct |
96 |
Correct |
808 ms |
11208 KB |
Output is correct |
97 |
Correct |
1672 ms |
23192 KB |
Output is correct |
98 |
Correct |
1697 ms |
14200 KB |
Output is correct |
99 |
Correct |
2757 ms |
23380 KB |
Output is correct |
100 |
Correct |
1380 ms |
22552 KB |
Output is correct |