#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>
inline int ser(char c) {
return c == 'J' ? 1 : c == 'O' ? 2 : 3;
}
const ll maxN = 2e5+5;
const ll MOD = 1e9+7;
const ll P = 5;
const ll invP1 = 250000002;
ll powP[maxN];
ll get_hash(string s) {
ll hash = 0;
for (int i = 0; i < s.size(); i++) {
hash += powP[i] * ser(s[i]);
hash %= MOD;
}
return hash;
}
inline ll cohash(ll val, int sz) {
return val * (powP[sz] - 1) * invP1 % MOD;
}
struct SEG {
vll toset;
vll hash;
void make(ll n) {
toset.resize(n*4);
hash.resize(n*4);
}
void push(ll v, ll tl, ll tm, ll tr) {
if (toset[v]) {
toset[v*2] = toset[v];
hash[v*2] = cohash(toset[v], tm-tl+1);
toset[v*2+1] = toset[v];
hash[v*2+1] = cohash(toset[v], tr-tm);
toset[v] = 0;
}
}
void pull(ll v, ll tl, ll tm, ll tr) {
hash[v] = (hash[v*2] + powP[tm - tl + 1] * hash[v*2+1]) % MOD;
}
void set(ll v, ll tl, ll tr, ll l, ll r, ll val) {
if (l > r) return;
if (tl == l && tr == r) {
toset[v] = val;
hash[v] = cohash(val, tr-tl+1);
return;
}
ll tm = (tl + tr) / 2;
push(v, tl, tm, tr);
set(v*2, tl, tm, l, min(r, tm), val);
set(v*2+1, tm+1, tr, max(l, tm+1), r, val);
pull(v, tl, tm, tr);
}
void get(ll v, ll tl, ll tr, ll ind) {
if (tl == tr) {
cout << ind << ": " << hash[v] << '\n';
return;
}
ll tm = (tl + tr) / 2;
push(v, tl, tm, tr);
if (ind <= tm) get(v*2, tl, tm, ind);
else get(v*2+1, tm+1, tr, ind);
}
};
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
ll n;
cin >> n;
powP[0] = 1;
for (int i = 1; i <= n; i++) powP[i] = powP[i-1] * P % MOD;
string s1, s2, s3;
cin >> s1 >> s2 >> s3;
ll h = get_hash(s1);
// cout << "hash: " << h << endl;
ll q;
cin >> q;
SEG seg;
seg.make(n);
for (ll i =0 ; i < n; i++) {
char c;
cin >> c;
seg.set(1, 0, n-1, i, i, ser(c));
}
// for (int i = 0; i < n; i++) seg.get(1, 0, n-1, i);
if (seg.hash[1] == h) cout << "Yes\n";
else cout << "No\n";
while (q--) {
ll l, r;
char c;
cin >> l >> r >> c;
l--, r--;
seg.set(1, 0, n-1, l, r, ser(c));
// for (int i = 0; i < n; i++) seg.get(1, 0, n-1, i);
if (seg.hash[1] == h) cout << "Yes\n";
else cout << "No\n";
}
}
Compilation message
Main.cpp: In function 'long long int get_hash(std::string)':
Main.cpp:19:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | for (int i = 0; i < s.size(); i++) {
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
2384 KB |
Output is correct |
2 |
Correct |
73 ms |
2384 KB |
Output is correct |
3 |
Correct |
54 ms |
2384 KB |
Output is correct |
4 |
Correct |
56 ms |
2388 KB |
Output is correct |
5 |
Correct |
39 ms |
2384 KB |
Output is correct |
6 |
Correct |
41 ms |
2396 KB |
Output is correct |
7 |
Correct |
54 ms |
2388 KB |
Output is correct |
8 |
Correct |
44 ms |
2368 KB |
Output is correct |
9 |
Correct |
44 ms |
2412 KB |
Output is correct |
10 |
Correct |
44 ms |
2388 KB |
Output is correct |
11 |
Correct |
44 ms |
2392 KB |
Output is correct |
12 |
Correct |
49 ms |
2388 KB |
Output is correct |
13 |
Correct |
60 ms |
2524 KB |
Output is correct |
14 |
Correct |
41 ms |
2392 KB |
Output is correct |
15 |
Correct |
44 ms |
2520 KB |
Output is correct |
16 |
Correct |
42 ms |
2360 KB |
Output is correct |
17 |
Correct |
43 ms |
2388 KB |
Output is correct |
18 |
Correct |
44 ms |
2504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
2384 KB |
Output is correct |
2 |
Correct |
73 ms |
2384 KB |
Output is correct |
3 |
Correct |
54 ms |
2384 KB |
Output is correct |
4 |
Correct |
56 ms |
2388 KB |
Output is correct |
5 |
Correct |
39 ms |
2384 KB |
Output is correct |
6 |
Correct |
41 ms |
2396 KB |
Output is correct |
7 |
Correct |
54 ms |
2388 KB |
Output is correct |
8 |
Correct |
44 ms |
2368 KB |
Output is correct |
9 |
Correct |
44 ms |
2412 KB |
Output is correct |
10 |
Correct |
44 ms |
2388 KB |
Output is correct |
11 |
Correct |
44 ms |
2392 KB |
Output is correct |
12 |
Correct |
49 ms |
2388 KB |
Output is correct |
13 |
Correct |
60 ms |
2524 KB |
Output is correct |
14 |
Correct |
41 ms |
2392 KB |
Output is correct |
15 |
Correct |
44 ms |
2520 KB |
Output is correct |
16 |
Correct |
42 ms |
2360 KB |
Output is correct |
17 |
Correct |
43 ms |
2388 KB |
Output is correct |
18 |
Correct |
44 ms |
2504 KB |
Output is correct |
19 |
Correct |
219 ms |
19512 KB |
Output is correct |
20 |
Correct |
186 ms |
19256 KB |
Output is correct |
21 |
Correct |
151 ms |
18228 KB |
Output is correct |
22 |
Correct |
141 ms |
16816 KB |
Output is correct |
23 |
Correct |
76 ms |
4176 KB |
Output is correct |
24 |
Correct |
70 ms |
4176 KB |
Output is correct |
25 |
Correct |
140 ms |
19508 KB |
Output is correct |
26 |
Correct |
142 ms |
19480 KB |
Output is correct |
27 |
Correct |
154 ms |
19480 KB |
Output is correct |
28 |
Correct |
159 ms |
19488 KB |
Output is correct |
29 |
Correct |
149 ms |
18976 KB |
Output is correct |
30 |
Correct |
77 ms |
4180 KB |
Output is correct |
31 |
Correct |
152 ms |
19352 KB |
Output is correct |
32 |
Correct |
154 ms |
17960 KB |
Output is correct |
33 |
Correct |
72 ms |
3920 KB |
Output is correct |
34 |
Correct |
158 ms |
19512 KB |
Output is correct |
35 |
Correct |
141 ms |
15184 KB |
Output is correct |
36 |
Correct |
74 ms |
3924 KB |
Output is correct |
37 |
Correct |
72 ms |
4176 KB |
Output is correct |
38 |
Correct |
164 ms |
19252 KB |
Output is correct |
39 |
Correct |
121 ms |
19364 KB |
Output is correct |
40 |
Correct |
141 ms |
14108 KB |
Output is correct |
41 |
Correct |
200 ms |
19512 KB |
Output is correct |
42 |
Correct |
92 ms |
18836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
2384 KB |
Output is correct |
2 |
Correct |
73 ms |
2384 KB |
Output is correct |
3 |
Correct |
54 ms |
2384 KB |
Output is correct |
4 |
Correct |
56 ms |
2388 KB |
Output is correct |
5 |
Correct |
39 ms |
2384 KB |
Output is correct |
6 |
Correct |
41 ms |
2396 KB |
Output is correct |
7 |
Correct |
54 ms |
2388 KB |
Output is correct |
8 |
Correct |
44 ms |
2368 KB |
Output is correct |
9 |
Correct |
44 ms |
2412 KB |
Output is correct |
10 |
Correct |
44 ms |
2388 KB |
Output is correct |
11 |
Correct |
44 ms |
2392 KB |
Output is correct |
12 |
Correct |
49 ms |
2388 KB |
Output is correct |
13 |
Correct |
60 ms |
2524 KB |
Output is correct |
14 |
Correct |
41 ms |
2392 KB |
Output is correct |
15 |
Correct |
44 ms |
2520 KB |
Output is correct |
16 |
Correct |
42 ms |
2360 KB |
Output is correct |
17 |
Correct |
43 ms |
2388 KB |
Output is correct |
18 |
Correct |
44 ms |
2504 KB |
Output is correct |
19 |
Correct |
46 ms |
2400 KB |
Output is correct |
20 |
Correct |
48 ms |
2464 KB |
Output is correct |
21 |
Incorrect |
46 ms |
2384 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
2384 KB |
Output is correct |
2 |
Correct |
73 ms |
2384 KB |
Output is correct |
3 |
Correct |
54 ms |
2384 KB |
Output is correct |
4 |
Correct |
56 ms |
2388 KB |
Output is correct |
5 |
Correct |
39 ms |
2384 KB |
Output is correct |
6 |
Correct |
41 ms |
2396 KB |
Output is correct |
7 |
Correct |
54 ms |
2388 KB |
Output is correct |
8 |
Correct |
44 ms |
2368 KB |
Output is correct |
9 |
Correct |
44 ms |
2412 KB |
Output is correct |
10 |
Correct |
44 ms |
2388 KB |
Output is correct |
11 |
Correct |
44 ms |
2392 KB |
Output is correct |
12 |
Correct |
49 ms |
2388 KB |
Output is correct |
13 |
Correct |
60 ms |
2524 KB |
Output is correct |
14 |
Correct |
41 ms |
2392 KB |
Output is correct |
15 |
Correct |
44 ms |
2520 KB |
Output is correct |
16 |
Correct |
42 ms |
2360 KB |
Output is correct |
17 |
Correct |
43 ms |
2388 KB |
Output is correct |
18 |
Correct |
44 ms |
2504 KB |
Output is correct |
19 |
Correct |
219 ms |
19512 KB |
Output is correct |
20 |
Correct |
186 ms |
19256 KB |
Output is correct |
21 |
Correct |
151 ms |
18228 KB |
Output is correct |
22 |
Correct |
141 ms |
16816 KB |
Output is correct |
23 |
Correct |
76 ms |
4176 KB |
Output is correct |
24 |
Correct |
70 ms |
4176 KB |
Output is correct |
25 |
Correct |
140 ms |
19508 KB |
Output is correct |
26 |
Correct |
142 ms |
19480 KB |
Output is correct |
27 |
Correct |
154 ms |
19480 KB |
Output is correct |
28 |
Correct |
159 ms |
19488 KB |
Output is correct |
29 |
Correct |
149 ms |
18976 KB |
Output is correct |
30 |
Correct |
77 ms |
4180 KB |
Output is correct |
31 |
Correct |
152 ms |
19352 KB |
Output is correct |
32 |
Correct |
154 ms |
17960 KB |
Output is correct |
33 |
Correct |
72 ms |
3920 KB |
Output is correct |
34 |
Correct |
158 ms |
19512 KB |
Output is correct |
35 |
Correct |
141 ms |
15184 KB |
Output is correct |
36 |
Correct |
74 ms |
3924 KB |
Output is correct |
37 |
Correct |
72 ms |
4176 KB |
Output is correct |
38 |
Correct |
164 ms |
19252 KB |
Output is correct |
39 |
Correct |
121 ms |
19364 KB |
Output is correct |
40 |
Correct |
141 ms |
14108 KB |
Output is correct |
41 |
Correct |
200 ms |
19512 KB |
Output is correct |
42 |
Correct |
92 ms |
18836 KB |
Output is correct |
43 |
Correct |
46 ms |
2400 KB |
Output is correct |
44 |
Correct |
48 ms |
2464 KB |
Output is correct |
45 |
Incorrect |
46 ms |
2384 KB |
Output isn't correct |
46 |
Halted |
0 ms |
0 KB |
- |