#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define lt(x) 2*x+1
#define rt(x) 2*x+2
const ll MXN = 2e5 + 20 , PR1 = 19 , PR2 = 31 , MOD1 = 998244353 , MOD2 = 1e9 + 9;
ll po1[MXN] , po2[MXN] , pref1[MXN] , pref2[MXN];
set<pair<ll,ll>> H;
pair<ll,ll> Hash(vector<int> v) {
ll h1 = 0 , h2 = 0 , p1 = 1 , p2 = 1;
for(auto x : v) {
x++;
h1 += x*p1 % MOD1; h1 %= MOD1;
h2 += x*p2 % MOD2; h2 %= MOD2;
p1 *= PR1; p1 %= MOD1;
p2 *= PR2; p2 %= MOD2;
}
return {h1 , h2};
}
vector<int> str[3];
int n,q;
void prep(int c1 , int c2 , int c3) {
vector<int> res(n);
for(int i = 0 ; i < n ; i++) {
res[i] = ((c1*str[0][i]) + (c2*str[1][i]) + (c3*str[2][i])) % 3;
}
H.insert(Hash(res));
}
inline ll P(ll a , ll b , ll MOD) {
ll res = 1;
while(b > 0) {
if(b&1) {
res *= a; res %= MOD;
}
a *= a; a %= MOD;
b >>= 1;
}
return res;
}
struct seg_tree {
int size;
vector<pair<ll,ll>> hsh;
vector<int> layZ;
seg_tree() {
size = 0;
}
void init() {
size = 1;
while(size < n) size <<= 1;
hsh.assign(2*size , {0 , 0});
layZ.assign(2*size , -1);
}
void build(int x , int lx , int rx , vector<int> &v) {
if(rx-lx == 1) {
if(lx < n) {
hsh[x] = {v[lx]+1 , v[lx]+1};
}
return;
}
int m = (lx+rx)/2;
build(lt(x) , lx , m , v);
build(rt(x) , m , rx , v);
pair<ll,ll> p = hsh[lt(x)] , q = hsh[rt(x)];
hsh[x].first = (p.first + q.first*po1[m-lx]%MOD1) % MOD1;
hsh[x].second = (p.second + q.second*po2[m-lx]%MOD2) % MOD2;
}
void build(vector<int> &v) {
build(0 , 0 , size , v);
}
void shift(int x , int lx , int rx) {
if(rx-lx == 1 || layZ[x] == -1) return;
layZ[lt(x)] = layZ[x];
layZ[rt(x)] = layZ[x];
}
void update(int x , int lx , int rx) {
if(layZ[x] == -1) return;
layZ[x]++;
hsh[x].first = layZ[x] * pref1[rx-lx-1] % MOD1;
hsh[x].second = layZ[x] * pref2[rx-lx-1] % MOD2;
layZ[x] = -1;
}
void set(int x , int lx , int rx , int l , int r , int k) {
if(lx >= l && rx <= r) {
layZ[x] = k;
shift(x , lx , rx);
update(x , lx , rx);
return;
}
if(lx >= r || rx <= l) {
shift(x , lx , rx);
update(x , lx , rx);
return;
}
shift(x , lx , rx);
int m = (lx+rx)/2;
set(lt(x) , lx , m , l , r , k);
set(rt(x) , m , rx , l , r , k);
pair<ll,ll> p = hsh[lt(x)] , q = hsh[rt(x)];
hsh[x].first = (p.first + q.first*po1[m-lx]%MOD1) % MOD1;
hsh[x].second = (p.second + q.second*po2[m-lx]%MOD2) % MOD2;
layZ[x] = -1;
}
void set(int l , int r , int k) {
set(0 , 0 , size , l , r , k);
}
pair<ll,ll> get(int x , int lx , int rx , int l , int r) {
if(lx >= l && rx <= r) {
shift(x , lx , rx);
update(x , lx , rx);
return hsh[x];
}
if(lx >= r || rx <= l) {
shift(x , lx , rx);
update(x , lx , rx);
return {0 , 0};
}
shift(x , lx , rx);
int m = (lx+rx)/2;
pair<ll,ll> p = get(lt(x) , lx , m , l , r);
pair<ll,ll> q = get(rt(x) , m , rx , l , r);
pair<ll,ll> res;
res.first = (p.first + q.first*po1[m-lx]%MOD1) % MOD1;
res.second = (p.second + q.second*po2[m-lx]%MOD2) % MOD2;
p = hsh[lt(x)] , q = hsh[rt(x)];
hsh[x].first = (p.first + q.first*po1[m-lx]%MOD1) % MOD1;
hsh[x].second = (p.second + q.second*po2[m-lx]%MOD2) % MOD2;
layZ[x] = -1;
return res;
}
pair<ll,ll> get(int l , int r) {
return get(0 , 0 , size , l , r);
}
};
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
po1[0] = po2[0] = 1;
pref1[0] = pref2[0] = 1;
for(int i = 1 ; i < MXN ; i++) {
po1[i] = po1[i-1] * PR1 % MOD1;
po2[i] = po2[i-1] * PR2 % MOD2;
pref1[i] = (po1[i] + pref1[i-1]) % MOD1;
pref2[i] = (po2[i] + pref2[i-1]) % MOD2;
}
cin >> n;
for(int i = 0 ; i < 3 ; i++) {
string s; cin >> s;
for(auto c : s) {
str[i].push_back(c == 'J' ? 0 : (c == 'O' ? 1 : 2));
}
}
prep(0 , 0 , 1); prep(0 , 1 , 0); prep(0 , 2 , 2);
prep(1 , 0 , 0); prep(1 , 1 , 2); prep(1 , 2 , 1);
prep(2 , 0 , 2); prep(2 , 1 , 1); prep(2 , 2 , 0);
cin >> q;
string s; cin >> s;
vector<int> v;
for(auto c : s) {
v.push_back(c == 'J' ? 0 : (c == 'O' ? 1 : 2));
}
seg_tree seg;
seg.init(); seg.build(v);
cout << (H.count(Hash(v)) ? "Yes\n" : "No\n");
while(q--) {
int l , r;
char c;
cin >> l >> r >> c; l--;
seg.set(l , r , (c == 'J' ? 0 : (c == 'O' ? 1 : 2)));
pair<ll,ll> h = seg.hsh[0];
cout << (H.count(h) ? "Yes\n" : "No\n");
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
7372 KB |
Output is correct |
2 |
Correct |
90 ms |
7516 KB |
Output is correct |
3 |
Correct |
93 ms |
7412 KB |
Output is correct |
4 |
Correct |
80 ms |
7412 KB |
Output is correct |
5 |
Correct |
84 ms |
7580 KB |
Output is correct |
6 |
Correct |
80 ms |
7632 KB |
Output is correct |
7 |
Correct |
80 ms |
7476 KB |
Output is correct |
8 |
Correct |
75 ms |
7512 KB |
Output is correct |
9 |
Correct |
86 ms |
7512 KB |
Output is correct |
10 |
Correct |
106 ms |
7544 KB |
Output is correct |
11 |
Correct |
85 ms |
7440 KB |
Output is correct |
12 |
Correct |
82 ms |
7544 KB |
Output is correct |
13 |
Correct |
85 ms |
7636 KB |
Output is correct |
14 |
Correct |
78 ms |
7420 KB |
Output is correct |
15 |
Correct |
92 ms |
7516 KB |
Output is correct |
16 |
Correct |
115 ms |
7500 KB |
Output is correct |
17 |
Correct |
86 ms |
7508 KB |
Output is correct |
18 |
Correct |
94 ms |
7500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
7372 KB |
Output is correct |
2 |
Correct |
90 ms |
7516 KB |
Output is correct |
3 |
Correct |
93 ms |
7412 KB |
Output is correct |
4 |
Correct |
80 ms |
7412 KB |
Output is correct |
5 |
Correct |
84 ms |
7580 KB |
Output is correct |
6 |
Correct |
80 ms |
7632 KB |
Output is correct |
7 |
Correct |
80 ms |
7476 KB |
Output is correct |
8 |
Correct |
75 ms |
7512 KB |
Output is correct |
9 |
Correct |
86 ms |
7512 KB |
Output is correct |
10 |
Correct |
106 ms |
7544 KB |
Output is correct |
11 |
Correct |
85 ms |
7440 KB |
Output is correct |
12 |
Correct |
82 ms |
7544 KB |
Output is correct |
13 |
Correct |
85 ms |
7636 KB |
Output is correct |
14 |
Correct |
78 ms |
7420 KB |
Output is correct |
15 |
Correct |
92 ms |
7516 KB |
Output is correct |
16 |
Correct |
115 ms |
7500 KB |
Output is correct |
17 |
Correct |
86 ms |
7508 KB |
Output is correct |
18 |
Correct |
94 ms |
7500 KB |
Output is correct |
19 |
Correct |
359 ms |
22216 KB |
Output is correct |
20 |
Correct |
306 ms |
22196 KB |
Output is correct |
21 |
Correct |
236 ms |
21840 KB |
Output is correct |
22 |
Correct |
233 ms |
21588 KB |
Output is correct |
23 |
Correct |
129 ms |
8412 KB |
Output is correct |
24 |
Correct |
130 ms |
8388 KB |
Output is correct |
25 |
Correct |
279 ms |
22276 KB |
Output is correct |
26 |
Correct |
244 ms |
22192 KB |
Output is correct |
27 |
Correct |
311 ms |
22192 KB |
Output is correct |
28 |
Correct |
287 ms |
22148 KB |
Output is correct |
29 |
Correct |
262 ms |
22044 KB |
Output is correct |
30 |
Correct |
171 ms |
8460 KB |
Output is correct |
31 |
Correct |
247 ms |
22156 KB |
Output is correct |
32 |
Correct |
250 ms |
22036 KB |
Output is correct |
33 |
Correct |
176 ms |
8348 KB |
Output is correct |
34 |
Correct |
232 ms |
22168 KB |
Output is correct |
35 |
Correct |
195 ms |
21324 KB |
Output is correct |
36 |
Correct |
139 ms |
8380 KB |
Output is correct |
37 |
Correct |
128 ms |
8364 KB |
Output is correct |
38 |
Correct |
245 ms |
22256 KB |
Output is correct |
39 |
Correct |
163 ms |
22164 KB |
Output is correct |
40 |
Correct |
256 ms |
15948 KB |
Output is correct |
41 |
Correct |
314 ms |
22368 KB |
Output is correct |
42 |
Correct |
129 ms |
22540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
7372 KB |
Output is correct |
2 |
Correct |
90 ms |
7516 KB |
Output is correct |
3 |
Correct |
93 ms |
7412 KB |
Output is correct |
4 |
Correct |
80 ms |
7412 KB |
Output is correct |
5 |
Correct |
84 ms |
7580 KB |
Output is correct |
6 |
Correct |
80 ms |
7632 KB |
Output is correct |
7 |
Correct |
80 ms |
7476 KB |
Output is correct |
8 |
Correct |
75 ms |
7512 KB |
Output is correct |
9 |
Correct |
86 ms |
7512 KB |
Output is correct |
10 |
Correct |
106 ms |
7544 KB |
Output is correct |
11 |
Correct |
85 ms |
7440 KB |
Output is correct |
12 |
Correct |
82 ms |
7544 KB |
Output is correct |
13 |
Correct |
85 ms |
7636 KB |
Output is correct |
14 |
Correct |
78 ms |
7420 KB |
Output is correct |
15 |
Correct |
92 ms |
7516 KB |
Output is correct |
16 |
Correct |
115 ms |
7500 KB |
Output is correct |
17 |
Correct |
86 ms |
7508 KB |
Output is correct |
18 |
Correct |
94 ms |
7500 KB |
Output is correct |
19 |
Correct |
92 ms |
7480 KB |
Output is correct |
20 |
Correct |
101 ms |
7480 KB |
Output is correct |
21 |
Correct |
91 ms |
7536 KB |
Output is correct |
22 |
Correct |
83 ms |
7372 KB |
Output is correct |
23 |
Correct |
89 ms |
7444 KB |
Output is correct |
24 |
Correct |
78 ms |
7488 KB |
Output is correct |
25 |
Correct |
85 ms |
7484 KB |
Output is correct |
26 |
Correct |
90 ms |
7396 KB |
Output is correct |
27 |
Correct |
84 ms |
7496 KB |
Output is correct |
28 |
Correct |
76 ms |
7448 KB |
Output is correct |
29 |
Correct |
89 ms |
7540 KB |
Output is correct |
30 |
Correct |
78 ms |
7468 KB |
Output is correct |
31 |
Correct |
89 ms |
7504 KB |
Output is correct |
32 |
Correct |
81 ms |
7440 KB |
Output is correct |
33 |
Correct |
98 ms |
7572 KB |
Output is correct |
34 |
Correct |
102 ms |
7436 KB |
Output is correct |
35 |
Correct |
82 ms |
7540 KB |
Output is correct |
36 |
Correct |
92 ms |
7540 KB |
Output is correct |
37 |
Correct |
85 ms |
7500 KB |
Output is correct |
38 |
Correct |
87 ms |
7508 KB |
Output is correct |
39 |
Correct |
82 ms |
7524 KB |
Output is correct |
40 |
Correct |
85 ms |
7428 KB |
Output is correct |
41 |
Correct |
90 ms |
7484 KB |
Output is correct |
42 |
Correct |
88 ms |
7436 KB |
Output is correct |
43 |
Correct |
79 ms |
7412 KB |
Output is correct |
44 |
Correct |
86 ms |
7496 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
7372 KB |
Output is correct |
2 |
Correct |
90 ms |
7516 KB |
Output is correct |
3 |
Correct |
93 ms |
7412 KB |
Output is correct |
4 |
Correct |
80 ms |
7412 KB |
Output is correct |
5 |
Correct |
84 ms |
7580 KB |
Output is correct |
6 |
Correct |
80 ms |
7632 KB |
Output is correct |
7 |
Correct |
80 ms |
7476 KB |
Output is correct |
8 |
Correct |
75 ms |
7512 KB |
Output is correct |
9 |
Correct |
86 ms |
7512 KB |
Output is correct |
10 |
Correct |
106 ms |
7544 KB |
Output is correct |
11 |
Correct |
85 ms |
7440 KB |
Output is correct |
12 |
Correct |
82 ms |
7544 KB |
Output is correct |
13 |
Correct |
85 ms |
7636 KB |
Output is correct |
14 |
Correct |
78 ms |
7420 KB |
Output is correct |
15 |
Correct |
92 ms |
7516 KB |
Output is correct |
16 |
Correct |
115 ms |
7500 KB |
Output is correct |
17 |
Correct |
86 ms |
7508 KB |
Output is correct |
18 |
Correct |
94 ms |
7500 KB |
Output is correct |
19 |
Correct |
359 ms |
22216 KB |
Output is correct |
20 |
Correct |
306 ms |
22196 KB |
Output is correct |
21 |
Correct |
236 ms |
21840 KB |
Output is correct |
22 |
Correct |
233 ms |
21588 KB |
Output is correct |
23 |
Correct |
129 ms |
8412 KB |
Output is correct |
24 |
Correct |
130 ms |
8388 KB |
Output is correct |
25 |
Correct |
279 ms |
22276 KB |
Output is correct |
26 |
Correct |
244 ms |
22192 KB |
Output is correct |
27 |
Correct |
311 ms |
22192 KB |
Output is correct |
28 |
Correct |
287 ms |
22148 KB |
Output is correct |
29 |
Correct |
262 ms |
22044 KB |
Output is correct |
30 |
Correct |
171 ms |
8460 KB |
Output is correct |
31 |
Correct |
247 ms |
22156 KB |
Output is correct |
32 |
Correct |
250 ms |
22036 KB |
Output is correct |
33 |
Correct |
176 ms |
8348 KB |
Output is correct |
34 |
Correct |
232 ms |
22168 KB |
Output is correct |
35 |
Correct |
195 ms |
21324 KB |
Output is correct |
36 |
Correct |
139 ms |
8380 KB |
Output is correct |
37 |
Correct |
128 ms |
8364 KB |
Output is correct |
38 |
Correct |
245 ms |
22256 KB |
Output is correct |
39 |
Correct |
163 ms |
22164 KB |
Output is correct |
40 |
Correct |
256 ms |
15948 KB |
Output is correct |
41 |
Correct |
314 ms |
22368 KB |
Output is correct |
42 |
Correct |
129 ms |
22540 KB |
Output is correct |
43 |
Correct |
92 ms |
7480 KB |
Output is correct |
44 |
Correct |
101 ms |
7480 KB |
Output is correct |
45 |
Correct |
91 ms |
7536 KB |
Output is correct |
46 |
Correct |
83 ms |
7372 KB |
Output is correct |
47 |
Correct |
89 ms |
7444 KB |
Output is correct |
48 |
Correct |
78 ms |
7488 KB |
Output is correct |
49 |
Correct |
85 ms |
7484 KB |
Output is correct |
50 |
Correct |
90 ms |
7396 KB |
Output is correct |
51 |
Correct |
84 ms |
7496 KB |
Output is correct |
52 |
Correct |
76 ms |
7448 KB |
Output is correct |
53 |
Correct |
89 ms |
7540 KB |
Output is correct |
54 |
Correct |
78 ms |
7468 KB |
Output is correct |
55 |
Correct |
89 ms |
7504 KB |
Output is correct |
56 |
Correct |
81 ms |
7440 KB |
Output is correct |
57 |
Correct |
98 ms |
7572 KB |
Output is correct |
58 |
Correct |
102 ms |
7436 KB |
Output is correct |
59 |
Correct |
82 ms |
7540 KB |
Output is correct |
60 |
Correct |
92 ms |
7540 KB |
Output is correct |
61 |
Correct |
85 ms |
7500 KB |
Output is correct |
62 |
Correct |
87 ms |
7508 KB |
Output is correct |
63 |
Correct |
82 ms |
7524 KB |
Output is correct |
64 |
Correct |
85 ms |
7428 KB |
Output is correct |
65 |
Correct |
90 ms |
7484 KB |
Output is correct |
66 |
Correct |
88 ms |
7436 KB |
Output is correct |
67 |
Correct |
79 ms |
7412 KB |
Output is correct |
68 |
Correct |
86 ms |
7496 KB |
Output is correct |
69 |
Correct |
275 ms |
22552 KB |
Output is correct |
70 |
Correct |
315 ms |
23700 KB |
Output is correct |
71 |
Correct |
143 ms |
10368 KB |
Output is correct |
72 |
Correct |
121 ms |
10384 KB |
Output is correct |
73 |
Correct |
155 ms |
10376 KB |
Output is correct |
74 |
Correct |
249 ms |
25112 KB |
Output is correct |
75 |
Correct |
125 ms |
10408 KB |
Output is correct |
76 |
Correct |
305 ms |
25800 KB |
Output is correct |
77 |
Correct |
203 ms |
25276 KB |
Output is correct |
78 |
Correct |
131 ms |
10400 KB |
Output is correct |
79 |
Correct |
147 ms |
10388 KB |
Output is correct |
80 |
Correct |
205 ms |
24468 KB |
Output is correct |
81 |
Correct |
124 ms |
10348 KB |
Output is correct |
82 |
Correct |
220 ms |
25848 KB |
Output is correct |
83 |
Correct |
281 ms |
25496 KB |
Output is correct |
84 |
Correct |
136 ms |
10444 KB |
Output is correct |
85 |
Correct |
136 ms |
10424 KB |
Output is correct |
86 |
Correct |
243 ms |
24648 KB |
Output is correct |
87 |
Correct |
278 ms |
25840 KB |
Output is correct |
88 |
Correct |
148 ms |
10404 KB |
Output is correct |
89 |
Correct |
213 ms |
24836 KB |
Output is correct |
90 |
Correct |
315 ms |
25744 KB |
Output is correct |
91 |
Correct |
137 ms |
10556 KB |
Output is correct |
92 |
Correct |
206 ms |
24580 KB |
Output is correct |
93 |
Correct |
130 ms |
10316 KB |
Output is correct |
94 |
Correct |
131 ms |
10416 KB |
Output is correct |
95 |
Correct |
138 ms |
10428 KB |
Output is correct |
96 |
Correct |
263 ms |
25396 KB |
Output is correct |
97 |
Correct |
175 ms |
25892 KB |
Output is correct |
98 |
Correct |
200 ms |
18724 KB |
Output is correct |
99 |
Correct |
320 ms |
25996 KB |
Output is correct |
100 |
Correct |
143 ms |
25312 KB |
Output is correct |