#include <bits/stdc++.h>
#define int long long
using namespace std;
const int P = 31;
const int mod = 1e9 + 7;
string resi(string a,string b) {
string res;
for(int i = 0; i < a.size(); i++) res += 'J';
for(int i = 1; i < a.size(); i++) {
if(a[i] == b[i]) res[i] = a[i];
else {
bool J = false,O = false,I = false;
if(a[i] == 'J' || b[i] == 'J') J = true;
if(a[i] == 'O' || b[i] == 'O') O = true;
if(a[i] == 'I' || b[i] == 'I') I = true;
if(!J) res[i] = 'J';
else if(!O) res[i] = 'O';
else res[i] = 'I';
}
}
return res;
}
int add(int a,int b) {
return (a + b) % mod;
}
int mul(int a,int b) {
return (a * b) % mod;
}
struct hes {
// h[i] = h[i - 1] + (pw[i] * s[i] - 'a' + 1)
string s;
vector<int>pw,val;
void build(string t,int n) {
s = t;
pw.resize(n + 1);
val.resize(n + 1);
pw[0] = 1;
for(int i = 1; i <= n; i++) pw[i] = mul(pw[i - 1],P);
for(int i = 1; i <= n; i++) val[i] = add(val[i - 1],mul(pw[i],(s[i] - 'A' + 1)));
}
};
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
set<string>st;
string a,b,c;
cin >> a >> b >> c;
a = '.' + a;
b = '.' + b;
c = '.' + c;
st.insert(a);
st.insert(b);
st.insert(c);
st.insert(resi(a,c));
st.insert(resi(b,c));
st.insert(resi(a,b));
st.insert(resi(resi(a,b),c));
st.insert(resi(resi(b,a),c));
st.insert(resi(resi(c,a),b));
st.insert(resi(resi(a,c),b));
st.insert(resi(resi(b,c),a));
st.insert(resi(resi(c,b),a));
vector<string>vec;
for(auto X : st) vec.push_back(X);
int K = vec.size();
vector<hes>niz(K);
for(int i = 0; i < K; i++) {
niz[i].build(vec[i],n);
}
int Q;
cin >> Q;
string str;
cin >> str;
str = '.' + str;
hes T;
T.build(str,n);
bool ok = false;
for(int i = 0; i < K; i++) if(T.val[n] == niz[i].val[n]) ok = true;
cout << (ok ? "Yes\n" : "No\n");
while(Q--) {
int l,r;
char c;
cin >> l >> r >> c;
for(int i = l; i <= r; i++) str[i] = c;
T.build(str,n);
bool ok = false;
for(int i = 0; i < K; i++) if(T.val[n] == niz[i].val[n]) ok = true;
cout << (ok ? "Yes\n" : "No\n");
}
}
/*
JOJO
JJOI
OJOO
a ^ b
a ^ c
b ^ c
a ^ a ^ b = b
a ^ a ^ c = c
a ^ b ^ c novo
b ^ a ^ b = a
b ^ a ^ c =
*/
Compilation message
Main.cpp: In function 'std::string resi(std::string, std::string)':
Main.cpp:13:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
13 | for(int i = 0; i < a.size(); i++) res += 'J';
| ~~^~~~~~~~~~
Main.cpp:14:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
14 | for(int i = 1; i < a.size(); i++) {
| ~~^~~~~~~~~~
Main.cpp:17:38: warning: variable 'I' set but not used [-Wunused-but-set-variable]
17 | bool J = false,O = false,I = false;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
180 ms |
2220 KB |
Output is correct |
2 |
Correct |
231 ms |
2384 KB |
Output is correct |
3 |
Correct |
240 ms |
2456 KB |
Output is correct |
4 |
Correct |
220 ms |
2376 KB |
Output is correct |
5 |
Correct |
206 ms |
2484 KB |
Output is correct |
6 |
Correct |
212 ms |
2464 KB |
Output is correct |
7 |
Correct |
178 ms |
2316 KB |
Output is correct |
8 |
Correct |
231 ms |
2508 KB |
Output is correct |
9 |
Correct |
237 ms |
2584 KB |
Output is correct |
10 |
Correct |
237 ms |
2468 KB |
Output is correct |
11 |
Correct |
230 ms |
2416 KB |
Output is correct |
12 |
Correct |
238 ms |
2388 KB |
Output is correct |
13 |
Correct |
237 ms |
2520 KB |
Output is correct |
14 |
Correct |
231 ms |
2468 KB |
Output is correct |
15 |
Correct |
234 ms |
2584 KB |
Output is correct |
16 |
Correct |
237 ms |
2436 KB |
Output is correct |
17 |
Correct |
235 ms |
2468 KB |
Output is correct |
18 |
Correct |
258 ms |
2384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
180 ms |
2220 KB |
Output is correct |
2 |
Correct |
231 ms |
2384 KB |
Output is correct |
3 |
Correct |
240 ms |
2456 KB |
Output is correct |
4 |
Correct |
220 ms |
2376 KB |
Output is correct |
5 |
Correct |
206 ms |
2484 KB |
Output is correct |
6 |
Correct |
212 ms |
2464 KB |
Output is correct |
7 |
Correct |
178 ms |
2316 KB |
Output is correct |
8 |
Correct |
231 ms |
2508 KB |
Output is correct |
9 |
Correct |
237 ms |
2584 KB |
Output is correct |
10 |
Correct |
237 ms |
2468 KB |
Output is correct |
11 |
Correct |
230 ms |
2416 KB |
Output is correct |
12 |
Correct |
238 ms |
2388 KB |
Output is correct |
13 |
Correct |
237 ms |
2520 KB |
Output is correct |
14 |
Correct |
231 ms |
2468 KB |
Output is correct |
15 |
Correct |
234 ms |
2584 KB |
Output is correct |
16 |
Correct |
237 ms |
2436 KB |
Output is correct |
17 |
Correct |
235 ms |
2468 KB |
Output is correct |
18 |
Correct |
258 ms |
2384 KB |
Output is correct |
19 |
Execution timed out |
7102 ms |
13372 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
180 ms |
2220 KB |
Output is correct |
2 |
Correct |
231 ms |
2384 KB |
Output is correct |
3 |
Correct |
240 ms |
2456 KB |
Output is correct |
4 |
Correct |
220 ms |
2376 KB |
Output is correct |
5 |
Correct |
206 ms |
2484 KB |
Output is correct |
6 |
Correct |
212 ms |
2464 KB |
Output is correct |
7 |
Correct |
178 ms |
2316 KB |
Output is correct |
8 |
Correct |
231 ms |
2508 KB |
Output is correct |
9 |
Correct |
237 ms |
2584 KB |
Output is correct |
10 |
Correct |
237 ms |
2468 KB |
Output is correct |
11 |
Correct |
230 ms |
2416 KB |
Output is correct |
12 |
Correct |
238 ms |
2388 KB |
Output is correct |
13 |
Correct |
237 ms |
2520 KB |
Output is correct |
14 |
Correct |
231 ms |
2468 KB |
Output is correct |
15 |
Correct |
234 ms |
2584 KB |
Output is correct |
16 |
Correct |
237 ms |
2436 KB |
Output is correct |
17 |
Correct |
235 ms |
2468 KB |
Output is correct |
18 |
Correct |
258 ms |
2384 KB |
Output is correct |
19 |
Correct |
222 ms |
2256 KB |
Output is correct |
20 |
Correct |
244 ms |
2896 KB |
Output is correct |
21 |
Correct |
232 ms |
2540 KB |
Output is correct |
22 |
Correct |
153 ms |
2360 KB |
Output is correct |
23 |
Correct |
234 ms |
2896 KB |
Output is correct |
24 |
Correct |
202 ms |
2472 KB |
Output is correct |
25 |
Correct |
232 ms |
2424 KB |
Output is correct |
26 |
Correct |
169 ms |
2388 KB |
Output is correct |
27 |
Correct |
237 ms |
2600 KB |
Output is correct |
28 |
Correct |
198 ms |
2640 KB |
Output is correct |
29 |
Correct |
232 ms |
2388 KB |
Output is correct |
30 |
Correct |
154 ms |
2184 KB |
Output is correct |
31 |
Correct |
237 ms |
2572 KB |
Output is correct |
32 |
Correct |
220 ms |
2540 KB |
Output is correct |
33 |
Correct |
233 ms |
2488 KB |
Output is correct |
34 |
Correct |
164 ms |
2268 KB |
Output is correct |
35 |
Correct |
233 ms |
2388 KB |
Output is correct |
36 |
Correct |
234 ms |
2644 KB |
Output is correct |
37 |
Correct |
233 ms |
2544 KB |
Output is correct |
38 |
Correct |
231 ms |
2452 KB |
Output is correct |
39 |
Correct |
233 ms |
2568 KB |
Output is correct |
40 |
Correct |
232 ms |
2444 KB |
Output is correct |
41 |
Correct |
235 ms |
2812 KB |
Output is correct |
42 |
Correct |
237 ms |
2524 KB |
Output is correct |
43 |
Correct |
182 ms |
2360 KB |
Output is correct |
44 |
Correct |
236 ms |
2592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
180 ms |
2220 KB |
Output is correct |
2 |
Correct |
231 ms |
2384 KB |
Output is correct |
3 |
Correct |
240 ms |
2456 KB |
Output is correct |
4 |
Correct |
220 ms |
2376 KB |
Output is correct |
5 |
Correct |
206 ms |
2484 KB |
Output is correct |
6 |
Correct |
212 ms |
2464 KB |
Output is correct |
7 |
Correct |
178 ms |
2316 KB |
Output is correct |
8 |
Correct |
231 ms |
2508 KB |
Output is correct |
9 |
Correct |
237 ms |
2584 KB |
Output is correct |
10 |
Correct |
237 ms |
2468 KB |
Output is correct |
11 |
Correct |
230 ms |
2416 KB |
Output is correct |
12 |
Correct |
238 ms |
2388 KB |
Output is correct |
13 |
Correct |
237 ms |
2520 KB |
Output is correct |
14 |
Correct |
231 ms |
2468 KB |
Output is correct |
15 |
Correct |
234 ms |
2584 KB |
Output is correct |
16 |
Correct |
237 ms |
2436 KB |
Output is correct |
17 |
Correct |
235 ms |
2468 KB |
Output is correct |
18 |
Correct |
258 ms |
2384 KB |
Output is correct |
19 |
Execution timed out |
7102 ms |
13372 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |