//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,sse,sse2,sse3,ssse3,sse4,abm,popcnt,mmx")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef complex<double> cd;
constexpr ll INF64 = 9'000'000'000'000'000'000, INF32 = 2'000'000'000, MOD = 1'000'000'007, p = 57;
constexpr db PI = acos(-1);
constexpr bool IS_FILE = false, IS_TEST_CASES = false;
random_device rd;
mt19937 rnd32(rd());
mt19937_64 rnd64(rd());
template<typename T>
bool assign_max(T& a, T b) {
if (b > a) {
a = b;
return true;
}
return false;
}
template<typename T>
bool assign_min(T& a, T b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template<typename T>
T square(T a) {
return a * a;
}
template<>
struct std::hash<pair<ll, ll>> {
ll operator() (pair<ll, ll> p) const {
return ((__int128)p.first * MOD + p.second) % INF64;
}
};
map<pair<char, char>, char> m;
set<ll> can;
string make(string& s1, string& s2) {
string ans(s1.size(), '.');
for (ll i = 0; i < s1.size(); i++) {
ans[i] = m[make_pair(s1[i], s2[i])];
}
return ans;
}
ll calc(string& s) {
ll ans = 0, now = 1;
for (auto i : s) {
ans += (i - 'A') * now;
ans %= MOD;
now *= p;
now %= MOD;
}
return ans;
}
void rec(string& s, string& s1, string& s2, string& s3) {
can.insert(calc(s));
s = make(s, s1);
if (can.find(calc(s)) == can.end()) {
rec(s, s1, s2, s3);
}
s = make(s, s1);
s = make(s, s2);
if (can.find(calc(s)) == can.end()) {
rec(s, s1, s2, s3);
}
s = make(s, s2);
s = make(s, s3);
if (can.find(calc(s)) == can.end()) {
rec(s, s1, s2, s3);
}
s = make(s, s3);
}
vector<ll> pp, ppref;
struct segment_tree {
vector<ll> tree, m;
ll size;
segment_tree(ll n) {
size = 1;
while (size < n) {
size *= 2;
}
tree.resize(size * 2, 0);
m.resize(size * 2, -1);
}
void set(ll v, ll l, ll r, ll x) {
m[v] = x;
tree[v] = x * ppref[r - l] % MOD;
}
void push(ll v, ll l, ll r) {
if (m[v] == -1) {
return;
}
ll mid = (l + r) / 2;
set(v * 2, l, mid, m[v]);
set(v * 2 + 1, mid, r, m[v]);
m[v] = -1;
}
ll get() {
return tree[1];
}
void set(ll l, ll r, ll x) {
set(1, 0, size, l, r, x);
}
void set(ll v, ll l, ll r, ll ql, ll qr, ll x) {
if (ql <= l && r <= qr) {
set(v, l, r, x);
return;
}
if (qr <= l || r <= ql) {
return;
}
push(v, l, r);
ll mid = (l + r) / 2;
set(v * 2, l, mid, ql, qr, x);
set(v * 2 + 1, mid, r, ql, qr, x);
tree[v] = (tree[v * 2] + (tree[v * 2 + 1] * pp[mid - l])) % MOD;
}
};
void solve() {
m[make_pair('O', 'O')] = 'O';
m[make_pair('O', 'I')] = 'J';
m[make_pair('O', 'J')] = 'I';
m[make_pair('I', 'O')] = 'J';
m[make_pair('I', 'I')] = 'I';
m[make_pair('I', 'J')] = 'O';
m[make_pair('J', 'O')] = 'I';
m[make_pair('J', 'I')] = 'O';
m[make_pair('J', 'J')] = 'J';
ll n;
cin >> n;
pp.push_back(1);
while (pp.size() < n * 2) {
pp.push_back(pp.back() * p % MOD);
}
ppref.push_back(0);
for (auto i : pp) {
ppref.push_back((ppref.back() + i) % MOD);
}
string s1, s2, s3;
cin >> s1 >> s2 >> s3;
string s = s1;
rec(s, s1, s2, s3);
segment_tree st(n);
ll q;
cin >> q;
cin >> s;
for (ll i = 0; i < n; i++) {
st.set(i, i + 1, s[i] - 'A');
}
cout << (can.find(st.get()) == can.end() ? "No" : "Yes") << '\n';
for (ll i = 0; i < q; i++) {
ll l, r;
char c;
cin >> l >> r >> c;
l--;
st.set(l, r, c - 'A');
cout << (can.find(st.get()) == can.end() ? "No" : "Yes") << '\n';
}
}
int main() {
if (IS_FILE) {
freopen("", "r", stdin);
freopen("", "w", stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll t = 1;
if (IS_TEST_CASES) {
cin >> t;
}
for (ll i = 0; i < t; i++) {
solve();
}
}
Compilation message
Main.cpp: In function 'std::string make(std::string&, std::string&)':
Main.cpp:56:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for (ll i = 0; i < s1.size(); i++) {
| ~~^~~~~~~~~~~
Main.cpp: In function 'void solve()':
Main.cpp:153:26: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
153 | while (pp.size() < n * 2) {
| ~~~~~~~~~~^~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:184:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
184 | freopen("", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~
Main.cpp:185:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
185 | freopen("", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
848 KB |
Output is correct |
2 |
Correct |
55 ms |
860 KB |
Output is correct |
3 |
Correct |
57 ms |
964 KB |
Output is correct |
4 |
Correct |
50 ms |
988 KB |
Output is correct |
5 |
Correct |
49 ms |
856 KB |
Output is correct |
6 |
Correct |
49 ms |
860 KB |
Output is correct |
7 |
Correct |
53 ms |
852 KB |
Output is correct |
8 |
Correct |
50 ms |
856 KB |
Output is correct |
9 |
Correct |
55 ms |
852 KB |
Output is correct |
10 |
Correct |
51 ms |
852 KB |
Output is correct |
11 |
Correct |
55 ms |
852 KB |
Output is correct |
12 |
Correct |
59 ms |
1044 KB |
Output is correct |
13 |
Correct |
53 ms |
944 KB |
Output is correct |
14 |
Correct |
53 ms |
1112 KB |
Output is correct |
15 |
Correct |
51 ms |
960 KB |
Output is correct |
16 |
Correct |
53 ms |
828 KB |
Output is correct |
17 |
Correct |
51 ms |
856 KB |
Output is correct |
18 |
Correct |
54 ms |
848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
848 KB |
Output is correct |
2 |
Correct |
55 ms |
860 KB |
Output is correct |
3 |
Correct |
57 ms |
964 KB |
Output is correct |
4 |
Correct |
50 ms |
988 KB |
Output is correct |
5 |
Correct |
49 ms |
856 KB |
Output is correct |
6 |
Correct |
49 ms |
860 KB |
Output is correct |
7 |
Correct |
53 ms |
852 KB |
Output is correct |
8 |
Correct |
50 ms |
856 KB |
Output is correct |
9 |
Correct |
55 ms |
852 KB |
Output is correct |
10 |
Correct |
51 ms |
852 KB |
Output is correct |
11 |
Correct |
55 ms |
852 KB |
Output is correct |
12 |
Correct |
59 ms |
1044 KB |
Output is correct |
13 |
Correct |
53 ms |
944 KB |
Output is correct |
14 |
Correct |
53 ms |
1112 KB |
Output is correct |
15 |
Correct |
51 ms |
960 KB |
Output is correct |
16 |
Correct |
53 ms |
828 KB |
Output is correct |
17 |
Correct |
51 ms |
856 KB |
Output is correct |
18 |
Correct |
54 ms |
848 KB |
Output is correct |
19 |
Correct |
207 ms |
17564 KB |
Output is correct |
20 |
Correct |
218 ms |
18252 KB |
Output is correct |
21 |
Correct |
175 ms |
19708 KB |
Output is correct |
22 |
Correct |
159 ms |
19000 KB |
Output is correct |
23 |
Correct |
84 ms |
4180 KB |
Output is correct |
24 |
Correct |
93 ms |
4300 KB |
Output is correct |
25 |
Correct |
174 ms |
21564 KB |
Output is correct |
26 |
Correct |
178 ms |
20208 KB |
Output is correct |
27 |
Correct |
181 ms |
20212 KB |
Output is correct |
28 |
Correct |
204 ms |
22072 KB |
Output is correct |
29 |
Correct |
180 ms |
21820 KB |
Output is correct |
30 |
Correct |
100 ms |
4380 KB |
Output is correct |
31 |
Correct |
181 ms |
20220 KB |
Output is correct |
32 |
Correct |
175 ms |
19692 KB |
Output is correct |
33 |
Correct |
86 ms |
4336 KB |
Output is correct |
34 |
Correct |
187 ms |
20532 KB |
Output is correct |
35 |
Correct |
150 ms |
18488 KB |
Output is correct |
36 |
Correct |
87 ms |
4260 KB |
Output is correct |
37 |
Correct |
85 ms |
4180 KB |
Output is correct |
38 |
Correct |
192 ms |
20788 KB |
Output is correct |
39 |
Correct |
156 ms |
20472 KB |
Output is correct |
40 |
Correct |
139 ms |
15176 KB |
Output is correct |
41 |
Correct |
220 ms |
22332 KB |
Output is correct |
42 |
Correct |
125 ms |
20328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
848 KB |
Output is correct |
2 |
Correct |
55 ms |
860 KB |
Output is correct |
3 |
Correct |
57 ms |
964 KB |
Output is correct |
4 |
Correct |
50 ms |
988 KB |
Output is correct |
5 |
Correct |
49 ms |
856 KB |
Output is correct |
6 |
Correct |
49 ms |
860 KB |
Output is correct |
7 |
Correct |
53 ms |
852 KB |
Output is correct |
8 |
Correct |
50 ms |
856 KB |
Output is correct |
9 |
Correct |
55 ms |
852 KB |
Output is correct |
10 |
Correct |
51 ms |
852 KB |
Output is correct |
11 |
Correct |
55 ms |
852 KB |
Output is correct |
12 |
Correct |
59 ms |
1044 KB |
Output is correct |
13 |
Correct |
53 ms |
944 KB |
Output is correct |
14 |
Correct |
53 ms |
1112 KB |
Output is correct |
15 |
Correct |
51 ms |
960 KB |
Output is correct |
16 |
Correct |
53 ms |
828 KB |
Output is correct |
17 |
Correct |
51 ms |
856 KB |
Output is correct |
18 |
Correct |
54 ms |
848 KB |
Output is correct |
19 |
Correct |
57 ms |
872 KB |
Output is correct |
20 |
Correct |
61 ms |
1044 KB |
Output is correct |
21 |
Correct |
57 ms |
848 KB |
Output is correct |
22 |
Correct |
52 ms |
848 KB |
Output is correct |
23 |
Correct |
53 ms |
852 KB |
Output is correct |
24 |
Correct |
52 ms |
852 KB |
Output is correct |
25 |
Correct |
58 ms |
1056 KB |
Output is correct |
26 |
Correct |
51 ms |
852 KB |
Output is correct |
27 |
Correct |
53 ms |
836 KB |
Output is correct |
28 |
Correct |
48 ms |
852 KB |
Output is correct |
29 |
Correct |
53 ms |
848 KB |
Output is correct |
30 |
Correct |
49 ms |
996 KB |
Output is correct |
31 |
Correct |
54 ms |
848 KB |
Output is correct |
32 |
Correct |
55 ms |
860 KB |
Output is correct |
33 |
Correct |
55 ms |
852 KB |
Output is correct |
34 |
Correct |
50 ms |
780 KB |
Output is correct |
35 |
Correct |
54 ms |
848 KB |
Output is correct |
36 |
Correct |
54 ms |
1112 KB |
Output is correct |
37 |
Correct |
54 ms |
1040 KB |
Output is correct |
38 |
Correct |
56 ms |
848 KB |
Output is correct |
39 |
Correct |
55 ms |
856 KB |
Output is correct |
40 |
Correct |
56 ms |
848 KB |
Output is correct |
41 |
Correct |
54 ms |
848 KB |
Output is correct |
42 |
Correct |
55 ms |
932 KB |
Output is correct |
43 |
Correct |
54 ms |
860 KB |
Output is correct |
44 |
Correct |
55 ms |
848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
848 KB |
Output is correct |
2 |
Correct |
55 ms |
860 KB |
Output is correct |
3 |
Correct |
57 ms |
964 KB |
Output is correct |
4 |
Correct |
50 ms |
988 KB |
Output is correct |
5 |
Correct |
49 ms |
856 KB |
Output is correct |
6 |
Correct |
49 ms |
860 KB |
Output is correct |
7 |
Correct |
53 ms |
852 KB |
Output is correct |
8 |
Correct |
50 ms |
856 KB |
Output is correct |
9 |
Correct |
55 ms |
852 KB |
Output is correct |
10 |
Correct |
51 ms |
852 KB |
Output is correct |
11 |
Correct |
55 ms |
852 KB |
Output is correct |
12 |
Correct |
59 ms |
1044 KB |
Output is correct |
13 |
Correct |
53 ms |
944 KB |
Output is correct |
14 |
Correct |
53 ms |
1112 KB |
Output is correct |
15 |
Correct |
51 ms |
960 KB |
Output is correct |
16 |
Correct |
53 ms |
828 KB |
Output is correct |
17 |
Correct |
51 ms |
856 KB |
Output is correct |
18 |
Correct |
54 ms |
848 KB |
Output is correct |
19 |
Correct |
207 ms |
17564 KB |
Output is correct |
20 |
Correct |
218 ms |
18252 KB |
Output is correct |
21 |
Correct |
175 ms |
19708 KB |
Output is correct |
22 |
Correct |
159 ms |
19000 KB |
Output is correct |
23 |
Correct |
84 ms |
4180 KB |
Output is correct |
24 |
Correct |
93 ms |
4300 KB |
Output is correct |
25 |
Correct |
174 ms |
21564 KB |
Output is correct |
26 |
Correct |
178 ms |
20208 KB |
Output is correct |
27 |
Correct |
181 ms |
20212 KB |
Output is correct |
28 |
Correct |
204 ms |
22072 KB |
Output is correct |
29 |
Correct |
180 ms |
21820 KB |
Output is correct |
30 |
Correct |
100 ms |
4380 KB |
Output is correct |
31 |
Correct |
181 ms |
20220 KB |
Output is correct |
32 |
Correct |
175 ms |
19692 KB |
Output is correct |
33 |
Correct |
86 ms |
4336 KB |
Output is correct |
34 |
Correct |
187 ms |
20532 KB |
Output is correct |
35 |
Correct |
150 ms |
18488 KB |
Output is correct |
36 |
Correct |
87 ms |
4260 KB |
Output is correct |
37 |
Correct |
85 ms |
4180 KB |
Output is correct |
38 |
Correct |
192 ms |
20788 KB |
Output is correct |
39 |
Correct |
156 ms |
20472 KB |
Output is correct |
40 |
Correct |
139 ms |
15176 KB |
Output is correct |
41 |
Correct |
220 ms |
22332 KB |
Output is correct |
42 |
Correct |
125 ms |
20328 KB |
Output is correct |
43 |
Correct |
57 ms |
872 KB |
Output is correct |
44 |
Correct |
61 ms |
1044 KB |
Output is correct |
45 |
Correct |
57 ms |
848 KB |
Output is correct |
46 |
Correct |
52 ms |
848 KB |
Output is correct |
47 |
Correct |
53 ms |
852 KB |
Output is correct |
48 |
Correct |
52 ms |
852 KB |
Output is correct |
49 |
Correct |
58 ms |
1056 KB |
Output is correct |
50 |
Correct |
51 ms |
852 KB |
Output is correct |
51 |
Correct |
53 ms |
836 KB |
Output is correct |
52 |
Correct |
48 ms |
852 KB |
Output is correct |
53 |
Correct |
53 ms |
848 KB |
Output is correct |
54 |
Correct |
49 ms |
996 KB |
Output is correct |
55 |
Correct |
54 ms |
848 KB |
Output is correct |
56 |
Correct |
55 ms |
860 KB |
Output is correct |
57 |
Correct |
55 ms |
852 KB |
Output is correct |
58 |
Correct |
50 ms |
780 KB |
Output is correct |
59 |
Correct |
54 ms |
848 KB |
Output is correct |
60 |
Correct |
54 ms |
1112 KB |
Output is correct |
61 |
Correct |
54 ms |
1040 KB |
Output is correct |
62 |
Correct |
56 ms |
848 KB |
Output is correct |
63 |
Correct |
55 ms |
856 KB |
Output is correct |
64 |
Correct |
56 ms |
848 KB |
Output is correct |
65 |
Correct |
54 ms |
848 KB |
Output is correct |
66 |
Correct |
55 ms |
932 KB |
Output is correct |
67 |
Correct |
54 ms |
860 KB |
Output is correct |
68 |
Correct |
55 ms |
848 KB |
Output is correct |
69 |
Correct |
354 ms |
19420 KB |
Output is correct |
70 |
Correct |
416 ms |
21300 KB |
Output is correct |
71 |
Correct |
97 ms |
4268 KB |
Output is correct |
72 |
Correct |
88 ms |
4184 KB |
Output is correct |
73 |
Correct |
89 ms |
4180 KB |
Output is correct |
74 |
Correct |
198 ms |
18748 KB |
Output is correct |
75 |
Correct |
91 ms |
4164 KB |
Output is correct |
76 |
Correct |
225 ms |
21408 KB |
Output is correct |
77 |
Correct |
203 ms |
21592 KB |
Output is correct |
78 |
Correct |
100 ms |
4296 KB |
Output is correct |
79 |
Correct |
88 ms |
4180 KB |
Output is correct |
80 |
Correct |
288 ms |
19260 KB |
Output is correct |
81 |
Correct |
102 ms |
4444 KB |
Output is correct |
82 |
Correct |
377 ms |
20532 KB |
Output is correct |
83 |
Correct |
357 ms |
19916 KB |
Output is correct |
84 |
Correct |
97 ms |
4336 KB |
Output is correct |
85 |
Correct |
96 ms |
4196 KB |
Output is correct |
86 |
Correct |
237 ms |
19840 KB |
Output is correct |
87 |
Correct |
272 ms |
21824 KB |
Output is correct |
88 |
Correct |
98 ms |
4276 KB |
Output is correct |
89 |
Correct |
264 ms |
18968 KB |
Output is correct |
90 |
Incorrect |
277 ms |
21440 KB |
Output isn't correct |
91 |
Halted |
0 ms |
0 KB |
- |