#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7, BASE = 5, MXN = 2e5+5;
ll Pow[MXN], Same[MXN];
ll getVal(char c) {
if (c == 'J') return 1;
if (c == 'O') return 2;
return 3;
}
char cross(char a, char b) {
if (a == b) return a;
if (a != 'O' && b != 'O') return 'O';
if (a != 'J' && b != 'J') return 'J';
return 'I';
}
string merge(string a, string b) {
string c(a.size(), ' ');
for (int i = 0; i<a.size(); ++i) {
c[i] = cross(a[i], b[i]);
}
return c;
}
vector<ll> starter;
struct Node {
ll l,r, mid,sz, set, hash;
Node *lp, *rp;
void blaSet(ll val) {
hash = val * Same[sz-1];
set = val;
}
void pull() {
hash = lp->hash * Pow[rp->sz] + rp->hash;
hash %= MOD;
}
void push() {
if (set != -1) {
lp->blaSet(set), rp->blaSet(set);
set = -1;
}
}
Node(ll l, ll r) : l(l), r(r), mid((l+r)/2), sz(r-l+1), set(-1) {
if (l != r) {
lp = new Node(l, mid), rp = new Node(mid+1,r);
pull();
}
else blaSet(starter[l]);
}
void update(int s, int e, ll val) {
if (s > r || e < l) return;
if (s <= l && e >= r) {
blaSet(val);
return;
}
push();
if (s <= mid) lp->update(s,e,val);
if (e > mid) rp->update(s,e,val);
pull();
}
};
void init() {
Pow[0] = 1; Same[0] = 1;
for (int i = 1; i<MXN; ++i) {
Pow[i] = (Pow[i-1] * BASE) % MOD;
Same[i] = (Same[i-1] * BASE + 1) % MOD;
}
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int n,q; cin >> n;
init();
vector<string> start(3);
set<string> s;
for (string &S :start) {
cin >> S;
s.insert(S);
}
/*for (int i = 0; i<3; ++i) for (int j = i+1; j<3; ++j) s.insert(merge(start[i], start[j]));
s.insert(merge(start[0], merge(start[2], start[1])));
s.insert(merge(start[1], merge(start[2], start[0])));
s.insert(merge(start[2], merge(start[1], start[0])));
*/
ll tot = 0;
for (int i = 0; i<n; ++i) tot = (tot*BASE + getVal(start[0][i])) % MOD;
cin >> q;
string seq; cin >> seq;
cout << (s.count(seq) ? "Yes" : "No") << '\n';
starter.resize(n);
for (int i = 0; i<n; ++i) starter[i] = getVal(seq[i]);
Node *seg = new Node(0, n-1);
while (q--) {
int l,r; char c;
cin >> l >> r >> c;
ll ne = getVal(c);
seg->update(l-1,r-1,ne);
cout << (seg->hash == tot ? "Yes" : "No") << '\n';
}
}
/*
* 7
OOOOOOO
OOOOOOO
OOOOOOO
4
OOOOOOO
*/
Compilation message
Main.cpp: In function 'std::string merge(std::string, std::string)':
Main.cpp:20:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | for (int i = 0; i<a.size(); ++i) {
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
3928 KB |
Output is correct |
2 |
Correct |
40 ms |
4180 KB |
Output is correct |
3 |
Correct |
38 ms |
4176 KB |
Output is correct |
4 |
Correct |
39 ms |
3924 KB |
Output is correct |
5 |
Correct |
35 ms |
4944 KB |
Output is correct |
6 |
Correct |
44 ms |
4936 KB |
Output is correct |
7 |
Correct |
37 ms |
5200 KB |
Output is correct |
8 |
Correct |
43 ms |
5000 KB |
Output is correct |
9 |
Correct |
40 ms |
5120 KB |
Output is correct |
10 |
Correct |
38 ms |
5200 KB |
Output is correct |
11 |
Correct |
41 ms |
5060 KB |
Output is correct |
12 |
Correct |
42 ms |
5080 KB |
Output is correct |
13 |
Correct |
41 ms |
5076 KB |
Output is correct |
14 |
Correct |
57 ms |
5084 KB |
Output is correct |
15 |
Correct |
40 ms |
5204 KB |
Output is correct |
16 |
Correct |
41 ms |
5012 KB |
Output is correct |
17 |
Correct |
41 ms |
5196 KB |
Output is correct |
18 |
Correct |
37 ms |
5192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
3928 KB |
Output is correct |
2 |
Correct |
40 ms |
4180 KB |
Output is correct |
3 |
Correct |
38 ms |
4176 KB |
Output is correct |
4 |
Correct |
39 ms |
3924 KB |
Output is correct |
5 |
Correct |
35 ms |
4944 KB |
Output is correct |
6 |
Correct |
44 ms |
4936 KB |
Output is correct |
7 |
Correct |
37 ms |
5200 KB |
Output is correct |
8 |
Correct |
43 ms |
5000 KB |
Output is correct |
9 |
Correct |
40 ms |
5120 KB |
Output is correct |
10 |
Correct |
38 ms |
5200 KB |
Output is correct |
11 |
Correct |
41 ms |
5060 KB |
Output is correct |
12 |
Correct |
42 ms |
5080 KB |
Output is correct |
13 |
Correct |
41 ms |
5076 KB |
Output is correct |
14 |
Correct |
57 ms |
5084 KB |
Output is correct |
15 |
Correct |
40 ms |
5204 KB |
Output is correct |
16 |
Correct |
41 ms |
5012 KB |
Output is correct |
17 |
Correct |
41 ms |
5196 KB |
Output is correct |
18 |
Correct |
37 ms |
5192 KB |
Output is correct |
19 |
Correct |
182 ms |
40248 KB |
Output is correct |
20 |
Correct |
141 ms |
40300 KB |
Output is correct |
21 |
Correct |
149 ms |
38184 KB |
Output is correct |
22 |
Correct |
118 ms |
34484 KB |
Output is correct |
23 |
Correct |
69 ms |
7320 KB |
Output is correct |
24 |
Correct |
68 ms |
7248 KB |
Output is correct |
25 |
Correct |
171 ms |
39840 KB |
Output is correct |
26 |
Correct |
141 ms |
40084 KB |
Output is correct |
27 |
Correct |
139 ms |
39844 KB |
Output is correct |
28 |
Correct |
169 ms |
39932 KB |
Output is correct |
29 |
Correct |
135 ms |
39060 KB |
Output is correct |
30 |
Correct |
76 ms |
7508 KB |
Output is correct |
31 |
Correct |
137 ms |
39952 KB |
Output is correct |
32 |
Correct |
139 ms |
36892 KB |
Output is correct |
33 |
Correct |
69 ms |
7260 KB |
Output is correct |
34 |
Correct |
157 ms |
40080 KB |
Output is correct |
35 |
Correct |
121 ms |
30908 KB |
Output is correct |
36 |
Correct |
68 ms |
7356 KB |
Output is correct |
37 |
Correct |
68 ms |
7188 KB |
Output is correct |
38 |
Correct |
144 ms |
40104 KB |
Output is correct |
39 |
Correct |
86 ms |
40000 KB |
Output is correct |
40 |
Correct |
123 ms |
28036 KB |
Output is correct |
41 |
Correct |
192 ms |
40236 KB |
Output is correct |
42 |
Correct |
46 ms |
40100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
3928 KB |
Output is correct |
2 |
Correct |
40 ms |
4180 KB |
Output is correct |
3 |
Correct |
38 ms |
4176 KB |
Output is correct |
4 |
Correct |
39 ms |
3924 KB |
Output is correct |
5 |
Correct |
35 ms |
4944 KB |
Output is correct |
6 |
Correct |
44 ms |
4936 KB |
Output is correct |
7 |
Correct |
37 ms |
5200 KB |
Output is correct |
8 |
Correct |
43 ms |
5000 KB |
Output is correct |
9 |
Correct |
40 ms |
5120 KB |
Output is correct |
10 |
Correct |
38 ms |
5200 KB |
Output is correct |
11 |
Correct |
41 ms |
5060 KB |
Output is correct |
12 |
Correct |
42 ms |
5080 KB |
Output is correct |
13 |
Correct |
41 ms |
5076 KB |
Output is correct |
14 |
Correct |
57 ms |
5084 KB |
Output is correct |
15 |
Correct |
40 ms |
5204 KB |
Output is correct |
16 |
Correct |
41 ms |
5012 KB |
Output is correct |
17 |
Correct |
41 ms |
5196 KB |
Output is correct |
18 |
Correct |
37 ms |
5192 KB |
Output is correct |
19 |
Correct |
40 ms |
5112 KB |
Output is correct |
20 |
Correct |
40 ms |
5012 KB |
Output is correct |
21 |
Incorrect |
37 ms |
5196 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
3928 KB |
Output is correct |
2 |
Correct |
40 ms |
4180 KB |
Output is correct |
3 |
Correct |
38 ms |
4176 KB |
Output is correct |
4 |
Correct |
39 ms |
3924 KB |
Output is correct |
5 |
Correct |
35 ms |
4944 KB |
Output is correct |
6 |
Correct |
44 ms |
4936 KB |
Output is correct |
7 |
Correct |
37 ms |
5200 KB |
Output is correct |
8 |
Correct |
43 ms |
5000 KB |
Output is correct |
9 |
Correct |
40 ms |
5120 KB |
Output is correct |
10 |
Correct |
38 ms |
5200 KB |
Output is correct |
11 |
Correct |
41 ms |
5060 KB |
Output is correct |
12 |
Correct |
42 ms |
5080 KB |
Output is correct |
13 |
Correct |
41 ms |
5076 KB |
Output is correct |
14 |
Correct |
57 ms |
5084 KB |
Output is correct |
15 |
Correct |
40 ms |
5204 KB |
Output is correct |
16 |
Correct |
41 ms |
5012 KB |
Output is correct |
17 |
Correct |
41 ms |
5196 KB |
Output is correct |
18 |
Correct |
37 ms |
5192 KB |
Output is correct |
19 |
Correct |
182 ms |
40248 KB |
Output is correct |
20 |
Correct |
141 ms |
40300 KB |
Output is correct |
21 |
Correct |
149 ms |
38184 KB |
Output is correct |
22 |
Correct |
118 ms |
34484 KB |
Output is correct |
23 |
Correct |
69 ms |
7320 KB |
Output is correct |
24 |
Correct |
68 ms |
7248 KB |
Output is correct |
25 |
Correct |
171 ms |
39840 KB |
Output is correct |
26 |
Correct |
141 ms |
40084 KB |
Output is correct |
27 |
Correct |
139 ms |
39844 KB |
Output is correct |
28 |
Correct |
169 ms |
39932 KB |
Output is correct |
29 |
Correct |
135 ms |
39060 KB |
Output is correct |
30 |
Correct |
76 ms |
7508 KB |
Output is correct |
31 |
Correct |
137 ms |
39952 KB |
Output is correct |
32 |
Correct |
139 ms |
36892 KB |
Output is correct |
33 |
Correct |
69 ms |
7260 KB |
Output is correct |
34 |
Correct |
157 ms |
40080 KB |
Output is correct |
35 |
Correct |
121 ms |
30908 KB |
Output is correct |
36 |
Correct |
68 ms |
7356 KB |
Output is correct |
37 |
Correct |
68 ms |
7188 KB |
Output is correct |
38 |
Correct |
144 ms |
40104 KB |
Output is correct |
39 |
Correct |
86 ms |
40000 KB |
Output is correct |
40 |
Correct |
123 ms |
28036 KB |
Output is correct |
41 |
Correct |
192 ms |
40236 KB |
Output is correct |
42 |
Correct |
46 ms |
40100 KB |
Output is correct |
43 |
Correct |
40 ms |
5112 KB |
Output is correct |
44 |
Correct |
40 ms |
5012 KB |
Output is correct |
45 |
Incorrect |
37 ms |
5196 KB |
Output isn't correct |
46 |
Halted |
0 ms |
0 KB |
- |