#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 200000 + 10;
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) {
a += b;
if(a < 0) a += mod;
if(a >= mod) a -= mod;
return a;
}
int mul(int a,int b) {
return (a * b) % mod;
}
int pw[N];
struct hes {
// h[i] = h[i - 1] + (pw[i] * s[i] - 'a' + 1)
// pw[i] * c + pw[i + 1] * c + pw[i + 2] * c = c(pw[i] + pw[i + 1],pw[i + 2]...)
string s;
vector<int>val;
void build(string t,int n) {
s = t;
val.resize(n + 1);
for(int i = 1; i <= n; i++) val[i] = add(val[i - 1],mul(pw[i],(s[i] - 'A' + 1)));
}
};
int st[N * 4],pref[N];
bool lazy[N * 4];
char koji[N * 4];
void push(int node,int tl,int tr) {
if(!lazy[node]) return;
st[node] = mul(koji[node] - 'A' + 1,add(pref[tr],-pref[tl - 1]));
if(tl != tr) {
lazy[node * 2] = true;
lazy[node * 2 + 1] = true;
koji[node * 2] = koji[node];
koji[node * 2 + 1] = koji[node];
}
lazy[node] = false;
}
void modify(int node,int tl,int tr,int l,int r,char c) {
push(node,tl,tr);
if(tl > r || tr < l) return;
if(tl >= l && tr <= r) {
lazy[node] = true;
koji[node] = c;
push(node,tl,tr);
return;
}
int mid = (tl + tr) / 2;
modify(node * 2,tl,mid,l,r,c);
modify(node * 2 + 1,mid + 1,tr,l,r,c);
st[node] = add(st[node * 2],st[node * 2 + 1]);
}
int get(int node,int tl,int tr,int l,int r) {
if(tl > r || tr < l) return 0;
if(tl >= l && tr <= r) return st[node];
int mid = (tl + tr) / 2;
return add(get(node * 2,tl,mid,l,r),get(node * 2 + 1,mid + 1,tr,l,r));
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
pw[0] = 1;
for(int i = 1; i <= n; i++) pw[i] = mul(pw[i - 1],P);
for(int i = 1; i <= n; i++) pref[i] = add(pref[i - 1],pw[i]);
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);
for(int i = 1; i <= n; i++) modify(1,1,n,i,i,str[i]);
bool ok = false;
for(int i = 0; i < K; i++) {
if(niz[i].val[n] == get(1,1,n,1,n)) ok = true;
}
cout << (ok ? "Yes\n" : "No\n");
while(Q--) {
int l,r;
char c;
cin >> l >> r >> c;
modify(1,1,n,l,r,c);
bool ok = false;
for(int i = 0; i < K; i++) {
if(niz[i].val[n] == get(1,1,n,1,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:15: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]
15 | for(int i = 0; i < a.size(); i++) res += 'J';
| ~~^~~~~~~~~~
Main.cpp:16: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]
16 | for(int i = 1; i < a.size(); i++) {
| ~~^~~~~~~~~~
Main.cpp:19:38: warning: variable 'I' set but not used [-Wunused-but-set-variable]
19 | bool J = false,O = false,I = false;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
6476 KB |
Output is correct |
2 |
Correct |
60 ms |
6484 KB |
Output is correct |
3 |
Correct |
56 ms |
6488 KB |
Output is correct |
4 |
Correct |
50 ms |
6484 KB |
Output is correct |
5 |
Correct |
46 ms |
6480 KB |
Output is correct |
6 |
Correct |
47 ms |
6484 KB |
Output is correct |
7 |
Correct |
62 ms |
6628 KB |
Output is correct |
8 |
Correct |
50 ms |
6576 KB |
Output is correct |
9 |
Correct |
52 ms |
6480 KB |
Output is correct |
10 |
Correct |
54 ms |
6484 KB |
Output is correct |
11 |
Correct |
52 ms |
6480 KB |
Output is correct |
12 |
Correct |
51 ms |
6632 KB |
Output is correct |
13 |
Correct |
67 ms |
6484 KB |
Output is correct |
14 |
Correct |
51 ms |
6672 KB |
Output is correct |
15 |
Correct |
52 ms |
6592 KB |
Output is correct |
16 |
Correct |
54 ms |
6488 KB |
Output is correct |
17 |
Correct |
52 ms |
6484 KB |
Output is correct |
18 |
Correct |
65 ms |
6464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
6476 KB |
Output is correct |
2 |
Correct |
60 ms |
6484 KB |
Output is correct |
3 |
Correct |
56 ms |
6488 KB |
Output is correct |
4 |
Correct |
50 ms |
6484 KB |
Output is correct |
5 |
Correct |
46 ms |
6480 KB |
Output is correct |
6 |
Correct |
47 ms |
6484 KB |
Output is correct |
7 |
Correct |
62 ms |
6628 KB |
Output is correct |
8 |
Correct |
50 ms |
6576 KB |
Output is correct |
9 |
Correct |
52 ms |
6480 KB |
Output is correct |
10 |
Correct |
54 ms |
6484 KB |
Output is correct |
11 |
Correct |
52 ms |
6480 KB |
Output is correct |
12 |
Correct |
51 ms |
6632 KB |
Output is correct |
13 |
Correct |
67 ms |
6484 KB |
Output is correct |
14 |
Correct |
51 ms |
6672 KB |
Output is correct |
15 |
Correct |
52 ms |
6592 KB |
Output is correct |
16 |
Correct |
54 ms |
6488 KB |
Output is correct |
17 |
Correct |
52 ms |
6484 KB |
Output is correct |
18 |
Correct |
65 ms |
6464 KB |
Output is correct |
19 |
Correct |
240 ms |
22080 KB |
Output is correct |
20 |
Correct |
223 ms |
21988 KB |
Output is correct |
21 |
Correct |
142 ms |
21520 KB |
Output is correct |
22 |
Correct |
143 ms |
20544 KB |
Output is correct |
23 |
Correct |
80 ms |
8020 KB |
Output is correct |
24 |
Correct |
83 ms |
7940 KB |
Output is correct |
25 |
Correct |
153 ms |
22240 KB |
Output is correct |
26 |
Correct |
155 ms |
22120 KB |
Output is correct |
27 |
Correct |
176 ms |
22076 KB |
Output is correct |
28 |
Correct |
179 ms |
22260 KB |
Output is correct |
29 |
Correct |
172 ms |
21844 KB |
Output is correct |
30 |
Correct |
90 ms |
7800 KB |
Output is correct |
31 |
Correct |
180 ms |
22356 KB |
Output is correct |
32 |
Correct |
163 ms |
21328 KB |
Output is correct |
33 |
Correct |
84 ms |
7836 KB |
Output is correct |
34 |
Correct |
181 ms |
22552 KB |
Output is correct |
35 |
Correct |
128 ms |
19592 KB |
Output is correct |
36 |
Correct |
81 ms |
8020 KB |
Output is correct |
37 |
Correct |
81 ms |
7968 KB |
Output is correct |
38 |
Correct |
207 ms |
22104 KB |
Output is correct |
39 |
Correct |
122 ms |
21840 KB |
Output is correct |
40 |
Correct |
158 ms |
16292 KB |
Output is correct |
41 |
Correct |
261 ms |
22784 KB |
Output is correct |
42 |
Correct |
80 ms |
21296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
6476 KB |
Output is correct |
2 |
Correct |
60 ms |
6484 KB |
Output is correct |
3 |
Correct |
56 ms |
6488 KB |
Output is correct |
4 |
Correct |
50 ms |
6484 KB |
Output is correct |
5 |
Correct |
46 ms |
6480 KB |
Output is correct |
6 |
Correct |
47 ms |
6484 KB |
Output is correct |
7 |
Correct |
62 ms |
6628 KB |
Output is correct |
8 |
Correct |
50 ms |
6576 KB |
Output is correct |
9 |
Correct |
52 ms |
6480 KB |
Output is correct |
10 |
Correct |
54 ms |
6484 KB |
Output is correct |
11 |
Correct |
52 ms |
6480 KB |
Output is correct |
12 |
Correct |
51 ms |
6632 KB |
Output is correct |
13 |
Correct |
67 ms |
6484 KB |
Output is correct |
14 |
Correct |
51 ms |
6672 KB |
Output is correct |
15 |
Correct |
52 ms |
6592 KB |
Output is correct |
16 |
Correct |
54 ms |
6488 KB |
Output is correct |
17 |
Correct |
52 ms |
6484 KB |
Output is correct |
18 |
Correct |
65 ms |
6464 KB |
Output is correct |
19 |
Correct |
60 ms |
6476 KB |
Output is correct |
20 |
Correct |
57 ms |
6480 KB |
Output is correct |
21 |
Correct |
52 ms |
6600 KB |
Output is correct |
22 |
Correct |
45 ms |
6484 KB |
Output is correct |
23 |
Correct |
54 ms |
6480 KB |
Output is correct |
24 |
Correct |
50 ms |
6480 KB |
Output is correct |
25 |
Correct |
52 ms |
6672 KB |
Output is correct |
26 |
Correct |
48 ms |
6552 KB |
Output is correct |
27 |
Correct |
53 ms |
6496 KB |
Output is correct |
28 |
Correct |
48 ms |
6484 KB |
Output is correct |
29 |
Correct |
58 ms |
6480 KB |
Output is correct |
30 |
Correct |
53 ms |
6444 KB |
Output is correct |
31 |
Correct |
56 ms |
6484 KB |
Output is correct |
32 |
Correct |
52 ms |
6484 KB |
Output is correct |
33 |
Correct |
56 ms |
6544 KB |
Output is correct |
34 |
Correct |
49 ms |
6736 KB |
Output is correct |
35 |
Correct |
62 ms |
6888 KB |
Output is correct |
36 |
Correct |
56 ms |
6536 KB |
Output is correct |
37 |
Correct |
58 ms |
6584 KB |
Output is correct |
38 |
Correct |
57 ms |
6616 KB |
Output is correct |
39 |
Correct |
55 ms |
6660 KB |
Output is correct |
40 |
Correct |
56 ms |
6488 KB |
Output is correct |
41 |
Correct |
55 ms |
6496 KB |
Output is correct |
42 |
Correct |
57 ms |
6480 KB |
Output is correct |
43 |
Correct |
75 ms |
6636 KB |
Output is correct |
44 |
Correct |
68 ms |
6480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
6476 KB |
Output is correct |
2 |
Correct |
60 ms |
6484 KB |
Output is correct |
3 |
Correct |
56 ms |
6488 KB |
Output is correct |
4 |
Correct |
50 ms |
6484 KB |
Output is correct |
5 |
Correct |
46 ms |
6480 KB |
Output is correct |
6 |
Correct |
47 ms |
6484 KB |
Output is correct |
7 |
Correct |
62 ms |
6628 KB |
Output is correct |
8 |
Correct |
50 ms |
6576 KB |
Output is correct |
9 |
Correct |
52 ms |
6480 KB |
Output is correct |
10 |
Correct |
54 ms |
6484 KB |
Output is correct |
11 |
Correct |
52 ms |
6480 KB |
Output is correct |
12 |
Correct |
51 ms |
6632 KB |
Output is correct |
13 |
Correct |
67 ms |
6484 KB |
Output is correct |
14 |
Correct |
51 ms |
6672 KB |
Output is correct |
15 |
Correct |
52 ms |
6592 KB |
Output is correct |
16 |
Correct |
54 ms |
6488 KB |
Output is correct |
17 |
Correct |
52 ms |
6484 KB |
Output is correct |
18 |
Correct |
65 ms |
6464 KB |
Output is correct |
19 |
Correct |
240 ms |
22080 KB |
Output is correct |
20 |
Correct |
223 ms |
21988 KB |
Output is correct |
21 |
Correct |
142 ms |
21520 KB |
Output is correct |
22 |
Correct |
143 ms |
20544 KB |
Output is correct |
23 |
Correct |
80 ms |
8020 KB |
Output is correct |
24 |
Correct |
83 ms |
7940 KB |
Output is correct |
25 |
Correct |
153 ms |
22240 KB |
Output is correct |
26 |
Correct |
155 ms |
22120 KB |
Output is correct |
27 |
Correct |
176 ms |
22076 KB |
Output is correct |
28 |
Correct |
179 ms |
22260 KB |
Output is correct |
29 |
Correct |
172 ms |
21844 KB |
Output is correct |
30 |
Correct |
90 ms |
7800 KB |
Output is correct |
31 |
Correct |
180 ms |
22356 KB |
Output is correct |
32 |
Correct |
163 ms |
21328 KB |
Output is correct |
33 |
Correct |
84 ms |
7836 KB |
Output is correct |
34 |
Correct |
181 ms |
22552 KB |
Output is correct |
35 |
Correct |
128 ms |
19592 KB |
Output is correct |
36 |
Correct |
81 ms |
8020 KB |
Output is correct |
37 |
Correct |
81 ms |
7968 KB |
Output is correct |
38 |
Correct |
207 ms |
22104 KB |
Output is correct |
39 |
Correct |
122 ms |
21840 KB |
Output is correct |
40 |
Correct |
158 ms |
16292 KB |
Output is correct |
41 |
Correct |
261 ms |
22784 KB |
Output is correct |
42 |
Correct |
80 ms |
21296 KB |
Output is correct |
43 |
Correct |
60 ms |
6476 KB |
Output is correct |
44 |
Correct |
57 ms |
6480 KB |
Output is correct |
45 |
Correct |
52 ms |
6600 KB |
Output is correct |
46 |
Correct |
45 ms |
6484 KB |
Output is correct |
47 |
Correct |
54 ms |
6480 KB |
Output is correct |
48 |
Correct |
50 ms |
6480 KB |
Output is correct |
49 |
Correct |
52 ms |
6672 KB |
Output is correct |
50 |
Correct |
48 ms |
6552 KB |
Output is correct |
51 |
Correct |
53 ms |
6496 KB |
Output is correct |
52 |
Correct |
48 ms |
6484 KB |
Output is correct |
53 |
Correct |
58 ms |
6480 KB |
Output is correct |
54 |
Correct |
53 ms |
6444 KB |
Output is correct |
55 |
Correct |
56 ms |
6484 KB |
Output is correct |
56 |
Correct |
52 ms |
6484 KB |
Output is correct |
57 |
Correct |
56 ms |
6544 KB |
Output is correct |
58 |
Correct |
49 ms |
6736 KB |
Output is correct |
59 |
Correct |
62 ms |
6888 KB |
Output is correct |
60 |
Correct |
56 ms |
6536 KB |
Output is correct |
61 |
Correct |
58 ms |
6584 KB |
Output is correct |
62 |
Correct |
57 ms |
6616 KB |
Output is correct |
63 |
Correct |
55 ms |
6660 KB |
Output is correct |
64 |
Correct |
56 ms |
6488 KB |
Output is correct |
65 |
Correct |
55 ms |
6496 KB |
Output is correct |
66 |
Correct |
57 ms |
6480 KB |
Output is correct |
67 |
Correct |
75 ms |
6636 KB |
Output is correct |
68 |
Correct |
68 ms |
6480 KB |
Output is correct |
69 |
Correct |
232 ms |
33052 KB |
Output is correct |
70 |
Correct |
274 ms |
37464 KB |
Output is correct |
71 |
Correct |
89 ms |
8184 KB |
Output is correct |
72 |
Correct |
90 ms |
8372 KB |
Output is correct |
73 |
Correct |
84 ms |
8312 KB |
Output is correct |
74 |
Correct |
168 ms |
27728 KB |
Output is correct |
75 |
Correct |
85 ms |
8272 KB |
Output is correct |
76 |
Correct |
171 ms |
30952 KB |
Output is correct |
77 |
Correct |
193 ms |
27848 KB |
Output is correct |
78 |
Correct |
86 ms |
8424 KB |
Output is correct |
79 |
Correct |
87 ms |
8488 KB |
Output is correct |
80 |
Correct |
161 ms |
30164 KB |
Output is correct |
81 |
Correct |
86 ms |
8788 KB |
Output is correct |
82 |
Correct |
203 ms |
37604 KB |
Output is correct |
83 |
Correct |
186 ms |
36068 KB |
Output is correct |
84 |
Correct |
118 ms |
8788 KB |
Output is correct |
85 |
Correct |
103 ms |
8788 KB |
Output is correct |
86 |
Correct |
192 ms |
31312 KB |
Output is correct |
87 |
Correct |
217 ms |
37412 KB |
Output is correct |
88 |
Correct |
104 ms |
8652 KB |
Output is correct |
89 |
Correct |
194 ms |
34216 KB |
Output is correct |
90 |
Correct |
228 ms |
37632 KB |
Output is correct |
91 |
Correct |
99 ms |
8788 KB |
Output is correct |
92 |
Correct |
166 ms |
31052 KB |
Output is correct |
93 |
Correct |
137 ms |
8756 KB |
Output is correct |
94 |
Correct |
97 ms |
8912 KB |
Output is correct |
95 |
Correct |
87 ms |
8788 KB |
Output is correct |
96 |
Correct |
218 ms |
21684 KB |
Output is correct |
97 |
Correct |
157 ms |
37348 KB |
Output is correct |
98 |
Correct |
163 ms |
26464 KB |
Output is correct |
99 |
Correct |
309 ms |
37832 KB |
Output is correct |
100 |
Correct |
120 ms |
36812 KB |
Output is correct |