#include <bits/stdc++.h>
#define DEBUG 0
using namespace std;
const int N = 2e5 + 10;
const int P = 31;
const int MOD = 1e9 + 7;
string pat = "JOI";
long long bn[N], qs[N];
long long get_hash(string s) {
long long H = 0;
int n = s.length();
for(int i = 0; i < n; i++) {
H = (H * P + s[i]) % MOD;
}
return H;
}
string crossing(string s, string t) {
string res = "";
int n = s.length();
for(int i = 0; i < n; i++) {
if(s[i] == t[i]) {
res += s[i];
continue;
}
for(int j = 0; j < 3; j++) {
if(s[i] != pat[j] and t[i] != pat[j]) {
res += pat[j];
break;
}
}
}
return res;
}
class SegmentTree {
private :
long long tree[4 * N];
char lazy[4 * N];
public :
long long merge(long long L, long long R, int l, int r) {
int mid = (l + r) / 2;
long long res = (L * bn[r - mid + 1] + R) % MOD;
return res;
}
void build(int idx, int l, int r) {
lazy[idx] = '*';
if(l == r) {
char t0;
cin >> t0;
tree[idx] = t0;
return;
}
int mid = (l + r) / 2;
build(idx * 2, l, mid);
build(idx * 2 + 1, mid + 1, r);
tree[idx] = merge(tree[idx * 2], tree[idx * 2 + 1], l, r);
}
void push(int idx, int l, int r) {
if(lazy[idx] == '*') {
return;
}
tree[idx] = (qs[r - l + 1] * lazy[idx]) % MOD;
if(l != r) {
lazy[idx * 2] = lazy[idx * 2 + 1] = lazy[idx];
}
lazy[idx] = '*';
}
void update(int idx, int l, int r, int ql, int qr, char c) {
push(idx, l, r);
if(r < ql or qr < l) {
return;
}
if(ql <= l and r <= qr) {
lazy[idx] = c;
push(idx, l, r);
return;
}
int mid = (l + r) / 2;
update(idx * 2, l, mid, ql, qr, c);
update(idx * 2 + 1, mid + 1, r, ql, qr, c);
tree[idx] = merge(tree[idx * 2], tree[idx * 2 + 1], l, r);
}
long long get_ans() {
return tree[1];
}
void print(int idx, int l, int r) {
push(idx, l, r);
cout << l << " - " << r << " : " << tree[idx] << '\n';
if(l == r) {
return;
}
int mid = (l + r) / 2;
print(idx * 2, l, mid);
print(idx * 2 + 1, mid + 1, r);
}
}ST;
int main() {
cin.tie(0)->sync_with_stdio(0);
int n;
cin >> n;
bn[1] = 1;
qs[1] = 1;
for(int i = 2; i <= n; i++) {
bn[i] = (bn[i - 1] * P) % MOD;
qs[i] = (qs[i - 1] + bn[i]) % MOD;
}
string s[6];
cin >> s[0] >> s[1] >> s[2];
set <long long> Hash;
for(int i = 0; i < 3; i++) {
Hash.insert(get_hash(s[i]));
if(DEBUG) {
cout << s[i] << ' ' << get_hash(s[i]) << '\n';
}
}
for(int i = 0; i < 3; i++) {
for(int j = i + 1; j < 3; j++) {
s[2 + i + j] = crossing(s[i], s[j]);
if(DEBUG) {
cout << s[2 + i + j] << ' ' << get_hash(s[2 + i + j]) << '\n';
}
Hash.insert(get_hash(s[2 + i + j]));
}
}
for(int i = 3; i < 6; i++) {
for(int j = i + 1; j < 6; j++) {
if(DEBUG) {
cout << crossing(s[i], s[j]) << ' ' << get_hash(crossing(s[i], s[j])) << '\n';
}
Hash.insert(get_hash(crossing(s[i], s[j])));
}
}
int q;
cin >> q;
ST.build(1, 0, n - 1); // input string t0
if(DEBUG) {
ST.print(1, 0, n - 1);
cout << ST.get_ans() << " : ";
}
if(Hash.count(ST.get_ans())) {
cout << "Yes\n";
}
else {
cout << "No\n";
}
while(q--) {
int l, r;
char c;
cin >> l >> r >> c;
ST.update(1, 0, n - 1, l - 1, r - 1, c);
if(DEBUG) {
ST.print(1, 0, n - 1);
cout << ST.get_ans() << " : ";
}
if(Hash.count(ST.get_ans())) {
cout << "Yes\n";
}
else {
cout << "No\n";
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
68 ms |
2368 KB |
Output is correct |
2 |
Correct |
72 ms |
2408 KB |
Output is correct |
3 |
Correct |
69 ms |
2308 KB |
Output is correct |
4 |
Correct |
60 ms |
2384 KB |
Output is correct |
5 |
Correct |
61 ms |
2272 KB |
Output is correct |
6 |
Correct |
62 ms |
2288 KB |
Output is correct |
7 |
Correct |
62 ms |
2408 KB |
Output is correct |
8 |
Correct |
61 ms |
2436 KB |
Output is correct |
9 |
Correct |
62 ms |
2392 KB |
Output is correct |
10 |
Correct |
63 ms |
2380 KB |
Output is correct |
11 |
Correct |
64 ms |
2484 KB |
Output is correct |
12 |
Correct |
65 ms |
2380 KB |
Output is correct |
13 |
Correct |
66 ms |
2380 KB |
Output is correct |
14 |
Correct |
66 ms |
2376 KB |
Output is correct |
15 |
Correct |
64 ms |
2464 KB |
Output is correct |
16 |
Correct |
63 ms |
2428 KB |
Output is correct |
17 |
Correct |
65 ms |
2360 KB |
Output is correct |
18 |
Correct |
63 ms |
2340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
68 ms |
2368 KB |
Output is correct |
2 |
Correct |
72 ms |
2408 KB |
Output is correct |
3 |
Correct |
69 ms |
2308 KB |
Output is correct |
4 |
Correct |
60 ms |
2384 KB |
Output is correct |
5 |
Correct |
61 ms |
2272 KB |
Output is correct |
6 |
Correct |
62 ms |
2288 KB |
Output is correct |
7 |
Correct |
62 ms |
2408 KB |
Output is correct |
8 |
Correct |
61 ms |
2436 KB |
Output is correct |
9 |
Correct |
62 ms |
2392 KB |
Output is correct |
10 |
Correct |
63 ms |
2380 KB |
Output is correct |
11 |
Correct |
64 ms |
2484 KB |
Output is correct |
12 |
Correct |
65 ms |
2380 KB |
Output is correct |
13 |
Correct |
66 ms |
2380 KB |
Output is correct |
14 |
Correct |
66 ms |
2376 KB |
Output is correct |
15 |
Correct |
64 ms |
2464 KB |
Output is correct |
16 |
Correct |
63 ms |
2428 KB |
Output is correct |
17 |
Correct |
65 ms |
2360 KB |
Output is correct |
18 |
Correct |
63 ms |
2340 KB |
Output is correct |
19 |
Correct |
204 ms |
14288 KB |
Output is correct |
20 |
Correct |
202 ms |
13892 KB |
Output is correct |
21 |
Correct |
145 ms |
13440 KB |
Output is correct |
22 |
Correct |
137 ms |
12844 KB |
Output is correct |
23 |
Correct |
96 ms |
3784 KB |
Output is correct |
24 |
Correct |
102 ms |
3808 KB |
Output is correct |
25 |
Correct |
151 ms |
14072 KB |
Output is correct |
26 |
Correct |
165 ms |
14040 KB |
Output is correct |
27 |
Correct |
168 ms |
14012 KB |
Output is correct |
28 |
Correct |
168 ms |
14004 KB |
Output is correct |
29 |
Correct |
170 ms |
13944 KB |
Output is correct |
30 |
Correct |
109 ms |
3800 KB |
Output is correct |
31 |
Correct |
165 ms |
14032 KB |
Output is correct |
32 |
Correct |
158 ms |
13464 KB |
Output is correct |
33 |
Correct |
104 ms |
3716 KB |
Output is correct |
34 |
Correct |
168 ms |
14080 KB |
Output is correct |
35 |
Correct |
130 ms |
12348 KB |
Output is correct |
36 |
Correct |
105 ms |
3752 KB |
Output is correct |
37 |
Correct |
98 ms |
3824 KB |
Output is correct |
38 |
Correct |
175 ms |
13820 KB |
Output is correct |
39 |
Correct |
128 ms |
14056 KB |
Output is correct |
40 |
Correct |
137 ms |
9796 KB |
Output is correct |
41 |
Correct |
213 ms |
14148 KB |
Output is correct |
42 |
Correct |
61 ms |
13436 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
68 ms |
2368 KB |
Output is correct |
2 |
Correct |
72 ms |
2408 KB |
Output is correct |
3 |
Correct |
69 ms |
2308 KB |
Output is correct |
4 |
Correct |
60 ms |
2384 KB |
Output is correct |
5 |
Correct |
61 ms |
2272 KB |
Output is correct |
6 |
Correct |
62 ms |
2288 KB |
Output is correct |
7 |
Correct |
62 ms |
2408 KB |
Output is correct |
8 |
Correct |
61 ms |
2436 KB |
Output is correct |
9 |
Correct |
62 ms |
2392 KB |
Output is correct |
10 |
Correct |
63 ms |
2380 KB |
Output is correct |
11 |
Correct |
64 ms |
2484 KB |
Output is correct |
12 |
Correct |
65 ms |
2380 KB |
Output is correct |
13 |
Correct |
66 ms |
2380 KB |
Output is correct |
14 |
Correct |
66 ms |
2376 KB |
Output is correct |
15 |
Correct |
64 ms |
2464 KB |
Output is correct |
16 |
Correct |
63 ms |
2428 KB |
Output is correct |
17 |
Correct |
65 ms |
2360 KB |
Output is correct |
18 |
Correct |
63 ms |
2340 KB |
Output is correct |
19 |
Correct |
75 ms |
2540 KB |
Output is correct |
20 |
Correct |
73 ms |
2340 KB |
Output is correct |
21 |
Correct |
67 ms |
2356 KB |
Output is correct |
22 |
Correct |
58 ms |
2220 KB |
Output is correct |
23 |
Correct |
65 ms |
2372 KB |
Output is correct |
24 |
Correct |
64 ms |
2376 KB |
Output is correct |
25 |
Correct |
66 ms |
2400 KB |
Output is correct |
26 |
Correct |
65 ms |
2380 KB |
Output is correct |
27 |
Correct |
66 ms |
2400 KB |
Output is correct |
28 |
Correct |
58 ms |
2252 KB |
Output is correct |
29 |
Correct |
68 ms |
2432 KB |
Output is correct |
30 |
Correct |
57 ms |
2252 KB |
Output is correct |
31 |
Correct |
66 ms |
2388 KB |
Output is correct |
32 |
Correct |
65 ms |
2348 KB |
Output is correct |
33 |
Correct |
67 ms |
2380 KB |
Output is correct |
34 |
Correct |
65 ms |
2220 KB |
Output is correct |
35 |
Correct |
66 ms |
2376 KB |
Output is correct |
36 |
Correct |
68 ms |
2420 KB |
Output is correct |
37 |
Correct |
67 ms |
2468 KB |
Output is correct |
38 |
Correct |
70 ms |
2360 KB |
Output is correct |
39 |
Correct |
72 ms |
2488 KB |
Output is correct |
40 |
Correct |
68 ms |
2368 KB |
Output is correct |
41 |
Correct |
69 ms |
2356 KB |
Output is correct |
42 |
Correct |
69 ms |
2380 KB |
Output is correct |
43 |
Correct |
62 ms |
2312 KB |
Output is correct |
44 |
Correct |
69 ms |
2448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
68 ms |
2368 KB |
Output is correct |
2 |
Correct |
72 ms |
2408 KB |
Output is correct |
3 |
Correct |
69 ms |
2308 KB |
Output is correct |
4 |
Correct |
60 ms |
2384 KB |
Output is correct |
5 |
Correct |
61 ms |
2272 KB |
Output is correct |
6 |
Correct |
62 ms |
2288 KB |
Output is correct |
7 |
Correct |
62 ms |
2408 KB |
Output is correct |
8 |
Correct |
61 ms |
2436 KB |
Output is correct |
9 |
Correct |
62 ms |
2392 KB |
Output is correct |
10 |
Correct |
63 ms |
2380 KB |
Output is correct |
11 |
Correct |
64 ms |
2484 KB |
Output is correct |
12 |
Correct |
65 ms |
2380 KB |
Output is correct |
13 |
Correct |
66 ms |
2380 KB |
Output is correct |
14 |
Correct |
66 ms |
2376 KB |
Output is correct |
15 |
Correct |
64 ms |
2464 KB |
Output is correct |
16 |
Correct |
63 ms |
2428 KB |
Output is correct |
17 |
Correct |
65 ms |
2360 KB |
Output is correct |
18 |
Correct |
63 ms |
2340 KB |
Output is correct |
19 |
Correct |
204 ms |
14288 KB |
Output is correct |
20 |
Correct |
202 ms |
13892 KB |
Output is correct |
21 |
Correct |
145 ms |
13440 KB |
Output is correct |
22 |
Correct |
137 ms |
12844 KB |
Output is correct |
23 |
Correct |
96 ms |
3784 KB |
Output is correct |
24 |
Correct |
102 ms |
3808 KB |
Output is correct |
25 |
Correct |
151 ms |
14072 KB |
Output is correct |
26 |
Correct |
165 ms |
14040 KB |
Output is correct |
27 |
Correct |
168 ms |
14012 KB |
Output is correct |
28 |
Correct |
168 ms |
14004 KB |
Output is correct |
29 |
Correct |
170 ms |
13944 KB |
Output is correct |
30 |
Correct |
109 ms |
3800 KB |
Output is correct |
31 |
Correct |
165 ms |
14032 KB |
Output is correct |
32 |
Correct |
158 ms |
13464 KB |
Output is correct |
33 |
Correct |
104 ms |
3716 KB |
Output is correct |
34 |
Correct |
168 ms |
14080 KB |
Output is correct |
35 |
Correct |
130 ms |
12348 KB |
Output is correct |
36 |
Correct |
105 ms |
3752 KB |
Output is correct |
37 |
Correct |
98 ms |
3824 KB |
Output is correct |
38 |
Correct |
175 ms |
13820 KB |
Output is correct |
39 |
Correct |
128 ms |
14056 KB |
Output is correct |
40 |
Correct |
137 ms |
9796 KB |
Output is correct |
41 |
Correct |
213 ms |
14148 KB |
Output is correct |
42 |
Correct |
61 ms |
13436 KB |
Output is correct |
43 |
Correct |
75 ms |
2540 KB |
Output is correct |
44 |
Correct |
73 ms |
2340 KB |
Output is correct |
45 |
Correct |
67 ms |
2356 KB |
Output is correct |
46 |
Correct |
58 ms |
2220 KB |
Output is correct |
47 |
Correct |
65 ms |
2372 KB |
Output is correct |
48 |
Correct |
64 ms |
2376 KB |
Output is correct |
49 |
Correct |
66 ms |
2400 KB |
Output is correct |
50 |
Correct |
65 ms |
2380 KB |
Output is correct |
51 |
Correct |
66 ms |
2400 KB |
Output is correct |
52 |
Correct |
58 ms |
2252 KB |
Output is correct |
53 |
Correct |
68 ms |
2432 KB |
Output is correct |
54 |
Correct |
57 ms |
2252 KB |
Output is correct |
55 |
Correct |
66 ms |
2388 KB |
Output is correct |
56 |
Correct |
65 ms |
2348 KB |
Output is correct |
57 |
Correct |
67 ms |
2380 KB |
Output is correct |
58 |
Correct |
65 ms |
2220 KB |
Output is correct |
59 |
Correct |
66 ms |
2376 KB |
Output is correct |
60 |
Correct |
68 ms |
2420 KB |
Output is correct |
61 |
Correct |
67 ms |
2468 KB |
Output is correct |
62 |
Correct |
70 ms |
2360 KB |
Output is correct |
63 |
Correct |
72 ms |
2488 KB |
Output is correct |
64 |
Correct |
68 ms |
2368 KB |
Output is correct |
65 |
Correct |
69 ms |
2356 KB |
Output is correct |
66 |
Correct |
69 ms |
2380 KB |
Output is correct |
67 |
Correct |
62 ms |
2312 KB |
Output is correct |
68 |
Correct |
69 ms |
2448 KB |
Output is correct |
69 |
Correct |
197 ms |
12748 KB |
Output is correct |
70 |
Correct |
222 ms |
13948 KB |
Output is correct |
71 |
Correct |
105 ms |
3832 KB |
Output is correct |
72 |
Correct |
101 ms |
3872 KB |
Output is correct |
73 |
Correct |
117 ms |
3788 KB |
Output is correct |
74 |
Correct |
149 ms |
12772 KB |
Output is correct |
75 |
Correct |
100 ms |
3836 KB |
Output is correct |
76 |
Correct |
166 ms |
14016 KB |
Output is correct |
77 |
Correct |
160 ms |
12960 KB |
Output is correct |
78 |
Correct |
105 ms |
3892 KB |
Output is correct |
79 |
Correct |
102 ms |
3788 KB |
Output is correct |
80 |
Correct |
145 ms |
12084 KB |
Output is correct |
81 |
Correct |
102 ms |
3840 KB |
Output is correct |
82 |
Correct |
169 ms |
14156 KB |
Output is correct |
83 |
Correct |
158 ms |
13576 KB |
Output is correct |
84 |
Correct |
102 ms |
3788 KB |
Output is correct |
85 |
Correct |
103 ms |
3848 KB |
Output is correct |
86 |
Correct |
170 ms |
12468 KB |
Output is correct |
87 |
Correct |
172 ms |
14072 KB |
Output is correct |
88 |
Correct |
108 ms |
3776 KB |
Output is correct |
89 |
Correct |
168 ms |
13248 KB |
Output is correct |
90 |
Correct |
177 ms |
14060 KB |
Output is correct |
91 |
Correct |
112 ms |
3788 KB |
Output is correct |
92 |
Correct |
149 ms |
12388 KB |
Output is correct |
93 |
Correct |
103 ms |
3744 KB |
Output is correct |
94 |
Correct |
107 ms |
3820 KB |
Output is correct |
95 |
Correct |
103 ms |
3752 KB |
Output is correct |
96 |
Correct |
181 ms |
13896 KB |
Output is correct |
97 |
Correct |
134 ms |
14040 KB |
Output is correct |
98 |
Correct |
151 ms |
9752 KB |
Output is correct |
99 |
Correct |
222 ms |
14200 KB |
Output is correct |
100 |
Correct |
74 ms |
13432 KB |
Output is correct |