#include <bits/stdc++.h>
using namespace std;
#define int long long // a.k.a. TLE creator
#define all(x) x.begin(), x.end()
template<class A, class B> istream& operator >>(istream &o, pair<A, B> &x){return o >> x.first >> x.second;}
template<class A, class B> ostream& operator <<(ostream &o, pair<A, B> &x){return o << x.first << ' ' << x.second << ' ';}
void setIO(){ios::sync_with_stdio(false); cin.tie(0);}
const int INF = 2e18, MOD = 998244353, N = 2e5 + 2;
int pw[N]{}, p = 9973;
void init(){
pw[0] = 1;
for(int i = 1; i < N; i++)pw[i] = pw[i - 1] * p % MOD;
}
struct Hash{
vector<int> h;
Hash(string s){
h.resize(s.size() + 1);
for(int i = 0; i < s.size(); i++){
h[i + 1] = (h[i] * p + s[i]) % MOD;
}
}
int get(int l, int r){
int ans = h[r + 1] - h[l] * pw[r - l + 1] % MOD;
if(ans < 0)ans += MOD;
return ans;
}
}J(string(N, 'J')), O(string(N, 'O')), I(string(N, 'I'));
int get(char c, int sz){
if(c == 'J')return J.get(0, sz - 1);
else if(c == 'O')return O.get(0, sz - 1);
else return I.get(0, sz - 1);
}
#define lc (p << 1)
#define rc (p << 1 | 1)
struct node{
int h, sz;
char lz = 'a';
void push(char c){
lz = c;
h = get(c, sz);
}
}seg[N << 2];
void pull(int p){seg[p].h = (seg[lc].h * pw[seg[rc].sz] + seg[rc].h) % MOD;}
void push(int p){
if(seg[p].lz != 'a'){
char &c = seg[p].lz;
seg[lc].push(c);
seg[rc].push(c);
c = 'a';
}
}
string t;
int n;
void build(int p = 1, int l = 0, int r = n){
seg[p].sz = r - l;
if(r - l == 1)return void(seg[p].h = t[l]);
int m = l + r >> 1;
build(lc, l, m);
build(rc, m, r);
pull(p);
}
void chg(int a, int b, char c, int p = 1, int l = 0, int r = n){
if(a <= l && b >= r)return void(seg[p].push(c));
push(p);
int m = l + r >> 1;
if(a < m)chg(a, b, c, lc, l, m);
if(b > m)chg(a, b, c, rc, m, r);
pull(p);
}
int qry(){return seg[1].h;}
vector<int> val;
bool good(int h){
for(int i : val)if(i == h)return true;
return false;
}
string joi = "JOI";
string cross(string i, string j){
string ans(i.size(), 'a');
for(int k = 0; k < n; k++){
if(i[k] != j[k]){
for(char c : joi)if(i[k] != c && j[k] != c){
ans[k] = c;
break;
}
}else ans[k] = i[k];
}
return ans;
}
int oneHash(string s){
int v = 0;
for(int j = 0; j < n; j++){
v = (v * p + s[j]) % MOD;
}
return v;
}
signed main(){
setIO();
init();
cin >> n;
string s[3];
for(auto &i : s)cin >> i;
val.push_back(oneHash(s[0]));
val.push_back(oneHash(s[1]));
val.push_back(oneHash(s[2]));
val.push_back(oneHash(cross(s[0], s[1])));
val.push_back(oneHash(cross(s[0], s[2])));
val.push_back(oneHash(cross(s[1], s[2])));
val.push_back(oneHash(cross(s[0], cross(s[1], s[2]))));
val.push_back(oneHash(cross(s[1], cross(s[0], s[2]))));
val.push_back(oneHash(cross(s[2], cross(s[0], s[1]))));
int q;
cin >> q >> t;
build();
cout << (good(qry()) ? "Yes\n" : "No\n");
for(int i = 0; i < q; i++){
int l, r;
char c;
cin >> l >> r >> c;
--l;
chg(l, r, c);
cout << (good(qry()) ? "Yes\n" : "No\n");
}
}
Compilation message
Main.cpp: In constructor 'Hash::Hash(std::string)':
Main.cpp:21:26: 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]
21 | for(int i = 0; i < s.size(); i++){
| ~~^~~~~~~~~~
Main.cpp: In function 'void build(long long int, long long int, long long int)':
Main.cpp:67:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
67 | int m = l + r >> 1;
| ~~^~~
Main.cpp: In function 'void chg(long long int, long long int, char, long long int, long long int, long long int)':
Main.cpp:76:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
76 | int m = l + r >> 1;
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
78 ms |
27392 KB |
Output is correct |
2 |
Correct |
98 ms |
27580 KB |
Output is correct |
3 |
Correct |
81 ms |
27500 KB |
Output is correct |
4 |
Correct |
80 ms |
27460 KB |
Output is correct |
5 |
Correct |
70 ms |
27456 KB |
Output is correct |
6 |
Correct |
78 ms |
27400 KB |
Output is correct |
7 |
Correct |
85 ms |
27568 KB |
Output is correct |
8 |
Correct |
77 ms |
27564 KB |
Output is correct |
9 |
Correct |
89 ms |
27616 KB |
Output is correct |
10 |
Correct |
92 ms |
27712 KB |
Output is correct |
11 |
Correct |
75 ms |
27604 KB |
Output is correct |
12 |
Correct |
74 ms |
27584 KB |
Output is correct |
13 |
Correct |
74 ms |
27620 KB |
Output is correct |
14 |
Correct |
103 ms |
27644 KB |
Output is correct |
15 |
Correct |
99 ms |
27572 KB |
Output is correct |
16 |
Correct |
72 ms |
27556 KB |
Output is correct |
17 |
Correct |
77 ms |
27636 KB |
Output is correct |
18 |
Correct |
106 ms |
27464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
78 ms |
27392 KB |
Output is correct |
2 |
Correct |
98 ms |
27580 KB |
Output is correct |
3 |
Correct |
81 ms |
27500 KB |
Output is correct |
4 |
Correct |
80 ms |
27460 KB |
Output is correct |
5 |
Correct |
70 ms |
27456 KB |
Output is correct |
6 |
Correct |
78 ms |
27400 KB |
Output is correct |
7 |
Correct |
85 ms |
27568 KB |
Output is correct |
8 |
Correct |
77 ms |
27564 KB |
Output is correct |
9 |
Correct |
89 ms |
27616 KB |
Output is correct |
10 |
Correct |
92 ms |
27712 KB |
Output is correct |
11 |
Correct |
75 ms |
27604 KB |
Output is correct |
12 |
Correct |
74 ms |
27584 KB |
Output is correct |
13 |
Correct |
74 ms |
27620 KB |
Output is correct |
14 |
Correct |
103 ms |
27644 KB |
Output is correct |
15 |
Correct |
99 ms |
27572 KB |
Output is correct |
16 |
Correct |
72 ms |
27556 KB |
Output is correct |
17 |
Correct |
77 ms |
27636 KB |
Output is correct |
18 |
Correct |
106 ms |
27464 KB |
Output is correct |
19 |
Correct |
232 ms |
31364 KB |
Output is correct |
20 |
Correct |
237 ms |
31208 KB |
Output is correct |
21 |
Correct |
158 ms |
31140 KB |
Output is correct |
22 |
Correct |
157 ms |
30400 KB |
Output is correct |
23 |
Correct |
137 ms |
28492 KB |
Output is correct |
24 |
Correct |
124 ms |
28468 KB |
Output is correct |
25 |
Correct |
162 ms |
31304 KB |
Output is correct |
26 |
Correct |
193 ms |
31336 KB |
Output is correct |
27 |
Correct |
189 ms |
31484 KB |
Output is correct |
28 |
Correct |
188 ms |
31316 KB |
Output is correct |
29 |
Correct |
213 ms |
31128 KB |
Output is correct |
30 |
Correct |
130 ms |
28528 KB |
Output is correct |
31 |
Correct |
176 ms |
31360 KB |
Output is correct |
32 |
Correct |
197 ms |
30572 KB |
Output is correct |
33 |
Correct |
126 ms |
28552 KB |
Output is correct |
34 |
Correct |
210 ms |
31312 KB |
Output is correct |
35 |
Correct |
160 ms |
30372 KB |
Output is correct |
36 |
Correct |
125 ms |
28572 KB |
Output is correct |
37 |
Correct |
111 ms |
28468 KB |
Output is correct |
38 |
Correct |
270 ms |
31084 KB |
Output is correct |
39 |
Correct |
137 ms |
31296 KB |
Output is correct |
40 |
Correct |
179 ms |
30440 KB |
Output is correct |
41 |
Correct |
265 ms |
31500 KB |
Output is correct |
42 |
Correct |
65 ms |
30720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
78 ms |
27392 KB |
Output is correct |
2 |
Correct |
98 ms |
27580 KB |
Output is correct |
3 |
Correct |
81 ms |
27500 KB |
Output is correct |
4 |
Correct |
80 ms |
27460 KB |
Output is correct |
5 |
Correct |
70 ms |
27456 KB |
Output is correct |
6 |
Correct |
78 ms |
27400 KB |
Output is correct |
7 |
Correct |
85 ms |
27568 KB |
Output is correct |
8 |
Correct |
77 ms |
27564 KB |
Output is correct |
9 |
Correct |
89 ms |
27616 KB |
Output is correct |
10 |
Correct |
92 ms |
27712 KB |
Output is correct |
11 |
Correct |
75 ms |
27604 KB |
Output is correct |
12 |
Correct |
74 ms |
27584 KB |
Output is correct |
13 |
Correct |
74 ms |
27620 KB |
Output is correct |
14 |
Correct |
103 ms |
27644 KB |
Output is correct |
15 |
Correct |
99 ms |
27572 KB |
Output is correct |
16 |
Correct |
72 ms |
27556 KB |
Output is correct |
17 |
Correct |
77 ms |
27636 KB |
Output is correct |
18 |
Correct |
106 ms |
27464 KB |
Output is correct |
19 |
Correct |
81 ms |
27560 KB |
Output is correct |
20 |
Correct |
90 ms |
27520 KB |
Output is correct |
21 |
Correct |
78 ms |
27616 KB |
Output is correct |
22 |
Correct |
68 ms |
27436 KB |
Output is correct |
23 |
Correct |
79 ms |
27648 KB |
Output is correct |
24 |
Correct |
78 ms |
27516 KB |
Output is correct |
25 |
Correct |
83 ms |
27540 KB |
Output is correct |
26 |
Correct |
78 ms |
27472 KB |
Output is correct |
27 |
Correct |
82 ms |
27564 KB |
Output is correct |
28 |
Correct |
86 ms |
27432 KB |
Output is correct |
29 |
Correct |
75 ms |
27604 KB |
Output is correct |
30 |
Correct |
76 ms |
27456 KB |
Output is correct |
31 |
Correct |
100 ms |
27624 KB |
Output is correct |
32 |
Correct |
75 ms |
27520 KB |
Output is correct |
33 |
Correct |
73 ms |
27644 KB |
Output is correct |
34 |
Correct |
69 ms |
27444 KB |
Output is correct |
35 |
Correct |
84 ms |
27552 KB |
Output is correct |
36 |
Correct |
82 ms |
27532 KB |
Output is correct |
37 |
Correct |
73 ms |
27644 KB |
Output is correct |
38 |
Correct |
76 ms |
27624 KB |
Output is correct |
39 |
Correct |
79 ms |
27560 KB |
Output is correct |
40 |
Correct |
88 ms |
27548 KB |
Output is correct |
41 |
Correct |
73 ms |
27628 KB |
Output is correct |
42 |
Correct |
79 ms |
27620 KB |
Output is correct |
43 |
Correct |
84 ms |
27484 KB |
Output is correct |
44 |
Correct |
98 ms |
27604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
78 ms |
27392 KB |
Output is correct |
2 |
Correct |
98 ms |
27580 KB |
Output is correct |
3 |
Correct |
81 ms |
27500 KB |
Output is correct |
4 |
Correct |
80 ms |
27460 KB |
Output is correct |
5 |
Correct |
70 ms |
27456 KB |
Output is correct |
6 |
Correct |
78 ms |
27400 KB |
Output is correct |
7 |
Correct |
85 ms |
27568 KB |
Output is correct |
8 |
Correct |
77 ms |
27564 KB |
Output is correct |
9 |
Correct |
89 ms |
27616 KB |
Output is correct |
10 |
Correct |
92 ms |
27712 KB |
Output is correct |
11 |
Correct |
75 ms |
27604 KB |
Output is correct |
12 |
Correct |
74 ms |
27584 KB |
Output is correct |
13 |
Correct |
74 ms |
27620 KB |
Output is correct |
14 |
Correct |
103 ms |
27644 KB |
Output is correct |
15 |
Correct |
99 ms |
27572 KB |
Output is correct |
16 |
Correct |
72 ms |
27556 KB |
Output is correct |
17 |
Correct |
77 ms |
27636 KB |
Output is correct |
18 |
Correct |
106 ms |
27464 KB |
Output is correct |
19 |
Correct |
232 ms |
31364 KB |
Output is correct |
20 |
Correct |
237 ms |
31208 KB |
Output is correct |
21 |
Correct |
158 ms |
31140 KB |
Output is correct |
22 |
Correct |
157 ms |
30400 KB |
Output is correct |
23 |
Correct |
137 ms |
28492 KB |
Output is correct |
24 |
Correct |
124 ms |
28468 KB |
Output is correct |
25 |
Correct |
162 ms |
31304 KB |
Output is correct |
26 |
Correct |
193 ms |
31336 KB |
Output is correct |
27 |
Correct |
189 ms |
31484 KB |
Output is correct |
28 |
Correct |
188 ms |
31316 KB |
Output is correct |
29 |
Correct |
213 ms |
31128 KB |
Output is correct |
30 |
Correct |
130 ms |
28528 KB |
Output is correct |
31 |
Correct |
176 ms |
31360 KB |
Output is correct |
32 |
Correct |
197 ms |
30572 KB |
Output is correct |
33 |
Correct |
126 ms |
28552 KB |
Output is correct |
34 |
Correct |
210 ms |
31312 KB |
Output is correct |
35 |
Correct |
160 ms |
30372 KB |
Output is correct |
36 |
Correct |
125 ms |
28572 KB |
Output is correct |
37 |
Correct |
111 ms |
28468 KB |
Output is correct |
38 |
Correct |
270 ms |
31084 KB |
Output is correct |
39 |
Correct |
137 ms |
31296 KB |
Output is correct |
40 |
Correct |
179 ms |
30440 KB |
Output is correct |
41 |
Correct |
265 ms |
31500 KB |
Output is correct |
42 |
Correct |
65 ms |
30720 KB |
Output is correct |
43 |
Correct |
81 ms |
27560 KB |
Output is correct |
44 |
Correct |
90 ms |
27520 KB |
Output is correct |
45 |
Correct |
78 ms |
27616 KB |
Output is correct |
46 |
Correct |
68 ms |
27436 KB |
Output is correct |
47 |
Correct |
79 ms |
27648 KB |
Output is correct |
48 |
Correct |
78 ms |
27516 KB |
Output is correct |
49 |
Correct |
83 ms |
27540 KB |
Output is correct |
50 |
Correct |
78 ms |
27472 KB |
Output is correct |
51 |
Correct |
82 ms |
27564 KB |
Output is correct |
52 |
Correct |
86 ms |
27432 KB |
Output is correct |
53 |
Correct |
75 ms |
27604 KB |
Output is correct |
54 |
Correct |
76 ms |
27456 KB |
Output is correct |
55 |
Correct |
100 ms |
27624 KB |
Output is correct |
56 |
Correct |
75 ms |
27520 KB |
Output is correct |
57 |
Correct |
73 ms |
27644 KB |
Output is correct |
58 |
Correct |
69 ms |
27444 KB |
Output is correct |
59 |
Correct |
84 ms |
27552 KB |
Output is correct |
60 |
Correct |
82 ms |
27532 KB |
Output is correct |
61 |
Correct |
73 ms |
27644 KB |
Output is correct |
62 |
Correct |
76 ms |
27624 KB |
Output is correct |
63 |
Correct |
79 ms |
27560 KB |
Output is correct |
64 |
Correct |
88 ms |
27548 KB |
Output is correct |
65 |
Correct |
73 ms |
27628 KB |
Output is correct |
66 |
Correct |
79 ms |
27620 KB |
Output is correct |
67 |
Correct |
84 ms |
27484 KB |
Output is correct |
68 |
Correct |
98 ms |
27604 KB |
Output is correct |
69 |
Correct |
210 ms |
30580 KB |
Output is correct |
70 |
Correct |
303 ms |
31268 KB |
Output is correct |
71 |
Correct |
115 ms |
28572 KB |
Output is correct |
72 |
Correct |
127 ms |
28448 KB |
Output is correct |
73 |
Correct |
109 ms |
28472 KB |
Output is correct |
74 |
Correct |
173 ms |
30592 KB |
Output is correct |
75 |
Correct |
114 ms |
28508 KB |
Output is correct |
76 |
Correct |
187 ms |
31328 KB |
Output is correct |
77 |
Correct |
181 ms |
30776 KB |
Output is correct |
78 |
Correct |
119 ms |
28544 KB |
Output is correct |
79 |
Correct |
108 ms |
28528 KB |
Output is correct |
80 |
Correct |
171 ms |
30064 KB |
Output is correct |
81 |
Correct |
116 ms |
28460 KB |
Output is correct |
82 |
Correct |
208 ms |
31360 KB |
Output is correct |
83 |
Correct |
182 ms |
31072 KB |
Output is correct |
84 |
Correct |
133 ms |
28464 KB |
Output is correct |
85 |
Correct |
108 ms |
28484 KB |
Output is correct |
86 |
Correct |
189 ms |
30148 KB |
Output is correct |
87 |
Correct |
206 ms |
31320 KB |
Output is correct |
88 |
Correct |
119 ms |
28472 KB |
Output is correct |
89 |
Correct |
252 ms |
30384 KB |
Output is correct |
90 |
Correct |
192 ms |
31252 KB |
Output is correct |
91 |
Correct |
147 ms |
28524 KB |
Output is correct |
92 |
Correct |
164 ms |
30084 KB |
Output is correct |
93 |
Correct |
109 ms |
28592 KB |
Output is correct |
94 |
Correct |
114 ms |
28496 KB |
Output is correct |
95 |
Correct |
118 ms |
28544 KB |
Output is correct |
96 |
Correct |
204 ms |
31096 KB |
Output is correct |
97 |
Correct |
132 ms |
31308 KB |
Output is correct |
98 |
Correct |
184 ms |
30428 KB |
Output is correct |
99 |
Correct |
295 ms |
31476 KB |
Output is correct |
100 |
Correct |
85 ms |
30808 KB |
Output is correct |