//IN THE NAME OF GOD
#include<bits/stdc++.h>
#pragma GCC optimize("O2,unroll-loops")
#define endl '\n'
#define F first
#define S second
#define pii pair<int,int>
#define all(x) x.begin(),x.end()
#define pb push_back
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long ll;
typedef long double dll;
#define int long long
const int N = 2e5+7, mod = 1e9+7, base = 73;
string a[3], t;
set<int> s;
int n, pw[N], seg[N<<2], dp[N];
pair<int,char> lz[N<<2];
int hashing(string s){
int ans = 0;
for(int i=0; i<ll(s.size()); i++) ans = ans * base % mod + (s[i]-'A'+1);
return ans;
}
string merge(string a, string b){
string make = "";
for(int i=0; i<ll(a.size()); i++){
if (a[i] == b[i]) make += a[i];
else{
if ((a[i] == 'O' && b[i] == 'J') || (a[i] == 'J' && b[i] == 'O')) make+='I';
if ((a[i] == 'O' && b[i] == 'I') || (a[i] == 'I' && b[i] == 'O')) make+='J';
if ((a[i] == 'I' && b[i] == 'J') || (a[i] == 'J' && b[i] == 'I')) make+='O';
}
}
return make;
}
void build(int ind, int l, int r){
if (l == r){
int ans = 0;
for(int i=l; i<=r; i++) ans = (ans + (t[i]-'A'+1) * pw[n-1-i] % mod) % mod;
seg[ind] = ans;
return;
}
int mid = (l+r)>>1;
build(2*ind,l,mid);
build(2*ind+1,mid+1,r);
seg[ind] += (seg[2*ind] + seg[2*ind+1]) % mod;
}
void shift(int ind, int l, int r){
if (!lz[ind].F) return;
int en = n-l-1, st = n-1-r;
int maj = dp[en] - (st == 0 ? 0 : dp[st-1]) + mod;
maj %= mod;
seg[ind] = (lz[ind].S-'A'+1) * maj % mod;
if (l != r){
lz[2*ind] = lz[ind];
lz[2*ind+1] = lz[ind];
}
lz[ind].F = 0;
}
void upd(int ind, int l, int r, int st, int en, char c){
shift(ind,l,r);
if (l > en || st > r) return;
if (l == r || (l >= st && r <= en)){
int en = n-l-1, st = n-1-r;
int maj = dp[en] - (st == 0 ? 0 : dp[st-1]) + mod;
maj %= mod;
seg[ind] = (c-'A'+1) * maj % mod;
if (l != r){
lz[2*ind] = {1,c};
lz[2*ind+1] = {1,c};
}
return;
}
int mid = (l+r)>>1;
upd(2*ind,l,mid,st,en,c);
upd(2*ind+1,mid+1,r,st,en,c);
seg[ind] = (seg[2*ind]+seg[2*ind+1])%mod;
}
int32_t main(){
fastio;
pw[0] = dp[0] = 1;
for(int i=1; i<N; i++){
pw[i] = pw[i-1] * base % mod;
dp[i] = (dp[i-1] + pw[i]) % mod;
}
cin >> n;
cin >> a[0] >> a[1] >> a[2];
s.insert(hashing(a[0]));
s.insert(hashing(a[1]));
s.insert(hashing(a[2]));
for(int i=0; i<3; i++)for(int j=0; j<3; j++) if (i != j) s.insert(hashing(merge(a[i],a[j])));
for(int i=0; i<3; i++){
for(int j=0; j<3; j++){
if (i == j) continue;
for(int k =0; k<3; k++){
if (k == i || k == j) continue;
s.insert(hashing(merge(merge(a[i],a[j]),a[k])));
}
}
}
int q; cin >> q;
cin >> t;
build(1,0,n-1);
if (s.find(seg[1]) != s.end()) cout << "Yes" << endl;
else cout << "No" << endl;
while(q--){
int l,r; cin >> l >> r; l--; r--;
char c; cin >> c;
upd(1,0,n-1,l,r,c);
if (s.find(seg[1]) != s.end()) cout << "Yes" << endl;
else cout << "No" << endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
7508 KB |
Output is correct |
2 |
Correct |
74 ms |
7892 KB |
Output is correct |
3 |
Correct |
72 ms |
7764 KB |
Output is correct |
4 |
Correct |
57 ms |
7624 KB |
Output is correct |
5 |
Correct |
56 ms |
7760 KB |
Output is correct |
6 |
Correct |
57 ms |
7764 KB |
Output is correct |
7 |
Correct |
57 ms |
7764 KB |
Output is correct |
8 |
Correct |
66 ms |
7848 KB |
Output is correct |
9 |
Correct |
59 ms |
7908 KB |
Output is correct |
10 |
Correct |
72 ms |
7844 KB |
Output is correct |
11 |
Correct |
62 ms |
7764 KB |
Output is correct |
12 |
Correct |
59 ms |
7732 KB |
Output is correct |
13 |
Correct |
60 ms |
7760 KB |
Output is correct |
14 |
Correct |
61 ms |
7888 KB |
Output is correct |
15 |
Correct |
60 ms |
7760 KB |
Output is correct |
16 |
Correct |
58 ms |
7764 KB |
Output is correct |
17 |
Correct |
60 ms |
7896 KB |
Output is correct |
18 |
Correct |
65 ms |
7804 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
7508 KB |
Output is correct |
2 |
Correct |
74 ms |
7892 KB |
Output is correct |
3 |
Correct |
72 ms |
7764 KB |
Output is correct |
4 |
Correct |
57 ms |
7624 KB |
Output is correct |
5 |
Correct |
56 ms |
7760 KB |
Output is correct |
6 |
Correct |
57 ms |
7764 KB |
Output is correct |
7 |
Correct |
57 ms |
7764 KB |
Output is correct |
8 |
Correct |
66 ms |
7848 KB |
Output is correct |
9 |
Correct |
59 ms |
7908 KB |
Output is correct |
10 |
Correct |
72 ms |
7844 KB |
Output is correct |
11 |
Correct |
62 ms |
7764 KB |
Output is correct |
12 |
Correct |
59 ms |
7732 KB |
Output is correct |
13 |
Correct |
60 ms |
7760 KB |
Output is correct |
14 |
Correct |
61 ms |
7888 KB |
Output is correct |
15 |
Correct |
60 ms |
7760 KB |
Output is correct |
16 |
Correct |
58 ms |
7764 KB |
Output is correct |
17 |
Correct |
60 ms |
7896 KB |
Output is correct |
18 |
Correct |
65 ms |
7804 KB |
Output is correct |
19 |
Correct |
242 ms |
23688 KB |
Output is correct |
20 |
Correct |
236 ms |
17064 KB |
Output is correct |
21 |
Correct |
143 ms |
23324 KB |
Output is correct |
22 |
Correct |
162 ms |
23476 KB |
Output is correct |
23 |
Correct |
92 ms |
11056 KB |
Output is correct |
24 |
Correct |
97 ms |
10836 KB |
Output is correct |
25 |
Correct |
151 ms |
23616 KB |
Output is correct |
26 |
Correct |
179 ms |
23968 KB |
Output is correct |
27 |
Correct |
195 ms |
23732 KB |
Output is correct |
28 |
Correct |
181 ms |
23664 KB |
Output is correct |
29 |
Correct |
167 ms |
23288 KB |
Output is correct |
30 |
Correct |
110 ms |
11044 KB |
Output is correct |
31 |
Correct |
203 ms |
23828 KB |
Output is correct |
32 |
Correct |
173 ms |
23736 KB |
Output is correct |
33 |
Correct |
99 ms |
10916 KB |
Output is correct |
34 |
Correct |
205 ms |
23792 KB |
Output is correct |
35 |
Correct |
128 ms |
22920 KB |
Output is correct |
36 |
Correct |
90 ms |
10996 KB |
Output is correct |
37 |
Correct |
102 ms |
10836 KB |
Output is correct |
38 |
Correct |
202 ms |
18572 KB |
Output is correct |
39 |
Correct |
119 ms |
17544 KB |
Output is correct |
40 |
Correct |
137 ms |
16824 KB |
Output is correct |
41 |
Correct |
249 ms |
23944 KB |
Output is correct |
42 |
Correct |
66 ms |
14708 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
7508 KB |
Output is correct |
2 |
Correct |
74 ms |
7892 KB |
Output is correct |
3 |
Correct |
72 ms |
7764 KB |
Output is correct |
4 |
Correct |
57 ms |
7624 KB |
Output is correct |
5 |
Correct |
56 ms |
7760 KB |
Output is correct |
6 |
Correct |
57 ms |
7764 KB |
Output is correct |
7 |
Correct |
57 ms |
7764 KB |
Output is correct |
8 |
Correct |
66 ms |
7848 KB |
Output is correct |
9 |
Correct |
59 ms |
7908 KB |
Output is correct |
10 |
Correct |
72 ms |
7844 KB |
Output is correct |
11 |
Correct |
62 ms |
7764 KB |
Output is correct |
12 |
Correct |
59 ms |
7732 KB |
Output is correct |
13 |
Correct |
60 ms |
7760 KB |
Output is correct |
14 |
Correct |
61 ms |
7888 KB |
Output is correct |
15 |
Correct |
60 ms |
7760 KB |
Output is correct |
16 |
Correct |
58 ms |
7764 KB |
Output is correct |
17 |
Correct |
60 ms |
7896 KB |
Output is correct |
18 |
Correct |
65 ms |
7804 KB |
Output is correct |
19 |
Correct |
69 ms |
7800 KB |
Output is correct |
20 |
Correct |
74 ms |
7760 KB |
Output is correct |
21 |
Correct |
66 ms |
7840 KB |
Output is correct |
22 |
Correct |
54 ms |
7584 KB |
Output is correct |
23 |
Correct |
67 ms |
7732 KB |
Output is correct |
24 |
Correct |
58 ms |
7764 KB |
Output is correct |
25 |
Correct |
60 ms |
7696 KB |
Output is correct |
26 |
Correct |
56 ms |
7764 KB |
Output is correct |
27 |
Correct |
60 ms |
7844 KB |
Output is correct |
28 |
Correct |
68 ms |
7732 KB |
Output is correct |
29 |
Correct |
62 ms |
7764 KB |
Output is correct |
30 |
Correct |
54 ms |
7508 KB |
Output is correct |
31 |
Correct |
62 ms |
7992 KB |
Output is correct |
32 |
Correct |
62 ms |
7764 KB |
Output is correct |
33 |
Correct |
66 ms |
7680 KB |
Output is correct |
34 |
Correct |
57 ms |
7620 KB |
Output is correct |
35 |
Correct |
63 ms |
7892 KB |
Output is correct |
36 |
Correct |
62 ms |
7744 KB |
Output is correct |
37 |
Correct |
78 ms |
7692 KB |
Output is correct |
38 |
Correct |
64 ms |
7712 KB |
Output is correct |
39 |
Correct |
68 ms |
7700 KB |
Output is correct |
40 |
Correct |
63 ms |
8016 KB |
Output is correct |
41 |
Correct |
62 ms |
7764 KB |
Output is correct |
42 |
Correct |
70 ms |
8280 KB |
Output is correct |
43 |
Correct |
60 ms |
7760 KB |
Output is correct |
44 |
Correct |
81 ms |
7672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
7508 KB |
Output is correct |
2 |
Correct |
74 ms |
7892 KB |
Output is correct |
3 |
Correct |
72 ms |
7764 KB |
Output is correct |
4 |
Correct |
57 ms |
7624 KB |
Output is correct |
5 |
Correct |
56 ms |
7760 KB |
Output is correct |
6 |
Correct |
57 ms |
7764 KB |
Output is correct |
7 |
Correct |
57 ms |
7764 KB |
Output is correct |
8 |
Correct |
66 ms |
7848 KB |
Output is correct |
9 |
Correct |
59 ms |
7908 KB |
Output is correct |
10 |
Correct |
72 ms |
7844 KB |
Output is correct |
11 |
Correct |
62 ms |
7764 KB |
Output is correct |
12 |
Correct |
59 ms |
7732 KB |
Output is correct |
13 |
Correct |
60 ms |
7760 KB |
Output is correct |
14 |
Correct |
61 ms |
7888 KB |
Output is correct |
15 |
Correct |
60 ms |
7760 KB |
Output is correct |
16 |
Correct |
58 ms |
7764 KB |
Output is correct |
17 |
Correct |
60 ms |
7896 KB |
Output is correct |
18 |
Correct |
65 ms |
7804 KB |
Output is correct |
19 |
Correct |
242 ms |
23688 KB |
Output is correct |
20 |
Correct |
236 ms |
17064 KB |
Output is correct |
21 |
Correct |
143 ms |
23324 KB |
Output is correct |
22 |
Correct |
162 ms |
23476 KB |
Output is correct |
23 |
Correct |
92 ms |
11056 KB |
Output is correct |
24 |
Correct |
97 ms |
10836 KB |
Output is correct |
25 |
Correct |
151 ms |
23616 KB |
Output is correct |
26 |
Correct |
179 ms |
23968 KB |
Output is correct |
27 |
Correct |
195 ms |
23732 KB |
Output is correct |
28 |
Correct |
181 ms |
23664 KB |
Output is correct |
29 |
Correct |
167 ms |
23288 KB |
Output is correct |
30 |
Correct |
110 ms |
11044 KB |
Output is correct |
31 |
Correct |
203 ms |
23828 KB |
Output is correct |
32 |
Correct |
173 ms |
23736 KB |
Output is correct |
33 |
Correct |
99 ms |
10916 KB |
Output is correct |
34 |
Correct |
205 ms |
23792 KB |
Output is correct |
35 |
Correct |
128 ms |
22920 KB |
Output is correct |
36 |
Correct |
90 ms |
10996 KB |
Output is correct |
37 |
Correct |
102 ms |
10836 KB |
Output is correct |
38 |
Correct |
202 ms |
18572 KB |
Output is correct |
39 |
Correct |
119 ms |
17544 KB |
Output is correct |
40 |
Correct |
137 ms |
16824 KB |
Output is correct |
41 |
Correct |
249 ms |
23944 KB |
Output is correct |
42 |
Correct |
66 ms |
14708 KB |
Output is correct |
43 |
Correct |
69 ms |
7800 KB |
Output is correct |
44 |
Correct |
74 ms |
7760 KB |
Output is correct |
45 |
Correct |
66 ms |
7840 KB |
Output is correct |
46 |
Correct |
54 ms |
7584 KB |
Output is correct |
47 |
Correct |
67 ms |
7732 KB |
Output is correct |
48 |
Correct |
58 ms |
7764 KB |
Output is correct |
49 |
Correct |
60 ms |
7696 KB |
Output is correct |
50 |
Correct |
56 ms |
7764 KB |
Output is correct |
51 |
Correct |
60 ms |
7844 KB |
Output is correct |
52 |
Correct |
68 ms |
7732 KB |
Output is correct |
53 |
Correct |
62 ms |
7764 KB |
Output is correct |
54 |
Correct |
54 ms |
7508 KB |
Output is correct |
55 |
Correct |
62 ms |
7992 KB |
Output is correct |
56 |
Correct |
62 ms |
7764 KB |
Output is correct |
57 |
Correct |
66 ms |
7680 KB |
Output is correct |
58 |
Correct |
57 ms |
7620 KB |
Output is correct |
59 |
Correct |
63 ms |
7892 KB |
Output is correct |
60 |
Correct |
62 ms |
7744 KB |
Output is correct |
61 |
Correct |
78 ms |
7692 KB |
Output is correct |
62 |
Correct |
64 ms |
7712 KB |
Output is correct |
63 |
Correct |
68 ms |
7700 KB |
Output is correct |
64 |
Correct |
63 ms |
8016 KB |
Output is correct |
65 |
Correct |
62 ms |
7764 KB |
Output is correct |
66 |
Correct |
70 ms |
8280 KB |
Output is correct |
67 |
Correct |
60 ms |
7760 KB |
Output is correct |
68 |
Correct |
81 ms |
7672 KB |
Output is correct |
69 |
Correct |
248 ms |
23020 KB |
Output is correct |
70 |
Correct |
261 ms |
18556 KB |
Output is correct |
71 |
Correct |
105 ms |
10832 KB |
Output is correct |
72 |
Correct |
95 ms |
10848 KB |
Output is correct |
73 |
Correct |
98 ms |
10832 KB |
Output is correct |
74 |
Correct |
157 ms |
23192 KB |
Output is correct |
75 |
Correct |
94 ms |
10920 KB |
Output is correct |
76 |
Correct |
179 ms |
23680 KB |
Output is correct |
77 |
Correct |
177 ms |
23352 KB |
Output is correct |
78 |
Correct |
97 ms |
10836 KB |
Output is correct |
79 |
Correct |
97 ms |
10832 KB |
Output is correct |
80 |
Correct |
157 ms |
22892 KB |
Output is correct |
81 |
Correct |
100 ms |
10864 KB |
Output is correct |
82 |
Correct |
222 ms |
23720 KB |
Output is correct |
83 |
Correct |
194 ms |
24092 KB |
Output is correct |
84 |
Correct |
97 ms |
10872 KB |
Output is correct |
85 |
Correct |
102 ms |
11020 KB |
Output is correct |
86 |
Correct |
163 ms |
23120 KB |
Output is correct |
87 |
Correct |
182 ms |
23808 KB |
Output is correct |
88 |
Correct |
114 ms |
10924 KB |
Output is correct |
89 |
Correct |
171 ms |
23304 KB |
Output is correct |
90 |
Correct |
176 ms |
23672 KB |
Output is correct |
91 |
Correct |
104 ms |
10888 KB |
Output is correct |
92 |
Correct |
166 ms |
23048 KB |
Output is correct |
93 |
Correct |
108 ms |
10836 KB |
Output is correct |
94 |
Correct |
98 ms |
10840 KB |
Output is correct |
95 |
Correct |
98 ms |
10828 KB |
Output is correct |
96 |
Correct |
205 ms |
23504 KB |
Output is correct |
97 |
Correct |
124 ms |
17612 KB |
Output is correct |
98 |
Correct |
155 ms |
17056 KB |
Output is correct |
99 |
Correct |
363 ms |
23956 KB |
Output is correct |
100 |
Correct |
94 ms |
14940 KB |
Output is correct |