// Be name khoda //
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) x.begin(), x.end()
#define pb push_back
#define fi first
#define se second
#define mp make_pair
const int maxn5 = 2e5 + 10;
const int maxnt = 1e6 + 10;
ll mod[2] = {1000000007, 1000000009};
ll base[2] = {21163, 21269};
int n, t[maxn5];
pair <ll, ll> hsh[maxnt];
int lazy[maxnt];
string s[3];
ll pw[2][maxn5], ps[2][maxn5];
set <pair<ll, ll>> av;
bool mark[100];
int get_val(char c){
if(c == 'J')
return 0;
if(c == 'O')
return 1;
return 2;
}
struct zarib{
int x[3];
int num;
zarib(){
x[0] = x[1] = x[2] = num = 0;
}
} q[100];
zarib comb(zarib a, zarib b){
zarib ret;
//cout << a.x[0] << ' ' << b.x[0] << endl;
ret.x[0] = (6 - a.x[0] - b.x[0]) % 3;
ret.x[1] = (6 - a.x[1] - b.x[1]) % 3;
ret.x[2] = (6 - a.x[2] - b.x[2]) % 3;
ret.num = ret.x[0] + ret.x[1] * 3 + ret.x[2] * 9;
//cout << ret.x[0] << ' ' << ret.x[1] << ' ' << ret.x[2] << ' ' << ret.num << endl;
return ret;
}
void shift(int, int, int);
void build(int l, int r, int v){
if(r - l == 1){
hsh[v].fi = t[l] * pw[0][n - l - 1] % mod[0];
hsh[v].se = t[l] * pw[1][n - l - 1] % mod[1];
return;
}
int mid = (l + r) >> 1;
build(l, mid, v * 2);
build(mid, r, v * 2 + 1);
hsh[v].fi = (hsh[v * 2].fi + hsh[v * 2 + 1].fi) % mod[0];
hsh[v].se = (hsh[v * 2].se + hsh[v * 2 + 1].se) % mod[1];
}
void upd(int l, int r, int lq, int rq, int val, int v){
if(rq <= l || r <= lq)
return;
if(lq <= l && r <= rq){
lazy[v] = val;
hsh[v].fi = (mod[0] + ps[0][n - l - 1] - (r == n ? 0 : ps[0][n - r - 1])) % mod[0] * val % mod[0];
hsh[v].se = (mod[1] + ps[1][n - l - 1] - (r == n ? 0 : ps[1][n - r - 1])) % mod[1] * val % mod[1];
return;
}
int mid = (l + r) >> 1;
shift(l, r, v);
upd(l, mid, lq, rq, val, v * 2);
upd(mid, r, lq, rq, val, v * 2 + 1);
hsh[v].fi = (hsh[v * 2].fi + hsh[v * 2 + 1].fi) % mod[0];
hsh[v].se = (hsh[v * 2].se + hsh[v * 2 + 1].se) % mod[1];
}
void shift(int l, int r, int v){
if(lazy[v] == -1)
return;
int mid = (l + r) >> 1;
upd(l, mid, l, mid, lazy[v], v * 2);
upd(mid, r, mid, r, lazy[v], v * 2 + 1);
lazy[v] = -1;
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
memset(lazy, -1, sizeof lazy);
cin >> n;
cin >> s[0] >> s[1] >> s[2];
for(int tt = 0; tt < 2; tt++){
pw[tt][0] = 1;
for(int i = 1; i < maxn5; i++)
pw[tt][i] = (pw[tt][i - 1] * base[tt]) % mod[tt];
ps[tt][0] = 1;
for(int i = 1; i < maxn5; i++)
ps[tt][i] = (ps[tt][i - 1] + pw[tt][i]) % mod[tt];
}
zarib a, b, c;
a.x[0] = b.x[1] = c.x[2] = 1;
a.num = 1;
b.num = 3;
c.num = 9;
q[0] = a;
q[1] = b;
q[2] = c;
mark[1] = mark[3] = mark[9] = true;
int l = 0, r = 3;
while(l < r){
zarib a = q[l];
for(int i = 0; i < l; i++){
zarib x = comb(a, q[i]);
if(!mark[x.num]){
q[r++] = x;
mark[x.num] = true;
}
}
l++;
}
for(int i = 0; i < r; i++){
ll val[2] = {0, 0};
for(int j = 0; j < n; j++){
int a = (get_val(s[0][j]) * q[i].x[0] + get_val(s[1][j]) * q[i].x[1] + get_val(s[2][j]) * q[i].x[2]) % 3;
val[0] = (val[0] * base[0] + a) % mod[0];
val[1] = (val[1] * base[1] + a) % mod[1];
//if(i == 0)
// cout << j << ' ' << a << endl;
}
//cout << i << ' ' << val[0] << ' ' << val[1] << endl;
av.insert(mp(val[0], val[1]));
}
string tm; int q;
cin >> q >> tm;
for(int i = 0; i < n; i++)
t[i] = get_val(tm[i]);
build(0, n, 1);
//cout << hsh[1].fi << ' ' << hsh[1].se << endl;
//cout << tm << ' ' << s[0] << endl;
//cout << (tm == s[0] ? "Yes\n" : "No\n");
cout << (av.find(hsh[1]) != av.end() ? "Yes\n" : "No\n");
while(q--){
int l, r; char c; cin >> l >> r >> c;
int a = get_val(c);
upd(0, n, l - 1, r, a, 1);
//cout << (tm == s[0] ? "Yes\n" : "No\n");
cout << (av.find(hsh[1]) != av.end() ? "Yes\n" : "No\n");
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
84 ms |
11012 KB |
Output is correct |
2 |
Correct |
90 ms |
11040 KB |
Output is correct |
3 |
Correct |
98 ms |
11092 KB |
Output is correct |
4 |
Correct |
73 ms |
11064 KB |
Output is correct |
5 |
Correct |
72 ms |
11084 KB |
Output is correct |
6 |
Correct |
70 ms |
10980 KB |
Output is correct |
7 |
Correct |
71 ms |
10996 KB |
Output is correct |
8 |
Correct |
75 ms |
11064 KB |
Output is correct |
9 |
Correct |
76 ms |
11084 KB |
Output is correct |
10 |
Correct |
74 ms |
10988 KB |
Output is correct |
11 |
Correct |
77 ms |
11084 KB |
Output is correct |
12 |
Correct |
73 ms |
11080 KB |
Output is correct |
13 |
Correct |
75 ms |
11084 KB |
Output is correct |
14 |
Correct |
75 ms |
11072 KB |
Output is correct |
15 |
Correct |
76 ms |
11028 KB |
Output is correct |
16 |
Correct |
77 ms |
11068 KB |
Output is correct |
17 |
Correct |
77 ms |
11004 KB |
Output is correct |
18 |
Correct |
94 ms |
11044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
84 ms |
11012 KB |
Output is correct |
2 |
Correct |
90 ms |
11040 KB |
Output is correct |
3 |
Correct |
98 ms |
11092 KB |
Output is correct |
4 |
Correct |
73 ms |
11064 KB |
Output is correct |
5 |
Correct |
72 ms |
11084 KB |
Output is correct |
6 |
Correct |
70 ms |
10980 KB |
Output is correct |
7 |
Correct |
71 ms |
10996 KB |
Output is correct |
8 |
Correct |
75 ms |
11064 KB |
Output is correct |
9 |
Correct |
76 ms |
11084 KB |
Output is correct |
10 |
Correct |
74 ms |
10988 KB |
Output is correct |
11 |
Correct |
77 ms |
11084 KB |
Output is correct |
12 |
Correct |
73 ms |
11080 KB |
Output is correct |
13 |
Correct |
75 ms |
11084 KB |
Output is correct |
14 |
Correct |
75 ms |
11072 KB |
Output is correct |
15 |
Correct |
76 ms |
11028 KB |
Output is correct |
16 |
Correct |
77 ms |
11068 KB |
Output is correct |
17 |
Correct |
77 ms |
11004 KB |
Output is correct |
18 |
Correct |
94 ms |
11044 KB |
Output is correct |
19 |
Correct |
339 ms |
20912 KB |
Output is correct |
20 |
Correct |
356 ms |
22628 KB |
Output is correct |
21 |
Correct |
173 ms |
24344 KB |
Output is correct |
22 |
Correct |
189 ms |
24008 KB |
Output is correct |
23 |
Correct |
117 ms |
14024 KB |
Output is correct |
24 |
Correct |
122 ms |
13948 KB |
Output is correct |
25 |
Correct |
184 ms |
24684 KB |
Output is correct |
26 |
Correct |
199 ms |
24588 KB |
Output is correct |
27 |
Correct |
232 ms |
24668 KB |
Output is correct |
28 |
Correct |
245 ms |
24628 KB |
Output is correct |
29 |
Correct |
220 ms |
24584 KB |
Output is correct |
30 |
Correct |
132 ms |
14028 KB |
Output is correct |
31 |
Correct |
238 ms |
24664 KB |
Output is correct |
32 |
Correct |
253 ms |
24352 KB |
Output is correct |
33 |
Correct |
120 ms |
13920 KB |
Output is correct |
34 |
Correct |
231 ms |
24588 KB |
Output is correct |
35 |
Correct |
164 ms |
23752 KB |
Output is correct |
36 |
Correct |
117 ms |
14040 KB |
Output is correct |
37 |
Correct |
121 ms |
14004 KB |
Output is correct |
38 |
Correct |
322 ms |
24400 KB |
Output is correct |
39 |
Correct |
144 ms |
24660 KB |
Output is correct |
40 |
Correct |
167 ms |
19608 KB |
Output is correct |
41 |
Correct |
390 ms |
24888 KB |
Output is correct |
42 |
Correct |
62 ms |
24040 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
84 ms |
11012 KB |
Output is correct |
2 |
Correct |
90 ms |
11040 KB |
Output is correct |
3 |
Correct |
98 ms |
11092 KB |
Output is correct |
4 |
Correct |
73 ms |
11064 KB |
Output is correct |
5 |
Correct |
72 ms |
11084 KB |
Output is correct |
6 |
Correct |
70 ms |
10980 KB |
Output is correct |
7 |
Correct |
71 ms |
10996 KB |
Output is correct |
8 |
Correct |
75 ms |
11064 KB |
Output is correct |
9 |
Correct |
76 ms |
11084 KB |
Output is correct |
10 |
Correct |
74 ms |
10988 KB |
Output is correct |
11 |
Correct |
77 ms |
11084 KB |
Output is correct |
12 |
Correct |
73 ms |
11080 KB |
Output is correct |
13 |
Correct |
75 ms |
11084 KB |
Output is correct |
14 |
Correct |
75 ms |
11072 KB |
Output is correct |
15 |
Correct |
76 ms |
11028 KB |
Output is correct |
16 |
Correct |
77 ms |
11068 KB |
Output is correct |
17 |
Correct |
77 ms |
11004 KB |
Output is correct |
18 |
Correct |
94 ms |
11044 KB |
Output is correct |
19 |
Correct |
90 ms |
11028 KB |
Output is correct |
20 |
Correct |
102 ms |
11048 KB |
Output is correct |
21 |
Correct |
75 ms |
11084 KB |
Output is correct |
22 |
Correct |
67 ms |
12340 KB |
Output is correct |
23 |
Correct |
76 ms |
12524 KB |
Output is correct |
24 |
Correct |
73 ms |
12456 KB |
Output is correct |
25 |
Correct |
85 ms |
12704 KB |
Output is correct |
26 |
Correct |
71 ms |
12416 KB |
Output is correct |
27 |
Correct |
75 ms |
12532 KB |
Output is correct |
28 |
Correct |
80 ms |
12380 KB |
Output is correct |
29 |
Correct |
78 ms |
12600 KB |
Output is correct |
30 |
Correct |
70 ms |
12336 KB |
Output is correct |
31 |
Correct |
78 ms |
12608 KB |
Output is correct |
32 |
Correct |
77 ms |
12524 KB |
Output is correct |
33 |
Correct |
79 ms |
12564 KB |
Output is correct |
34 |
Correct |
71 ms |
12460 KB |
Output is correct |
35 |
Correct |
77 ms |
12628 KB |
Output is correct |
36 |
Correct |
78 ms |
12604 KB |
Output is correct |
37 |
Correct |
77 ms |
12552 KB |
Output is correct |
38 |
Correct |
81 ms |
12636 KB |
Output is correct |
39 |
Correct |
78 ms |
12688 KB |
Output is correct |
40 |
Correct |
83 ms |
12524 KB |
Output is correct |
41 |
Correct |
77 ms |
12620 KB |
Output is correct |
42 |
Correct |
80 ms |
12540 KB |
Output is correct |
43 |
Correct |
81 ms |
12484 KB |
Output is correct |
44 |
Correct |
82 ms |
12728 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
84 ms |
11012 KB |
Output is correct |
2 |
Correct |
90 ms |
11040 KB |
Output is correct |
3 |
Correct |
98 ms |
11092 KB |
Output is correct |
4 |
Correct |
73 ms |
11064 KB |
Output is correct |
5 |
Correct |
72 ms |
11084 KB |
Output is correct |
6 |
Correct |
70 ms |
10980 KB |
Output is correct |
7 |
Correct |
71 ms |
10996 KB |
Output is correct |
8 |
Correct |
75 ms |
11064 KB |
Output is correct |
9 |
Correct |
76 ms |
11084 KB |
Output is correct |
10 |
Correct |
74 ms |
10988 KB |
Output is correct |
11 |
Correct |
77 ms |
11084 KB |
Output is correct |
12 |
Correct |
73 ms |
11080 KB |
Output is correct |
13 |
Correct |
75 ms |
11084 KB |
Output is correct |
14 |
Correct |
75 ms |
11072 KB |
Output is correct |
15 |
Correct |
76 ms |
11028 KB |
Output is correct |
16 |
Correct |
77 ms |
11068 KB |
Output is correct |
17 |
Correct |
77 ms |
11004 KB |
Output is correct |
18 |
Correct |
94 ms |
11044 KB |
Output is correct |
19 |
Correct |
339 ms |
20912 KB |
Output is correct |
20 |
Correct |
356 ms |
22628 KB |
Output is correct |
21 |
Correct |
173 ms |
24344 KB |
Output is correct |
22 |
Correct |
189 ms |
24008 KB |
Output is correct |
23 |
Correct |
117 ms |
14024 KB |
Output is correct |
24 |
Correct |
122 ms |
13948 KB |
Output is correct |
25 |
Correct |
184 ms |
24684 KB |
Output is correct |
26 |
Correct |
199 ms |
24588 KB |
Output is correct |
27 |
Correct |
232 ms |
24668 KB |
Output is correct |
28 |
Correct |
245 ms |
24628 KB |
Output is correct |
29 |
Correct |
220 ms |
24584 KB |
Output is correct |
30 |
Correct |
132 ms |
14028 KB |
Output is correct |
31 |
Correct |
238 ms |
24664 KB |
Output is correct |
32 |
Correct |
253 ms |
24352 KB |
Output is correct |
33 |
Correct |
120 ms |
13920 KB |
Output is correct |
34 |
Correct |
231 ms |
24588 KB |
Output is correct |
35 |
Correct |
164 ms |
23752 KB |
Output is correct |
36 |
Correct |
117 ms |
14040 KB |
Output is correct |
37 |
Correct |
121 ms |
14004 KB |
Output is correct |
38 |
Correct |
322 ms |
24400 KB |
Output is correct |
39 |
Correct |
144 ms |
24660 KB |
Output is correct |
40 |
Correct |
167 ms |
19608 KB |
Output is correct |
41 |
Correct |
390 ms |
24888 KB |
Output is correct |
42 |
Correct |
62 ms |
24040 KB |
Output is correct |
43 |
Correct |
90 ms |
11028 KB |
Output is correct |
44 |
Correct |
102 ms |
11048 KB |
Output is correct |
45 |
Correct |
75 ms |
11084 KB |
Output is correct |
46 |
Correct |
67 ms |
12340 KB |
Output is correct |
47 |
Correct |
76 ms |
12524 KB |
Output is correct |
48 |
Correct |
73 ms |
12456 KB |
Output is correct |
49 |
Correct |
85 ms |
12704 KB |
Output is correct |
50 |
Correct |
71 ms |
12416 KB |
Output is correct |
51 |
Correct |
75 ms |
12532 KB |
Output is correct |
52 |
Correct |
80 ms |
12380 KB |
Output is correct |
53 |
Correct |
78 ms |
12600 KB |
Output is correct |
54 |
Correct |
70 ms |
12336 KB |
Output is correct |
55 |
Correct |
78 ms |
12608 KB |
Output is correct |
56 |
Correct |
77 ms |
12524 KB |
Output is correct |
57 |
Correct |
79 ms |
12564 KB |
Output is correct |
58 |
Correct |
71 ms |
12460 KB |
Output is correct |
59 |
Correct |
77 ms |
12628 KB |
Output is correct |
60 |
Correct |
78 ms |
12604 KB |
Output is correct |
61 |
Correct |
77 ms |
12552 KB |
Output is correct |
62 |
Correct |
81 ms |
12636 KB |
Output is correct |
63 |
Correct |
78 ms |
12688 KB |
Output is correct |
64 |
Correct |
83 ms |
12524 KB |
Output is correct |
65 |
Correct |
77 ms |
12620 KB |
Output is correct |
66 |
Correct |
80 ms |
12540 KB |
Output is correct |
67 |
Correct |
81 ms |
12484 KB |
Output is correct |
68 |
Correct |
82 ms |
12728 KB |
Output is correct |
69 |
Correct |
320 ms |
23912 KB |
Output is correct |
70 |
Correct |
362 ms |
24712 KB |
Output is correct |
71 |
Correct |
122 ms |
13980 KB |
Output is correct |
72 |
Correct |
120 ms |
14036 KB |
Output is correct |
73 |
Correct |
120 ms |
14080 KB |
Output is correct |
74 |
Correct |
178 ms |
23920 KB |
Output is correct |
75 |
Correct |
120 ms |
14024 KB |
Output is correct |
76 |
Correct |
210 ms |
24680 KB |
Output is correct |
77 |
Correct |
210 ms |
24100 KB |
Output is correct |
78 |
Correct |
124 ms |
14012 KB |
Output is correct |
79 |
Correct |
126 ms |
14012 KB |
Output is correct |
80 |
Correct |
197 ms |
23652 KB |
Output is correct |
81 |
Correct |
132 ms |
13968 KB |
Output is correct |
82 |
Correct |
224 ms |
24680 KB |
Output is correct |
83 |
Correct |
215 ms |
24348 KB |
Output is correct |
84 |
Correct |
131 ms |
13968 KB |
Output is correct |
85 |
Correct |
135 ms |
13992 KB |
Output is correct |
86 |
Correct |
252 ms |
23840 KB |
Output is correct |
87 |
Correct |
267 ms |
24604 KB |
Output is correct |
88 |
Correct |
151 ms |
14028 KB |
Output is correct |
89 |
Correct |
222 ms |
24132 KB |
Output is correct |
90 |
Correct |
239 ms |
24644 KB |
Output is correct |
91 |
Correct |
140 ms |
14128 KB |
Output is correct |
92 |
Correct |
171 ms |
23704 KB |
Output is correct |
93 |
Correct |
132 ms |
13944 KB |
Output is correct |
94 |
Correct |
123 ms |
14028 KB |
Output is correct |
95 |
Correct |
123 ms |
14048 KB |
Output is correct |
96 |
Correct |
307 ms |
24408 KB |
Output is correct |
97 |
Correct |
146 ms |
24684 KB |
Output is correct |
98 |
Correct |
172 ms |
19584 KB |
Output is correct |
99 |
Correct |
388 ms |
24840 KB |
Output is correct |
100 |
Correct |
69 ms |
24132 KB |
Output is correct |