#include <bits/stdc++.h>
using namespace std;
vector<string> s(3);
vector<long long> hash_val(9);
string q;
long long c[(int)2e5+1], cc[(int)(2e5+2)];
const int mod=341036447;
void get(string &a, string &b){
string res;
int n=a.size();
for (int i=0; i<n; i++){
if (a[i] == b[i]){
res += a[i]; continue;
}
if (a[i] == 'J'){
if (b[i] == 'O'){res += 'I';}
else{res += 'O';}
}else if (a[i] == 'O'){
if (b[i] == 'J'){res += 'I';}
else{res += 'J';}
}else{
if (b[i] == 'J'){res += 'O';}
else{res += 'J';}
}
}
s.push_back(res);
}
long long get_hash(string &a){
int n=a.size();
long long res=0;
for (int i=0; i<n; i++){
res += c[i] * (a[i]-'A');
res %= mod;
}
return res;
}
struct segTree{
int l, r, mid;
long long val, lz=0;
segTree *tl, *tr;
segTree(int ll, int rr): l(ll), r(rr){
mid = (l+r)/2;
if (l == r-1){
val = c[l] * (q[l]-'A') % mod;
return;
}
tl = new segTree(l, mid);
tr = new segTree(mid, r);
val = (tl->val + tr->val) % mod;
}
void push(){
if (lz == 0){return;}
if (l == r-1){
val = c[l] * lz % mod; lz = 0;
return;
}
tl->val = lz * (cc[mid] - cc[l]) % mod;
if (tl->val < 0){tl->val += mod;}
tr->val = lz * (cc[r] - cc[mid]) % mod;
if (tr->val < 0){tr->val += mod;}
tl->lz = lz; tr->lz = lz;
lz = 0;
}
void update(int ll, int rr, long long u){
if (ll <= l && rr >= r){
lz = u;
val = u * (cc[r] - cc[l]) % mod;
if (val < 0){val += mod;}
return;
}
push();
if (ll < mid){tl->update(ll, rr, u);}
if (mid < rr){tr->update(ll, rr, u);}
val = (tl->val + tr->val) % mod;
}
};
int main(){
cin.sync_with_stdio(0); cin.tie(0);
int len; cin >> len;
for (int i=0; i<3; i++){cin >> s[i];}
get(s[0], s[1]); get(s[1], s[2]); get(s[2], s[0]);
get(s[3], s[2]); get(s[4], s[0]); get(s[5], s[1]);
c[0] = 1;
for (int i=1; i<2e5+1; i++){
c[i] = c[i-1] * 29;
c[i] %= mod;
}
cc[0] = 0;
for (int i=1; i<2e5+2; i++){
cc[i] = cc[i-1] + c[i-1];
cc[i] %= mod;
}
for (int i=0; i<9; i++){
hash_val[i] = get_hash(s[i]);
}
int n; cin >> n;
cin >> q;
segTree st(0, len);
bool check=0;
for (auto v: hash_val){
if (v == st.val){check = 1; break;}
}
cout << ((check)? "Yes": "No") << '\n';
for (int nn=0; nn<n; nn++){
int l, r; char m; cin >> l >> r >> m;
int x=m-'A'; l--;
st.update(l, r, x);
check = 0;
for (auto v: hash_val){
if (v == st.val){check = 1; break;}
}
cout << ((check)? "Yes": "No") << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
3952 KB |
Output is correct |
2 |
Correct |
72 ms |
4004 KB |
Output is correct |
3 |
Correct |
65 ms |
4036 KB |
Output is correct |
4 |
Correct |
58 ms |
3908 KB |
Output is correct |
5 |
Correct |
58 ms |
5436 KB |
Output is correct |
6 |
Correct |
58 ms |
5444 KB |
Output is correct |
7 |
Correct |
59 ms |
5456 KB |
Output is correct |
8 |
Correct |
62 ms |
5460 KB |
Output is correct |
9 |
Correct |
63 ms |
5488 KB |
Output is correct |
10 |
Correct |
62 ms |
5576 KB |
Output is correct |
11 |
Correct |
60 ms |
5488 KB |
Output is correct |
12 |
Correct |
60 ms |
5508 KB |
Output is correct |
13 |
Correct |
62 ms |
5516 KB |
Output is correct |
14 |
Correct |
60 ms |
5536 KB |
Output is correct |
15 |
Correct |
60 ms |
5492 KB |
Output is correct |
16 |
Correct |
68 ms |
5512 KB |
Output is correct |
17 |
Correct |
59 ms |
5572 KB |
Output is correct |
18 |
Correct |
62 ms |
5508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
3952 KB |
Output is correct |
2 |
Correct |
72 ms |
4004 KB |
Output is correct |
3 |
Correct |
65 ms |
4036 KB |
Output is correct |
4 |
Correct |
58 ms |
3908 KB |
Output is correct |
5 |
Correct |
58 ms |
5436 KB |
Output is correct |
6 |
Correct |
58 ms |
5444 KB |
Output is correct |
7 |
Correct |
59 ms |
5456 KB |
Output is correct |
8 |
Correct |
62 ms |
5460 KB |
Output is correct |
9 |
Correct |
63 ms |
5488 KB |
Output is correct |
10 |
Correct |
62 ms |
5576 KB |
Output is correct |
11 |
Correct |
60 ms |
5488 KB |
Output is correct |
12 |
Correct |
60 ms |
5508 KB |
Output is correct |
13 |
Correct |
62 ms |
5516 KB |
Output is correct |
14 |
Correct |
60 ms |
5536 KB |
Output is correct |
15 |
Correct |
60 ms |
5492 KB |
Output is correct |
16 |
Correct |
68 ms |
5512 KB |
Output is correct |
17 |
Correct |
59 ms |
5572 KB |
Output is correct |
18 |
Correct |
62 ms |
5508 KB |
Output is correct |
19 |
Correct |
286 ms |
34760 KB |
Output is correct |
20 |
Correct |
205 ms |
34620 KB |
Output is correct |
21 |
Correct |
199 ms |
32804 KB |
Output is correct |
22 |
Correct |
203 ms |
30132 KB |
Output is correct |
23 |
Correct |
98 ms |
7732 KB |
Output is correct |
24 |
Correct |
98 ms |
7748 KB |
Output is correct |
25 |
Correct |
229 ms |
34960 KB |
Output is correct |
26 |
Correct |
222 ms |
34752 KB |
Output is correct |
27 |
Correct |
248 ms |
34716 KB |
Output is correct |
28 |
Correct |
253 ms |
34740 KB |
Output is correct |
29 |
Correct |
227 ms |
33796 KB |
Output is correct |
30 |
Correct |
105 ms |
7748 KB |
Output is correct |
31 |
Correct |
223 ms |
34748 KB |
Output is correct |
32 |
Correct |
231 ms |
32148 KB |
Output is correct |
33 |
Correct |
98 ms |
7732 KB |
Output is correct |
34 |
Correct |
241 ms |
34656 KB |
Output is correct |
35 |
Correct |
187 ms |
27300 KB |
Output is correct |
36 |
Correct |
96 ms |
7748 KB |
Output is correct |
37 |
Correct |
99 ms |
7760 KB |
Output is correct |
38 |
Correct |
193 ms |
34504 KB |
Output is correct |
39 |
Correct |
128 ms |
34744 KB |
Output is correct |
40 |
Correct |
213 ms |
25000 KB |
Output is correct |
41 |
Correct |
305 ms |
34848 KB |
Output is correct |
42 |
Correct |
77 ms |
34124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
3952 KB |
Output is correct |
2 |
Correct |
72 ms |
4004 KB |
Output is correct |
3 |
Correct |
65 ms |
4036 KB |
Output is correct |
4 |
Correct |
58 ms |
3908 KB |
Output is correct |
5 |
Correct |
58 ms |
5436 KB |
Output is correct |
6 |
Correct |
58 ms |
5444 KB |
Output is correct |
7 |
Correct |
59 ms |
5456 KB |
Output is correct |
8 |
Correct |
62 ms |
5460 KB |
Output is correct |
9 |
Correct |
63 ms |
5488 KB |
Output is correct |
10 |
Correct |
62 ms |
5576 KB |
Output is correct |
11 |
Correct |
60 ms |
5488 KB |
Output is correct |
12 |
Correct |
60 ms |
5508 KB |
Output is correct |
13 |
Correct |
62 ms |
5516 KB |
Output is correct |
14 |
Correct |
60 ms |
5536 KB |
Output is correct |
15 |
Correct |
60 ms |
5492 KB |
Output is correct |
16 |
Correct |
68 ms |
5512 KB |
Output is correct |
17 |
Correct |
59 ms |
5572 KB |
Output is correct |
18 |
Correct |
62 ms |
5508 KB |
Output is correct |
19 |
Correct |
67 ms |
5432 KB |
Output is correct |
20 |
Correct |
90 ms |
5356 KB |
Output is correct |
21 |
Correct |
62 ms |
5500 KB |
Output is correct |
22 |
Correct |
57 ms |
5272 KB |
Output is correct |
23 |
Correct |
60 ms |
5552 KB |
Output is correct |
24 |
Correct |
59 ms |
5444 KB |
Output is correct |
25 |
Correct |
59 ms |
5480 KB |
Output is correct |
26 |
Correct |
59 ms |
5484 KB |
Output is correct |
27 |
Correct |
62 ms |
5540 KB |
Output is correct |
28 |
Correct |
57 ms |
5312 KB |
Output is correct |
29 |
Correct |
61 ms |
5564 KB |
Output is correct |
30 |
Correct |
57 ms |
5368 KB |
Output is correct |
31 |
Correct |
61 ms |
5524 KB |
Output is correct |
32 |
Correct |
59 ms |
5444 KB |
Output is correct |
33 |
Correct |
64 ms |
5520 KB |
Output is correct |
34 |
Correct |
56 ms |
5424 KB |
Output is correct |
35 |
Correct |
61 ms |
5556 KB |
Output is correct |
36 |
Correct |
60 ms |
5488 KB |
Output is correct |
37 |
Correct |
64 ms |
5572 KB |
Output is correct |
38 |
Correct |
63 ms |
5572 KB |
Output is correct |
39 |
Correct |
60 ms |
5572 KB |
Output is correct |
40 |
Correct |
60 ms |
5464 KB |
Output is correct |
41 |
Correct |
61 ms |
5508 KB |
Output is correct |
42 |
Correct |
62 ms |
5552 KB |
Output is correct |
43 |
Correct |
58 ms |
5420 KB |
Output is correct |
44 |
Correct |
64 ms |
5616 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
3952 KB |
Output is correct |
2 |
Correct |
72 ms |
4004 KB |
Output is correct |
3 |
Correct |
65 ms |
4036 KB |
Output is correct |
4 |
Correct |
58 ms |
3908 KB |
Output is correct |
5 |
Correct |
58 ms |
5436 KB |
Output is correct |
6 |
Correct |
58 ms |
5444 KB |
Output is correct |
7 |
Correct |
59 ms |
5456 KB |
Output is correct |
8 |
Correct |
62 ms |
5460 KB |
Output is correct |
9 |
Correct |
63 ms |
5488 KB |
Output is correct |
10 |
Correct |
62 ms |
5576 KB |
Output is correct |
11 |
Correct |
60 ms |
5488 KB |
Output is correct |
12 |
Correct |
60 ms |
5508 KB |
Output is correct |
13 |
Correct |
62 ms |
5516 KB |
Output is correct |
14 |
Correct |
60 ms |
5536 KB |
Output is correct |
15 |
Correct |
60 ms |
5492 KB |
Output is correct |
16 |
Correct |
68 ms |
5512 KB |
Output is correct |
17 |
Correct |
59 ms |
5572 KB |
Output is correct |
18 |
Correct |
62 ms |
5508 KB |
Output is correct |
19 |
Correct |
286 ms |
34760 KB |
Output is correct |
20 |
Correct |
205 ms |
34620 KB |
Output is correct |
21 |
Correct |
199 ms |
32804 KB |
Output is correct |
22 |
Correct |
203 ms |
30132 KB |
Output is correct |
23 |
Correct |
98 ms |
7732 KB |
Output is correct |
24 |
Correct |
98 ms |
7748 KB |
Output is correct |
25 |
Correct |
229 ms |
34960 KB |
Output is correct |
26 |
Correct |
222 ms |
34752 KB |
Output is correct |
27 |
Correct |
248 ms |
34716 KB |
Output is correct |
28 |
Correct |
253 ms |
34740 KB |
Output is correct |
29 |
Correct |
227 ms |
33796 KB |
Output is correct |
30 |
Correct |
105 ms |
7748 KB |
Output is correct |
31 |
Correct |
223 ms |
34748 KB |
Output is correct |
32 |
Correct |
231 ms |
32148 KB |
Output is correct |
33 |
Correct |
98 ms |
7732 KB |
Output is correct |
34 |
Correct |
241 ms |
34656 KB |
Output is correct |
35 |
Correct |
187 ms |
27300 KB |
Output is correct |
36 |
Correct |
96 ms |
7748 KB |
Output is correct |
37 |
Correct |
99 ms |
7760 KB |
Output is correct |
38 |
Correct |
193 ms |
34504 KB |
Output is correct |
39 |
Correct |
128 ms |
34744 KB |
Output is correct |
40 |
Correct |
213 ms |
25000 KB |
Output is correct |
41 |
Correct |
305 ms |
34848 KB |
Output is correct |
42 |
Correct |
77 ms |
34124 KB |
Output is correct |
43 |
Correct |
67 ms |
5432 KB |
Output is correct |
44 |
Correct |
90 ms |
5356 KB |
Output is correct |
45 |
Correct |
62 ms |
5500 KB |
Output is correct |
46 |
Correct |
57 ms |
5272 KB |
Output is correct |
47 |
Correct |
60 ms |
5552 KB |
Output is correct |
48 |
Correct |
59 ms |
5444 KB |
Output is correct |
49 |
Correct |
59 ms |
5480 KB |
Output is correct |
50 |
Correct |
59 ms |
5484 KB |
Output is correct |
51 |
Correct |
62 ms |
5540 KB |
Output is correct |
52 |
Correct |
57 ms |
5312 KB |
Output is correct |
53 |
Correct |
61 ms |
5564 KB |
Output is correct |
54 |
Correct |
57 ms |
5368 KB |
Output is correct |
55 |
Correct |
61 ms |
5524 KB |
Output is correct |
56 |
Correct |
59 ms |
5444 KB |
Output is correct |
57 |
Correct |
64 ms |
5520 KB |
Output is correct |
58 |
Correct |
56 ms |
5424 KB |
Output is correct |
59 |
Correct |
61 ms |
5556 KB |
Output is correct |
60 |
Correct |
60 ms |
5488 KB |
Output is correct |
61 |
Correct |
64 ms |
5572 KB |
Output is correct |
62 |
Correct |
63 ms |
5572 KB |
Output is correct |
63 |
Correct |
60 ms |
5572 KB |
Output is correct |
64 |
Correct |
60 ms |
5464 KB |
Output is correct |
65 |
Correct |
61 ms |
5508 KB |
Output is correct |
66 |
Correct |
62 ms |
5552 KB |
Output is correct |
67 |
Correct |
58 ms |
5420 KB |
Output is correct |
68 |
Correct |
64 ms |
5616 KB |
Output is correct |
69 |
Correct |
241 ms |
29784 KB |
Output is correct |
70 |
Correct |
211 ms |
34660 KB |
Output is correct |
71 |
Correct |
99 ms |
7860 KB |
Output is correct |
72 |
Correct |
98 ms |
7776 KB |
Output is correct |
73 |
Correct |
100 ms |
7748 KB |
Output is correct |
74 |
Correct |
225 ms |
29800 KB |
Output is correct |
75 |
Correct |
101 ms |
7748 KB |
Output is correct |
76 |
Correct |
223 ms |
34728 KB |
Output is correct |
77 |
Correct |
204 ms |
29896 KB |
Output is correct |
78 |
Correct |
98 ms |
7724 KB |
Output is correct |
79 |
Correct |
100 ms |
7788 KB |
Output is correct |
80 |
Correct |
190 ms |
26368 KB |
Output is correct |
81 |
Correct |
109 ms |
7688 KB |
Output is correct |
82 |
Correct |
231 ms |
34748 KB |
Output is correct |
83 |
Correct |
239 ms |
32860 KB |
Output is correct |
84 |
Correct |
106 ms |
7632 KB |
Output is correct |
85 |
Correct |
108 ms |
7784 KB |
Output is correct |
86 |
Correct |
215 ms |
27884 KB |
Output is correct |
87 |
Correct |
247 ms |
34752 KB |
Output is correct |
88 |
Correct |
110 ms |
7748 KB |
Output is correct |
89 |
Correct |
232 ms |
31128 KB |
Output is correct |
90 |
Correct |
245 ms |
34748 KB |
Output is correct |
91 |
Correct |
106 ms |
7736 KB |
Output is correct |
92 |
Correct |
217 ms |
27480 KB |
Output is correct |
93 |
Correct |
102 ms |
7700 KB |
Output is correct |
94 |
Correct |
105 ms |
7864 KB |
Output is correct |
95 |
Correct |
103 ms |
7752 KB |
Output is correct |
96 |
Correct |
183 ms |
34500 KB |
Output is correct |
97 |
Correct |
134 ms |
34764 KB |
Output is correct |
98 |
Correct |
220 ms |
24960 KB |
Output is correct |
99 |
Correct |
314 ms |
34888 KB |
Output is correct |
100 |
Correct |
88 ms |
34108 KB |
Output is correct |