#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define endl '\n'
#define MASK(i) (1LL << (i))
#define ull unsigned long long
#define ld long double
#define pb push_back
#define all(x) (x).begin() , (x).end()
#define BIT(x , i) ((x >> (i)) & 1)
#define TASK "task"
#define sz(s) (int) (s).size()
using namespace std;
const int mxN = 5e5 + 227;
const int inf = 1e9 + 277;
const ll infll = 1e18 + 7;
const int base = 307;
const int LOG = 20;
template <typename T1, typename T2> bool minimize(T1 &a, T2 b) {
if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b) {
if (a < b) {a = b; return true;} return false;
}
int mod[2] = {(int) 1e9 + 7, (int) 1e9 + 9};
int pw[mxN][2];
int f[10][mxN][10];
int getidx(char ch)
{
if(ch == 'J') return 0;
if(ch == 'O') return 1;
if(ch == 'I') return 2;
}
string tt;
struct SegmentLazy{
int n;
vector<pair<int, int>> t;
vector<char> lz;
SegmentLazy(){}
SegmentLazy(int _n)
{
n = _n;
int offset = 1;
while(offset < n) offset *= 2;
t.resize(offset * 2, make_pair(0, 0));
lz.resize(offset * 2, '*');
}
void push_down(int v, int tl, int tr)
{
if(lz[v] == '*') return;
int tm = (tl + tr) / 2;
t[v * 2].fi = 1LL * f[getidx(lz[v])][tm - tl + 1][0];
t[v * 2].se = 1LL * f[getidx(lz[v])][tm - tl + 1][1];
t[v * 2 + 1].fi = 1LL * f[getidx(lz[v])][tr - tm][0];
t[v * 2 + 1].se = 1LL * f[getidx(lz[v])][tr - tm][1];
lz[v * 2] = lz[v * 2 + 1] = lz[v];
lz[v] = '*';
}
void build(int v, int tl, int tr)
{
if(tl == tr) {
t[v].fi = f[getidx(tt[tl - 1])][tr - tl + 1][0];
t[v].se = f[getidx(tt[tl - 1])][tr - tl + 1][1];
lz[v] = '*';
}
else {
int tm = (tl + tr) / 2;
build(v * 2, tl, tm);
build(v * 2 + 1, tm + 1, tr);
t[v].fi = (1LL * t[v * 2].fi * pw[tr - tm][0] % mod[0] + t[v * 2 + 1].fi) % mod[0];
t[v].se = (1LL * t[v * 2].se * pw[tr - tm][1] % mod[1] + t[v * 2 + 1].se) % mod[1];
}
}
void update(int v, int tl, int tr, int l, int r, char val)
{
if(l > r) return;
if(tl == l && tr == r) {
t[v].fi = f[getidx(val)][r - l + 1][0];
t[v].se = f[getidx(val)][r - l + 1][1];
lz[v] = val;
}
else {
int tm = (tl + tr) / 2;
push_down(v, tl, tr);
update(v * 2, tl, tm, l, min(r, tm), val);
update(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, val);
t[v].fi = (1LL * t[v * 2].fi * pw[tr - tm][0] % mod[0] + t[v * 2 + 1].fi) % mod[0];
t[v].se = (1LL * t[v * 2].se * pw[tr - tm][1] % mod[1] + t[v * 2 + 1].se) % mod[1];
}
}
void update(int l, int r, char val)
{
update(1, 1, n, l, r, val);
}
} seg;
int n;
int q;
string s1;
string s2;
string s3;
string t;
char spec[3] = {'J', 'O', 'I'};
pair<int, int> findhash(string a, string b = "", string c = "")
{
string res = a;
if(sz(res) == sz(b)) {
for(int i = 0; i < sz(b); i++) {
if(res[i] == b[i]) continue;
res[i] = spec[0 ^ 1 ^ 2 ^ getidx(res[i]) ^ getidx(b[i])];
}
}
if(sz(res) == sz(c)) {
for(int i = 0; i < sz(c); i++) {
if(res[i] == c[i]) continue;
res[i] = spec[0 ^ 1 ^ 2 ^ getidx(res[i]) ^ getidx(c[i])];
}
}
pair<int, int> ans = {0, 0};
for(int i = 0; i < sz(res); i++) {
ans.fi = (1LL * ans.fi * base + res[i]) % mod[0];
ans.se = (1LL * ans.se * base + res[i]) % mod[1];
}
//cout << res << ' ';
//cout << ans.fi << ' ' << ans.se << endl;
return ans;
}
void solve()
{
cin >> n >> s1 >> s2 >> s3;
cin >> q;
cin >> t;
tt = t;
pw[0][0] = pw[0][1] = 1;
for(int i = 1; i <= n; i++) {
for(int j = 0; j < 2; j++) {
pw[i][j] = 1LL * pw[i - 1][j] * base % mod[j];
}
}
for(int i = 0; i < 3; i++) {
char it = spec[i];
f[i][0][0] = f[i][0][1] = 0;
for(int j = 1; j <= n; j++)
for(int k = 0; k < 2; k++)
f[i][j][k] = (1LL * f[i][j - 1][k] * base + it) % mod[k];
}
vector<pair<int, int>> val;
val.pb(findhash(s1));
val.pb(findhash(s2));
val.pb(findhash(s3));
val.pb(findhash(s1, s2));
val.pb(findhash(s1, s3));
val.pb(findhash(s2, s3));
val.pb(findhash(s2, s3, s1));
val.pb(findhash(s1, s2, s3));
val.pb(findhash(s1, s3, s2));
sort(all(val));
seg = SegmentLazy(n);
seg.build(1, 1, n);
pair<int, int> tmp = seg.t[1];
//cout << tmp.fi << ' ' << tmp.se << endl;
if(binary_search(all(val), tmp) == true) cout << "Yes" << endl;
else cout << "No" << endl;
while(q--) {
int l, r;
char c;
cin >> l >> r >> c;
seg.update(l, r, c);
pair<int, int> tmp = seg.t[1];
//cout << tmp.fi << ' ' << tmp.se << endl;
if(binary_search(all(val), tmp) == true) cout << "Yes" << endl;
else cout << "No" << endl;
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen(TASK".inp" , "r" , stdin);
//freopen(TASK".out" , "w" , stdout);
int tc = 1;
//cin >> tc;
while(tc--) {
solve();
}
return 0;
}
Compilation message
Main.cpp: In function 'int getidx(char)':
Main.cpp:38:1: warning: control reaches end of non-void function [-Wreturn-type]
38 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
101 ms |
2320 KB |
Output is correct |
2 |
Correct |
113 ms |
2444 KB |
Output is correct |
3 |
Correct |
117 ms |
2360 KB |
Output is correct |
4 |
Correct |
93 ms |
2400 KB |
Output is correct |
5 |
Correct |
93 ms |
2396 KB |
Output is correct |
6 |
Correct |
92 ms |
2252 KB |
Output is correct |
7 |
Correct |
94 ms |
2324 KB |
Output is correct |
8 |
Correct |
101 ms |
2448 KB |
Output is correct |
9 |
Correct |
105 ms |
2416 KB |
Output is correct |
10 |
Correct |
98 ms |
2488 KB |
Output is correct |
11 |
Correct |
102 ms |
2540 KB |
Output is correct |
12 |
Correct |
101 ms |
2448 KB |
Output is correct |
13 |
Correct |
98 ms |
2488 KB |
Output is correct |
14 |
Correct |
96 ms |
2472 KB |
Output is correct |
15 |
Correct |
101 ms |
2472 KB |
Output is correct |
16 |
Correct |
103 ms |
2380 KB |
Output is correct |
17 |
Correct |
98 ms |
2380 KB |
Output is correct |
18 |
Correct |
104 ms |
2332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
101 ms |
2320 KB |
Output is correct |
2 |
Correct |
113 ms |
2444 KB |
Output is correct |
3 |
Correct |
117 ms |
2360 KB |
Output is correct |
4 |
Correct |
93 ms |
2400 KB |
Output is correct |
5 |
Correct |
93 ms |
2396 KB |
Output is correct |
6 |
Correct |
92 ms |
2252 KB |
Output is correct |
7 |
Correct |
94 ms |
2324 KB |
Output is correct |
8 |
Correct |
101 ms |
2448 KB |
Output is correct |
9 |
Correct |
105 ms |
2416 KB |
Output is correct |
10 |
Correct |
98 ms |
2488 KB |
Output is correct |
11 |
Correct |
102 ms |
2540 KB |
Output is correct |
12 |
Correct |
101 ms |
2448 KB |
Output is correct |
13 |
Correct |
98 ms |
2488 KB |
Output is correct |
14 |
Correct |
96 ms |
2472 KB |
Output is correct |
15 |
Correct |
101 ms |
2472 KB |
Output is correct |
16 |
Correct |
103 ms |
2380 KB |
Output is correct |
17 |
Correct |
98 ms |
2380 KB |
Output is correct |
18 |
Correct |
104 ms |
2332 KB |
Output is correct |
19 |
Correct |
350 ms |
36016 KB |
Output is correct |
20 |
Correct |
379 ms |
36064 KB |
Output is correct |
21 |
Correct |
254 ms |
34288 KB |
Output is correct |
22 |
Correct |
243 ms |
31568 KB |
Output is correct |
23 |
Correct |
167 ms |
4888 KB |
Output is correct |
24 |
Correct |
170 ms |
4972 KB |
Output is correct |
25 |
Correct |
271 ms |
36092 KB |
Output is correct |
26 |
Correct |
278 ms |
36088 KB |
Output is correct |
27 |
Correct |
313 ms |
35968 KB |
Output is correct |
28 |
Correct |
312 ms |
36132 KB |
Output is correct |
29 |
Correct |
296 ms |
35148 KB |
Output is correct |
30 |
Correct |
194 ms |
4880 KB |
Output is correct |
31 |
Correct |
309 ms |
36044 KB |
Output is correct |
32 |
Correct |
295 ms |
33404 KB |
Output is correct |
33 |
Correct |
174 ms |
4896 KB |
Output is correct |
34 |
Correct |
296 ms |
36060 KB |
Output is correct |
35 |
Correct |
265 ms |
28716 KB |
Output is correct |
36 |
Correct |
168 ms |
4872 KB |
Output is correct |
37 |
Correct |
171 ms |
4816 KB |
Output is correct |
38 |
Correct |
327 ms |
35804 KB |
Output is correct |
39 |
Correct |
243 ms |
36108 KB |
Output is correct |
40 |
Correct |
243 ms |
24180 KB |
Output is correct |
41 |
Correct |
390 ms |
36224 KB |
Output is correct |
42 |
Correct |
92 ms |
35492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
101 ms |
2320 KB |
Output is correct |
2 |
Correct |
113 ms |
2444 KB |
Output is correct |
3 |
Correct |
117 ms |
2360 KB |
Output is correct |
4 |
Correct |
93 ms |
2400 KB |
Output is correct |
5 |
Correct |
93 ms |
2396 KB |
Output is correct |
6 |
Correct |
92 ms |
2252 KB |
Output is correct |
7 |
Correct |
94 ms |
2324 KB |
Output is correct |
8 |
Correct |
101 ms |
2448 KB |
Output is correct |
9 |
Correct |
105 ms |
2416 KB |
Output is correct |
10 |
Correct |
98 ms |
2488 KB |
Output is correct |
11 |
Correct |
102 ms |
2540 KB |
Output is correct |
12 |
Correct |
101 ms |
2448 KB |
Output is correct |
13 |
Correct |
98 ms |
2488 KB |
Output is correct |
14 |
Correct |
96 ms |
2472 KB |
Output is correct |
15 |
Correct |
101 ms |
2472 KB |
Output is correct |
16 |
Correct |
103 ms |
2380 KB |
Output is correct |
17 |
Correct |
98 ms |
2380 KB |
Output is correct |
18 |
Correct |
104 ms |
2332 KB |
Output is correct |
19 |
Correct |
109 ms |
2384 KB |
Output is correct |
20 |
Correct |
119 ms |
2396 KB |
Output is correct |
21 |
Correct |
103 ms |
2424 KB |
Output is correct |
22 |
Correct |
88 ms |
2252 KB |
Output is correct |
23 |
Correct |
106 ms |
2560 KB |
Output is correct |
24 |
Correct |
97 ms |
2460 KB |
Output is correct |
25 |
Correct |
102 ms |
2400 KB |
Output is correct |
26 |
Correct |
92 ms |
2280 KB |
Output is correct |
27 |
Correct |
105 ms |
2488 KB |
Output is correct |
28 |
Correct |
92 ms |
2356 KB |
Output is correct |
29 |
Correct |
103 ms |
2540 KB |
Output is correct |
30 |
Correct |
88 ms |
2284 KB |
Output is correct |
31 |
Correct |
103 ms |
2436 KB |
Output is correct |
32 |
Correct |
104 ms |
2412 KB |
Output is correct |
33 |
Correct |
108 ms |
2416 KB |
Output is correct |
34 |
Correct |
94 ms |
2284 KB |
Output is correct |
35 |
Correct |
110 ms |
2460 KB |
Output is correct |
36 |
Correct |
111 ms |
2428 KB |
Output is correct |
37 |
Correct |
109 ms |
2452 KB |
Output is correct |
38 |
Correct |
108 ms |
2484 KB |
Output is correct |
39 |
Correct |
108 ms |
2424 KB |
Output is correct |
40 |
Correct |
108 ms |
2380 KB |
Output is correct |
41 |
Correct |
103 ms |
2484 KB |
Output is correct |
42 |
Correct |
111 ms |
2488 KB |
Output is correct |
43 |
Correct |
102 ms |
2400 KB |
Output is correct |
44 |
Correct |
101 ms |
2380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
101 ms |
2320 KB |
Output is correct |
2 |
Correct |
113 ms |
2444 KB |
Output is correct |
3 |
Correct |
117 ms |
2360 KB |
Output is correct |
4 |
Correct |
93 ms |
2400 KB |
Output is correct |
5 |
Correct |
93 ms |
2396 KB |
Output is correct |
6 |
Correct |
92 ms |
2252 KB |
Output is correct |
7 |
Correct |
94 ms |
2324 KB |
Output is correct |
8 |
Correct |
101 ms |
2448 KB |
Output is correct |
9 |
Correct |
105 ms |
2416 KB |
Output is correct |
10 |
Correct |
98 ms |
2488 KB |
Output is correct |
11 |
Correct |
102 ms |
2540 KB |
Output is correct |
12 |
Correct |
101 ms |
2448 KB |
Output is correct |
13 |
Correct |
98 ms |
2488 KB |
Output is correct |
14 |
Correct |
96 ms |
2472 KB |
Output is correct |
15 |
Correct |
101 ms |
2472 KB |
Output is correct |
16 |
Correct |
103 ms |
2380 KB |
Output is correct |
17 |
Correct |
98 ms |
2380 KB |
Output is correct |
18 |
Correct |
104 ms |
2332 KB |
Output is correct |
19 |
Correct |
350 ms |
36016 KB |
Output is correct |
20 |
Correct |
379 ms |
36064 KB |
Output is correct |
21 |
Correct |
254 ms |
34288 KB |
Output is correct |
22 |
Correct |
243 ms |
31568 KB |
Output is correct |
23 |
Correct |
167 ms |
4888 KB |
Output is correct |
24 |
Correct |
170 ms |
4972 KB |
Output is correct |
25 |
Correct |
271 ms |
36092 KB |
Output is correct |
26 |
Correct |
278 ms |
36088 KB |
Output is correct |
27 |
Correct |
313 ms |
35968 KB |
Output is correct |
28 |
Correct |
312 ms |
36132 KB |
Output is correct |
29 |
Correct |
296 ms |
35148 KB |
Output is correct |
30 |
Correct |
194 ms |
4880 KB |
Output is correct |
31 |
Correct |
309 ms |
36044 KB |
Output is correct |
32 |
Correct |
295 ms |
33404 KB |
Output is correct |
33 |
Correct |
174 ms |
4896 KB |
Output is correct |
34 |
Correct |
296 ms |
36060 KB |
Output is correct |
35 |
Correct |
265 ms |
28716 KB |
Output is correct |
36 |
Correct |
168 ms |
4872 KB |
Output is correct |
37 |
Correct |
171 ms |
4816 KB |
Output is correct |
38 |
Correct |
327 ms |
35804 KB |
Output is correct |
39 |
Correct |
243 ms |
36108 KB |
Output is correct |
40 |
Correct |
243 ms |
24180 KB |
Output is correct |
41 |
Correct |
390 ms |
36224 KB |
Output is correct |
42 |
Correct |
92 ms |
35492 KB |
Output is correct |
43 |
Correct |
109 ms |
2384 KB |
Output is correct |
44 |
Correct |
119 ms |
2396 KB |
Output is correct |
45 |
Correct |
103 ms |
2424 KB |
Output is correct |
46 |
Correct |
88 ms |
2252 KB |
Output is correct |
47 |
Correct |
106 ms |
2560 KB |
Output is correct |
48 |
Correct |
97 ms |
2460 KB |
Output is correct |
49 |
Correct |
102 ms |
2400 KB |
Output is correct |
50 |
Correct |
92 ms |
2280 KB |
Output is correct |
51 |
Correct |
105 ms |
2488 KB |
Output is correct |
52 |
Correct |
92 ms |
2356 KB |
Output is correct |
53 |
Correct |
103 ms |
2540 KB |
Output is correct |
54 |
Correct |
88 ms |
2284 KB |
Output is correct |
55 |
Correct |
103 ms |
2436 KB |
Output is correct |
56 |
Correct |
104 ms |
2412 KB |
Output is correct |
57 |
Correct |
108 ms |
2416 KB |
Output is correct |
58 |
Correct |
94 ms |
2284 KB |
Output is correct |
59 |
Correct |
110 ms |
2460 KB |
Output is correct |
60 |
Correct |
111 ms |
2428 KB |
Output is correct |
61 |
Correct |
109 ms |
2452 KB |
Output is correct |
62 |
Correct |
108 ms |
2484 KB |
Output is correct |
63 |
Correct |
108 ms |
2424 KB |
Output is correct |
64 |
Correct |
108 ms |
2380 KB |
Output is correct |
65 |
Correct |
103 ms |
2484 KB |
Output is correct |
66 |
Correct |
111 ms |
2488 KB |
Output is correct |
67 |
Correct |
102 ms |
2400 KB |
Output is correct |
68 |
Correct |
101 ms |
2380 KB |
Output is correct |
69 |
Correct |
344 ms |
31300 KB |
Output is correct |
70 |
Correct |
396 ms |
35860 KB |
Output is correct |
71 |
Correct |
174 ms |
4880 KB |
Output is correct |
72 |
Correct |
172 ms |
4888 KB |
Output is correct |
73 |
Correct |
176 ms |
5012 KB |
Output is correct |
74 |
Correct |
260 ms |
31152 KB |
Output is correct |
75 |
Correct |
171 ms |
4912 KB |
Output is correct |
76 |
Correct |
274 ms |
36028 KB |
Output is correct |
77 |
Correct |
267 ms |
31384 KB |
Output is correct |
78 |
Correct |
171 ms |
4844 KB |
Output is correct |
79 |
Correct |
170 ms |
5132 KB |
Output is correct |
80 |
Correct |
241 ms |
27652 KB |
Output is correct |
81 |
Correct |
170 ms |
4792 KB |
Output is correct |
82 |
Correct |
285 ms |
35956 KB |
Output is correct |
83 |
Correct |
271 ms |
34192 KB |
Output is correct |
84 |
Correct |
173 ms |
4916 KB |
Output is correct |
85 |
Correct |
181 ms |
5104 KB |
Output is correct |
86 |
Correct |
288 ms |
29128 KB |
Output is correct |
87 |
Correct |
323 ms |
36032 KB |
Output is correct |
88 |
Correct |
192 ms |
4860 KB |
Output is correct |
89 |
Correct |
289 ms |
32500 KB |
Output is correct |
90 |
Correct |
300 ms |
36052 KB |
Output is correct |
91 |
Correct |
192 ms |
4892 KB |
Output is correct |
92 |
Correct |
257 ms |
28760 KB |
Output is correct |
93 |
Correct |
170 ms |
4812 KB |
Output is correct |
94 |
Correct |
172 ms |
4816 KB |
Output is correct |
95 |
Correct |
174 ms |
5024 KB |
Output is correct |
96 |
Correct |
316 ms |
35788 KB |
Output is correct |
97 |
Correct |
248 ms |
36216 KB |
Output is correct |
98 |
Correct |
254 ms |
24200 KB |
Output is correct |
99 |
Correct |
404 ms |
36224 KB |
Output is correct |
100 |
Correct |
100 ms |
35520 KB |
Output is correct |