/*
DavitMarg
In a honky-tonk,
Down in Mexico
*/
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <random>
#include <chrono>
#define mod 998244353ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
#define fastIO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
const int N = 500005;
string crossing(string a, string b)
{
string s = a;
for (int i = 0; i < a.length(); i++)
{
if (a[i] == b[i])
continue;
s[i] = '0' + ((a[i] - '0') ^ (b[i] - '0'));
}
return s;
}
string norm(string s)
{
for (int i = 0; i < s.length(); i++)
{
if (s[i] == 'J')
s[i] = '1';
else if(s[i] == 'O')
s[i] = '2';
else
s[i] = '3';
}
return s;
}
int n, q;
string s[N];
map<LL, bool> used;
LL prime = 271;
LL e[N], pr[5][N];
void hashInit()
{
e[0] = 1;
for(int i = 1; i <= n; i++)
e[i] = (e[i - 1] * prime) % mod;
for (int i = 0; i <= n; i++)
{
for (int j = 1; j <= 3; j++)
{
pr[j][i] = (j * e[i]) % mod;
if(i)
pr[j][i] = (pr[j][i] + pr[j][i - 1]) % mod;
}
}
}
LL getHash(string s)
{
LL h = 0;
for(int i = 0; i < s.length(); i++)
h = (h + (LL)(s[i] - '0') * e[i]) % mod;
return h;
}
LL t[4 * N];
char d[4 * N];
void build(int v, int l, int r)
{
d[v] = '0';
if (l == r)
{
t[v] = (LL)(s[0][l] - '0') * e[l];
t[v] %= mod;
return;
}
int mid = (l + r) / 2;
build(2 * v, l, mid);
build(2 * v + 1, mid + 1, r);
t[v] = (t[2 * v] + t[2 * v + 1]) % mod;
}
void push(int v, int l, int r)
{
if(d[v] == '0')
return;
if (l != r)
{
d[v * 2] = d[v];
d[v * 2 + 1] = d[v];
}
t[v] = (pr[d[v] - '0'][r] - pr[d[v] - '0'][l - 1] + mod) % mod;
d[v] = '0';
}
LL get(int v, int l, int r, int i, int j)
{
push(v, l, r);
if(i > j)
return 0;
if (l == i && r == j)
return t[v];
int mid = (l + r) / 2;
LL res = (
get(2 * v, l, mid, i, min(j, mid)) +
get(2 * v + 1, mid + 1, r, max(i, mid + 1), j)) % mod;
return res;
}
void upd(int v, int l, int r, int i, int j, char val)
{
push(v, l, r);
if (i > j)
return;
if (l == i && r == j)
{
d[v] = val;
push(v, l, r);
return;
}
int mid = (l + r) / 2;
upd(2 * v, l, mid, i, min(j, mid), val);
upd(2 * v + 1, mid + 1, r, max(i, mid + 1), j, val);
t[v] = (t[2 * v] + t[2 * v + 1]) % mod;
}
void solve()
{
cin >> n;
cin >> s[1] >> s[2] >> s[3];
s[1] = norm(s[1]);
s[2] = norm(s[2]);
s[3] = norm(s[3]);
hashInit();
for (int i = 1; i <= 3; i++)
for (int j = 1; j <= 3; j++)
for (int k = 1; k <= 3; k++)
used[getHash(crossing(crossing(s[i], s[j]), s[k]))] = 1;
cin >> q;
cin >> s[0];
s[0] = norm(s[0]);
build(1, 0, n - 1);
if (used[t[1]])
cout << "Yes\n";
else
cout << "No\n";
for (int i = 1; i <= q; i++)
{
int l, r;
char c;
cin >> l >> r >> c;
if(c == 'J')
c = '1';
else if(c == 'O')
c = '2';
else
c = '3';
upd(1, 0, n - 1, l - 1, r - 1, c);
if (used[t[1]])
cout << "Yes\n";
else
cout << "No\n";
}
}
int main()
{
fastIO;
int T = 1;
//cin >> T;
while (T--)
{
solve();
}
return 0;
}
/*
*/
Compilation message
Main.cpp: In function 'std::string crossing(std::string, std::string)':
Main.cpp:39:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for (int i = 0; i < a.length(); i++)
| ~~^~~~~~~~~~~~
Main.cpp: In function 'std::string norm(std::string)':
Main.cpp:50:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for (int i = 0; i < s.length(); i++)
| ~~^~~~~~~~~~~~
Main.cpp: In function 'long long int getHash(std::string)':
Main.cpp:90:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
90 | for(int i = 0; i < s.length(); i++)
| ~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
112 ms |
25928 KB |
Output is correct |
2 |
Correct |
138 ms |
26812 KB |
Output is correct |
3 |
Correct |
117 ms |
20216 KB |
Output is correct |
4 |
Correct |
146 ms |
26756 KB |
Output is correct |
5 |
Correct |
136 ms |
26864 KB |
Output is correct |
6 |
Correct |
137 ms |
26024 KB |
Output is correct |
7 |
Correct |
146 ms |
26332 KB |
Output is correct |
8 |
Correct |
174 ms |
27116 KB |
Output is correct |
9 |
Correct |
144 ms |
26744 KB |
Output is correct |
10 |
Correct |
168 ms |
28108 KB |
Output is correct |
11 |
Correct |
156 ms |
27320 KB |
Output is correct |
12 |
Correct |
179 ms |
28064 KB |
Output is correct |
13 |
Correct |
190 ms |
27424 KB |
Output is correct |
14 |
Correct |
208 ms |
28196 KB |
Output is correct |
15 |
Correct |
164 ms |
27316 KB |
Output is correct |
16 |
Correct |
145 ms |
28108 KB |
Output is correct |
17 |
Correct |
165 ms |
27436 KB |
Output is correct |
18 |
Correct |
114 ms |
18480 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
112 ms |
25928 KB |
Output is correct |
2 |
Correct |
138 ms |
26812 KB |
Output is correct |
3 |
Correct |
117 ms |
20216 KB |
Output is correct |
4 |
Correct |
146 ms |
26756 KB |
Output is correct |
5 |
Correct |
136 ms |
26864 KB |
Output is correct |
6 |
Correct |
137 ms |
26024 KB |
Output is correct |
7 |
Correct |
146 ms |
26332 KB |
Output is correct |
8 |
Correct |
174 ms |
27116 KB |
Output is correct |
9 |
Correct |
144 ms |
26744 KB |
Output is correct |
10 |
Correct |
168 ms |
28108 KB |
Output is correct |
11 |
Correct |
156 ms |
27320 KB |
Output is correct |
12 |
Correct |
179 ms |
28064 KB |
Output is correct |
13 |
Correct |
190 ms |
27424 KB |
Output is correct |
14 |
Correct |
208 ms |
28196 KB |
Output is correct |
15 |
Correct |
164 ms |
27316 KB |
Output is correct |
16 |
Correct |
145 ms |
28108 KB |
Output is correct |
17 |
Correct |
165 ms |
27436 KB |
Output is correct |
18 |
Correct |
114 ms |
18480 KB |
Output is correct |
19 |
Correct |
506 ms |
37992 KB |
Output is correct |
20 |
Correct |
433 ms |
38684 KB |
Output is correct |
21 |
Correct |
323 ms |
39204 KB |
Output is correct |
22 |
Correct |
228 ms |
36452 KB |
Output is correct |
23 |
Correct |
171 ms |
29656 KB |
Output is correct |
24 |
Correct |
218 ms |
28444 KB |
Output is correct |
25 |
Correct |
334 ms |
40356 KB |
Output is correct |
26 |
Correct |
375 ms |
38428 KB |
Output is correct |
27 |
Correct |
314 ms |
40744 KB |
Output is correct |
28 |
Correct |
349 ms |
38324 KB |
Output is correct |
29 |
Correct |
276 ms |
40256 KB |
Output is correct |
30 |
Correct |
199 ms |
29644 KB |
Output is correct |
31 |
Correct |
301 ms |
40708 KB |
Output is correct |
32 |
Correct |
286 ms |
37492 KB |
Output is correct |
33 |
Correct |
169 ms |
28348 KB |
Output is correct |
34 |
Correct |
283 ms |
38348 KB |
Output is correct |
35 |
Correct |
285 ms |
36752 KB |
Output is correct |
36 |
Correct |
162 ms |
28428 KB |
Output is correct |
37 |
Correct |
160 ms |
28376 KB |
Output is correct |
38 |
Correct |
244 ms |
36120 KB |
Output is correct |
39 |
Correct |
188 ms |
34616 KB |
Output is correct |
40 |
Correct |
238 ms |
33936 KB |
Output is correct |
41 |
Correct |
219 ms |
29264 KB |
Output is correct |
42 |
Correct |
73 ms |
29216 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
112 ms |
25928 KB |
Output is correct |
2 |
Correct |
138 ms |
26812 KB |
Output is correct |
3 |
Correct |
117 ms |
20216 KB |
Output is correct |
4 |
Correct |
146 ms |
26756 KB |
Output is correct |
5 |
Correct |
136 ms |
26864 KB |
Output is correct |
6 |
Correct |
137 ms |
26024 KB |
Output is correct |
7 |
Correct |
146 ms |
26332 KB |
Output is correct |
8 |
Correct |
174 ms |
27116 KB |
Output is correct |
9 |
Correct |
144 ms |
26744 KB |
Output is correct |
10 |
Correct |
168 ms |
28108 KB |
Output is correct |
11 |
Correct |
156 ms |
27320 KB |
Output is correct |
12 |
Correct |
179 ms |
28064 KB |
Output is correct |
13 |
Correct |
190 ms |
27424 KB |
Output is correct |
14 |
Correct |
208 ms |
28196 KB |
Output is correct |
15 |
Correct |
164 ms |
27316 KB |
Output is correct |
16 |
Correct |
145 ms |
28108 KB |
Output is correct |
17 |
Correct |
165 ms |
27436 KB |
Output is correct |
18 |
Correct |
114 ms |
18480 KB |
Output is correct |
19 |
Correct |
119 ms |
26188 KB |
Output is correct |
20 |
Correct |
103 ms |
20212 KB |
Output is correct |
21 |
Correct |
132 ms |
27480 KB |
Output is correct |
22 |
Correct |
118 ms |
25584 KB |
Output is correct |
23 |
Correct |
152 ms |
27600 KB |
Output is correct |
24 |
Correct |
117 ms |
26444 KB |
Output is correct |
25 |
Correct |
130 ms |
27500 KB |
Output is correct |
26 |
Correct |
118 ms |
26140 KB |
Output is correct |
27 |
Correct |
128 ms |
27536 KB |
Output is correct |
28 |
Correct |
117 ms |
26452 KB |
Output is correct |
29 |
Correct |
122 ms |
26868 KB |
Output is correct |
30 |
Correct |
140 ms |
25960 KB |
Output is correct |
31 |
Correct |
130 ms |
27756 KB |
Output is correct |
32 |
Correct |
133 ms |
27596 KB |
Output is correct |
33 |
Correct |
123 ms |
27172 KB |
Output is correct |
34 |
Correct |
112 ms |
26244 KB |
Output is correct |
35 |
Correct |
143 ms |
28144 KB |
Output is correct |
36 |
Correct |
124 ms |
27344 KB |
Output is correct |
37 |
Correct |
141 ms |
28172 KB |
Output is correct |
38 |
Correct |
129 ms |
27392 KB |
Output is correct |
39 |
Correct |
130 ms |
28108 KB |
Output is correct |
40 |
Correct |
136 ms |
27372 KB |
Output is correct |
41 |
Correct |
144 ms |
28088 KB |
Output is correct |
42 |
Correct |
126 ms |
27416 KB |
Output is correct |
43 |
Correct |
117 ms |
26708 KB |
Output is correct |
44 |
Correct |
128 ms |
27140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
112 ms |
25928 KB |
Output is correct |
2 |
Correct |
138 ms |
26812 KB |
Output is correct |
3 |
Correct |
117 ms |
20216 KB |
Output is correct |
4 |
Correct |
146 ms |
26756 KB |
Output is correct |
5 |
Correct |
136 ms |
26864 KB |
Output is correct |
6 |
Correct |
137 ms |
26024 KB |
Output is correct |
7 |
Correct |
146 ms |
26332 KB |
Output is correct |
8 |
Correct |
174 ms |
27116 KB |
Output is correct |
9 |
Correct |
144 ms |
26744 KB |
Output is correct |
10 |
Correct |
168 ms |
28108 KB |
Output is correct |
11 |
Correct |
156 ms |
27320 KB |
Output is correct |
12 |
Correct |
179 ms |
28064 KB |
Output is correct |
13 |
Correct |
190 ms |
27424 KB |
Output is correct |
14 |
Correct |
208 ms |
28196 KB |
Output is correct |
15 |
Correct |
164 ms |
27316 KB |
Output is correct |
16 |
Correct |
145 ms |
28108 KB |
Output is correct |
17 |
Correct |
165 ms |
27436 KB |
Output is correct |
18 |
Correct |
114 ms |
18480 KB |
Output is correct |
19 |
Correct |
506 ms |
37992 KB |
Output is correct |
20 |
Correct |
433 ms |
38684 KB |
Output is correct |
21 |
Correct |
323 ms |
39204 KB |
Output is correct |
22 |
Correct |
228 ms |
36452 KB |
Output is correct |
23 |
Correct |
171 ms |
29656 KB |
Output is correct |
24 |
Correct |
218 ms |
28444 KB |
Output is correct |
25 |
Correct |
334 ms |
40356 KB |
Output is correct |
26 |
Correct |
375 ms |
38428 KB |
Output is correct |
27 |
Correct |
314 ms |
40744 KB |
Output is correct |
28 |
Correct |
349 ms |
38324 KB |
Output is correct |
29 |
Correct |
276 ms |
40256 KB |
Output is correct |
30 |
Correct |
199 ms |
29644 KB |
Output is correct |
31 |
Correct |
301 ms |
40708 KB |
Output is correct |
32 |
Correct |
286 ms |
37492 KB |
Output is correct |
33 |
Correct |
169 ms |
28348 KB |
Output is correct |
34 |
Correct |
283 ms |
38348 KB |
Output is correct |
35 |
Correct |
285 ms |
36752 KB |
Output is correct |
36 |
Correct |
162 ms |
28428 KB |
Output is correct |
37 |
Correct |
160 ms |
28376 KB |
Output is correct |
38 |
Correct |
244 ms |
36120 KB |
Output is correct |
39 |
Correct |
188 ms |
34616 KB |
Output is correct |
40 |
Correct |
238 ms |
33936 KB |
Output is correct |
41 |
Correct |
219 ms |
29264 KB |
Output is correct |
42 |
Correct |
73 ms |
29216 KB |
Output is correct |
43 |
Correct |
119 ms |
26188 KB |
Output is correct |
44 |
Correct |
103 ms |
20212 KB |
Output is correct |
45 |
Correct |
132 ms |
27480 KB |
Output is correct |
46 |
Correct |
118 ms |
25584 KB |
Output is correct |
47 |
Correct |
152 ms |
27600 KB |
Output is correct |
48 |
Correct |
117 ms |
26444 KB |
Output is correct |
49 |
Correct |
130 ms |
27500 KB |
Output is correct |
50 |
Correct |
118 ms |
26140 KB |
Output is correct |
51 |
Correct |
128 ms |
27536 KB |
Output is correct |
52 |
Correct |
117 ms |
26452 KB |
Output is correct |
53 |
Correct |
122 ms |
26868 KB |
Output is correct |
54 |
Correct |
140 ms |
25960 KB |
Output is correct |
55 |
Correct |
130 ms |
27756 KB |
Output is correct |
56 |
Correct |
133 ms |
27596 KB |
Output is correct |
57 |
Correct |
123 ms |
27172 KB |
Output is correct |
58 |
Correct |
112 ms |
26244 KB |
Output is correct |
59 |
Correct |
143 ms |
28144 KB |
Output is correct |
60 |
Correct |
124 ms |
27344 KB |
Output is correct |
61 |
Correct |
141 ms |
28172 KB |
Output is correct |
62 |
Correct |
129 ms |
27392 KB |
Output is correct |
63 |
Correct |
130 ms |
28108 KB |
Output is correct |
64 |
Correct |
136 ms |
27372 KB |
Output is correct |
65 |
Correct |
144 ms |
28088 KB |
Output is correct |
66 |
Correct |
126 ms |
27416 KB |
Output is correct |
67 |
Correct |
117 ms |
26708 KB |
Output is correct |
68 |
Correct |
128 ms |
27140 KB |
Output is correct |
69 |
Correct |
318 ms |
35856 KB |
Output is correct |
70 |
Correct |
322 ms |
38816 KB |
Output is correct |
71 |
Correct |
164 ms |
28548 KB |
Output is correct |
72 |
Correct |
177 ms |
28508 KB |
Output is correct |
73 |
Correct |
160 ms |
28488 KB |
Output is correct |
74 |
Correct |
272 ms |
37852 KB |
Output is correct |
75 |
Correct |
202 ms |
29676 KB |
Output is correct |
76 |
Correct |
378 ms |
40396 KB |
Output is correct |
77 |
Correct |
262 ms |
36632 KB |
Output is correct |
78 |
Correct |
166 ms |
28456 KB |
Output is correct |
79 |
Correct |
181 ms |
28564 KB |
Output is correct |
80 |
Correct |
284 ms |
36736 KB |
Output is correct |
81 |
Correct |
194 ms |
29772 KB |
Output is correct |
82 |
Correct |
347 ms |
40388 KB |
Output is correct |
83 |
Correct |
273 ms |
37644 KB |
Output is correct |
84 |
Correct |
171 ms |
28600 KB |
Output is correct |
85 |
Correct |
183 ms |
28924 KB |
Output is correct |
86 |
Correct |
305 ms |
36876 KB |
Output is correct |
87 |
Correct |
330 ms |
39316 KB |
Output is correct |
88 |
Correct |
223 ms |
28620 KB |
Output is correct |
89 |
Correct |
249 ms |
37144 KB |
Output is correct |
90 |
Correct |
304 ms |
39568 KB |
Output is correct |
91 |
Correct |
184 ms |
28760 KB |
Output is correct |
92 |
Correct |
251 ms |
37644 KB |
Output is correct |
93 |
Correct |
166 ms |
29308 KB |
Output is correct |
94 |
Correct |
173 ms |
29424 KB |
Output is correct |
95 |
Correct |
165 ms |
29348 KB |
Output is correct |
96 |
Correct |
256 ms |
36900 KB |
Output is correct |
97 |
Correct |
190 ms |
36880 KB |
Output is correct |
98 |
Correct |
260 ms |
34912 KB |
Output is correct |
99 |
Correct |
276 ms |
30076 KB |
Output is correct |
100 |
Correct |
98 ms |
30048 KB |
Output is correct |