#ifndef Yamada
#define Yamada
#include Yamada __FILE__ Yamada
char JOI[] = {'J', 'O', 'I'};
vector<int> cross(vector<int> &g1, vector<int> &g2) {
vector<int> ret;
for (int i = 0; i < SZ(g1); ++i) {
int cur = 2 * (g1[i] + g2[i]) % 3;
ret.eb(cur);
}
return ret;
}
const int maxn = 2e5 + 5;
struct node {
int sc, tc, val, tag;
} seg[maxn * 4];
void build(int id, int l, int r, vector<int> &v, vector<int> &t) {
seg[id].sc = seg[id].tc = seg[id].tag = -1;
seg[id].val = 0;
if (l == r-1) {
seg[id].sc = v[l];
seg[id].tc = t[l];
seg[id].val = (v[l] == t[l]);
seg[id].tag = -1;
return;
}
int mid = l + r >> 1;
build(id * 2 + 1, l, mid, v, t);
build(id * 2 + 2, mid, r, v, t);
seg[id].sc = (seg[id * 2 + 1].sc == seg[id * 2 + 2].sc ? seg[id * 2 + 1].sc : -1);
seg[id].tc = (seg[id * 2 + 1].tc == seg[id * 2 + 2].tc ? seg[id * 2 + 1].tc : -1);
seg[id].val = seg[id * 2 + 1].val & seg[id * 2 + 2].val;
}
void push(int id) {
if (seg[id].tag == -1) return;
seg[id * 2 + 1].tag = seg[id].tag;
seg[id * 2 + 2].tag = seg[id].tag;
seg[id].tag = -1;
}
void ins(int id, int l, int r, int L, int R, int op) {
if (L <= l && R >= r) {
seg[id].tag = op;
seg[id].tc = op;
seg[id].val = (seg[id].tc == seg[id].sc);
return;
}
if (l >= R || r <= L) return;
int mid = l + r >> 1;
push(id);
ins(id * 2 + 1, l, mid, L, R, op);
ins(id * 2 + 2, mid, r, L, R, op);
int lc = (seg[id * 2 + 1].tag == -1 ? seg[id * 2 + 1].tc : seg[id * 2 + 1].tag);
int rc = (seg[id * 2 + 2].tag == -1 ? seg[id * 2 + 2].tc : seg[id * 2 + 2].tag);
int lval = (seg[id * 2 + 1].tag == -1 ? seg[id * 2 + 1].val : (seg[id * 2 + 1].tag == seg[id * 2 + 1].sc));
int rval = (seg[id * 2 + 2].tag == -1 ? seg[id * 2 + 2].val : (seg[id * 2 + 2].tag == seg[id * 2 + 2].sc));
seg[id].tc = (lc == rc ? lc : -1);
seg[id].val = lval & rval;
}
void solve() {
int n; cin >> n;
vector<int> gene[3];
for (int i = 0; i < 3; ++i) {
string s; cin >> s;
for (int j = 0; j < n; ++j) {
for (int k = 0; k < 3; ++k) {
if (s[j] == JOI[k]) gene[i].eb(k);
}
}
}
vector<vector<int>> G;
G.eb(gene[0]);
G.eb(gene[1]);
G.eb(gene[2]);
vector<int> t1 = cross(gene[0], gene[1]);
vector<int> t2 = cross(gene[0], gene[2]);
vector<int> t3 = cross(gene[1], gene[2]);
G.eb(t1);
G.eb(t2);
G.eb(t3);
G.eb(cross(t1, gene[2]));
G.eb(cross(t2, gene[1]));
G.eb(cross(t3, gene[0]));
int q; cin >> q;
string T; cin >> T;
vector<int> gt;
for (int i = 0; i < n; ++i) {
for (int k = 0; k < 3; ++k) {
if (T[i] == JOI[k]) gt.eb(k);
}
}
vector<pair<pii, int>> qr;
for (int i = 1; i <= q; ++i) {
int l, r;
cin >> l >> r;
--l;
char c; cin >> c;
int op = -1;
for (int k = 0; k < 3; ++k) if (c == JOI[k]) op = k;
qr.eb(pii(l, r), op);
}
vector<int> ans(q + 1);
auto cal = [&](vector<int> &v) -> void {
build(0, 0, n, v, gt);
ans[0] |= seg[0].val;
for (int i = 0; i < q; ++i){
int l = qr[i].X.X, r = qr[i].X.Y, op = qr[i].Y;
ins(0, 0, n, l, r, op);
ans[i+1] |= seg[0].val;
}
};
for (auto vec : G) {
cal(vec);
}
for (int i = 0; i <= q; ++i) {
if (ans[i]) print("Yes");
else print("No");
}
}
signed main() {
IOS();
int t = 1; // cin >> t;
for (int i=1;i<=t;++i) solve();
return 0;
}
#else
#ifdef local
#define _GLIBCXX_DEBUG 1
#endif
#pragma GCC optimize ("Ofast", "unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define double __float80
using pii = pair<int, int>;
template <typename T> using MaxHeap = std::priority_queue<T>;
template <typename T> using MinHeap = std::priority_queue<T, vector<T>, greater<T>>;
#define SZ(a) ((int)(a).size())
#define ALL(a) begin(a), end(a)
#define RALL(a) rbegin(a), rend(a)
#define ee emplace
#define eb emplace_back
#define ef emplace_front
#define pb pop_back
#define pf pop_front
#define X first
#define Y second
#ifdef local
#define IOS() void()
#define debug(...) \
fprintf(stderr, "\e[1;93m"), \
fprintf(stderr, "At [%s], line %d: (%s) = ", __FUNCTION__, __LINE__, #__VA_ARGS__), \
_do(__VA_ARGS__), \
fprintf(stderr, "\e[0m")
template <typename T> void _do(T &&_t) {cerr << _t << '\n';}
template <typename T, typename ...U> void _do(T &&_t, U &&..._u) {cerr << _t << ", ", _do(_u...);}
#define print(...) \
fprintf(stderr, "\e[1;96m"), \
_P(__VA_ARGS__), \
fprintf(stderr, "\e[0m")
#else
#define IOS() ios_base::sync_with_stdio(0); cin.tie(0)
#define debug(...) void()
#define print(...) _P(__VA_ARGS__)
#define endl '\n'
#endif
template <typename U, typename V> bool chmin(U &u, V v) {return u > v ? u = v, 1 : 0;}
template <typename U, typename V> bool chmax(U &u, V v) {return u < v ? u = v, 1 : 0;}
template <typename T> void _P(T &&_x) {cout << _x << '\n';}
template <typename T, typename ...S> void _P(T &&_x, S &&..._t) {cout << _x << " "; _P(_t...);}
#endif
Compilation message
Main.cpp: In function 'void build(int64_t, int64_t, int64_t, std::vector<long int>&, std::vector<long int>&)':
Main.cpp:32:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
32 | int mid = l + r >> 1;
| ~~^~~
Main.cpp: In function 'void ins(int64_t, int64_t, int64_t, int64_t, int64_t, int64_t)':
Main.cpp:55:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
55 | int mid = l + r >> 1;
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
215 ms |
9392 KB |
Output is correct |
2 |
Correct |
251 ms |
8652 KB |
Output is correct |
3 |
Correct |
200 ms |
9168 KB |
Output is correct |
4 |
Correct |
194 ms |
8976 KB |
Output is correct |
5 |
Correct |
188 ms |
9164 KB |
Output is correct |
6 |
Correct |
195 ms |
9528 KB |
Output is correct |
7 |
Correct |
193 ms |
9420 KB |
Output is correct |
8 |
Correct |
202 ms |
9912 KB |
Output is correct |
9 |
Correct |
208 ms |
8848 KB |
Output is correct |
10 |
Correct |
206 ms |
9272 KB |
Output is correct |
11 |
Correct |
211 ms |
8888 KB |
Output is correct |
12 |
Correct |
206 ms |
9152 KB |
Output is correct |
13 |
Correct |
216 ms |
8656 KB |
Output is correct |
14 |
Correct |
207 ms |
9732 KB |
Output is correct |
15 |
Correct |
213 ms |
9056 KB |
Output is correct |
16 |
Correct |
213 ms |
9936 KB |
Output is correct |
17 |
Correct |
212 ms |
9576 KB |
Output is correct |
18 |
Correct |
172 ms |
9164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
215 ms |
9392 KB |
Output is correct |
2 |
Correct |
251 ms |
8652 KB |
Output is correct |
3 |
Correct |
200 ms |
9168 KB |
Output is correct |
4 |
Correct |
194 ms |
8976 KB |
Output is correct |
5 |
Correct |
188 ms |
9164 KB |
Output is correct |
6 |
Correct |
195 ms |
9528 KB |
Output is correct |
7 |
Correct |
193 ms |
9420 KB |
Output is correct |
8 |
Correct |
202 ms |
9912 KB |
Output is correct |
9 |
Correct |
208 ms |
8848 KB |
Output is correct |
10 |
Correct |
206 ms |
9272 KB |
Output is correct |
11 |
Correct |
211 ms |
8888 KB |
Output is correct |
12 |
Correct |
206 ms |
9152 KB |
Output is correct |
13 |
Correct |
216 ms |
8656 KB |
Output is correct |
14 |
Correct |
207 ms |
9732 KB |
Output is correct |
15 |
Correct |
213 ms |
9056 KB |
Output is correct |
16 |
Correct |
213 ms |
9936 KB |
Output is correct |
17 |
Correct |
212 ms |
9576 KB |
Output is correct |
18 |
Correct |
172 ms |
9164 KB |
Output is correct |
19 |
Correct |
820 ms |
54568 KB |
Output is correct |
20 |
Correct |
752 ms |
52864 KB |
Output is correct |
21 |
Correct |
569 ms |
52032 KB |
Output is correct |
22 |
Correct |
564 ms |
49428 KB |
Output is correct |
23 |
Correct |
396 ms |
13816 KB |
Output is correct |
24 |
Correct |
389 ms |
13804 KB |
Output is correct |
25 |
Correct |
622 ms |
53376 KB |
Output is correct |
26 |
Correct |
635 ms |
53580 KB |
Output is correct |
27 |
Correct |
675 ms |
54412 KB |
Output is correct |
28 |
Correct |
708 ms |
53212 KB |
Output is correct |
29 |
Correct |
660 ms |
52352 KB |
Output is correct |
30 |
Correct |
442 ms |
13536 KB |
Output is correct |
31 |
Correct |
681 ms |
54684 KB |
Output is correct |
32 |
Correct |
676 ms |
51524 KB |
Output is correct |
33 |
Correct |
403 ms |
12476 KB |
Output is correct |
34 |
Correct |
686 ms |
54148 KB |
Output is correct |
35 |
Correct |
528 ms |
46280 KB |
Output is correct |
36 |
Correct |
400 ms |
13796 KB |
Output is correct |
37 |
Correct |
400 ms |
13296 KB |
Output is correct |
38 |
Correct |
610 ms |
53112 KB |
Output is correct |
39 |
Correct |
403 ms |
54400 KB |
Output is correct |
40 |
Correct |
518 ms |
36424 KB |
Output is correct |
41 |
Correct |
898 ms |
54404 KB |
Output is correct |
42 |
Correct |
76 ms |
53124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
215 ms |
9392 KB |
Output is correct |
2 |
Correct |
251 ms |
8652 KB |
Output is correct |
3 |
Correct |
200 ms |
9168 KB |
Output is correct |
4 |
Correct |
194 ms |
8976 KB |
Output is correct |
5 |
Correct |
188 ms |
9164 KB |
Output is correct |
6 |
Correct |
195 ms |
9528 KB |
Output is correct |
7 |
Correct |
193 ms |
9420 KB |
Output is correct |
8 |
Correct |
202 ms |
9912 KB |
Output is correct |
9 |
Correct |
208 ms |
8848 KB |
Output is correct |
10 |
Correct |
206 ms |
9272 KB |
Output is correct |
11 |
Correct |
211 ms |
8888 KB |
Output is correct |
12 |
Correct |
206 ms |
9152 KB |
Output is correct |
13 |
Correct |
216 ms |
8656 KB |
Output is correct |
14 |
Correct |
207 ms |
9732 KB |
Output is correct |
15 |
Correct |
213 ms |
9056 KB |
Output is correct |
16 |
Correct |
213 ms |
9936 KB |
Output is correct |
17 |
Correct |
212 ms |
9576 KB |
Output is correct |
18 |
Correct |
172 ms |
9164 KB |
Output is correct |
19 |
Correct |
244 ms |
8960 KB |
Output is correct |
20 |
Correct |
204 ms |
9164 KB |
Output is correct |
21 |
Correct |
206 ms |
9416 KB |
Output is correct |
22 |
Correct |
181 ms |
9164 KB |
Output is correct |
23 |
Correct |
205 ms |
9148 KB |
Output is correct |
24 |
Correct |
200 ms |
9136 KB |
Output is correct |
25 |
Correct |
208 ms |
9008 KB |
Output is correct |
26 |
Correct |
189 ms |
9140 KB |
Output is correct |
27 |
Correct |
206 ms |
8912 KB |
Output is correct |
28 |
Correct |
183 ms |
9404 KB |
Output is correct |
29 |
Correct |
211 ms |
9296 KB |
Output is correct |
30 |
Correct |
178 ms |
8628 KB |
Output is correct |
31 |
Correct |
205 ms |
9412 KB |
Output is correct |
32 |
Correct |
204 ms |
8908 KB |
Output is correct |
33 |
Correct |
215 ms |
9396 KB |
Output is correct |
34 |
Correct |
186 ms |
8648 KB |
Output is correct |
35 |
Correct |
206 ms |
9168 KB |
Output is correct |
36 |
Correct |
216 ms |
8912 KB |
Output is correct |
37 |
Correct |
206 ms |
9164 KB |
Output is correct |
38 |
Correct |
212 ms |
8896 KB |
Output is correct |
39 |
Correct |
206 ms |
8908 KB |
Output is correct |
40 |
Correct |
213 ms |
9260 KB |
Output is correct |
41 |
Correct |
208 ms |
9312 KB |
Output is correct |
42 |
Correct |
213 ms |
8628 KB |
Output is correct |
43 |
Correct |
209 ms |
9908 KB |
Output is correct |
44 |
Correct |
213 ms |
9152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
215 ms |
9392 KB |
Output is correct |
2 |
Correct |
251 ms |
8652 KB |
Output is correct |
3 |
Correct |
200 ms |
9168 KB |
Output is correct |
4 |
Correct |
194 ms |
8976 KB |
Output is correct |
5 |
Correct |
188 ms |
9164 KB |
Output is correct |
6 |
Correct |
195 ms |
9528 KB |
Output is correct |
7 |
Correct |
193 ms |
9420 KB |
Output is correct |
8 |
Correct |
202 ms |
9912 KB |
Output is correct |
9 |
Correct |
208 ms |
8848 KB |
Output is correct |
10 |
Correct |
206 ms |
9272 KB |
Output is correct |
11 |
Correct |
211 ms |
8888 KB |
Output is correct |
12 |
Correct |
206 ms |
9152 KB |
Output is correct |
13 |
Correct |
216 ms |
8656 KB |
Output is correct |
14 |
Correct |
207 ms |
9732 KB |
Output is correct |
15 |
Correct |
213 ms |
9056 KB |
Output is correct |
16 |
Correct |
213 ms |
9936 KB |
Output is correct |
17 |
Correct |
212 ms |
9576 KB |
Output is correct |
18 |
Correct |
172 ms |
9164 KB |
Output is correct |
19 |
Correct |
820 ms |
54568 KB |
Output is correct |
20 |
Correct |
752 ms |
52864 KB |
Output is correct |
21 |
Correct |
569 ms |
52032 KB |
Output is correct |
22 |
Correct |
564 ms |
49428 KB |
Output is correct |
23 |
Correct |
396 ms |
13816 KB |
Output is correct |
24 |
Correct |
389 ms |
13804 KB |
Output is correct |
25 |
Correct |
622 ms |
53376 KB |
Output is correct |
26 |
Correct |
635 ms |
53580 KB |
Output is correct |
27 |
Correct |
675 ms |
54412 KB |
Output is correct |
28 |
Correct |
708 ms |
53212 KB |
Output is correct |
29 |
Correct |
660 ms |
52352 KB |
Output is correct |
30 |
Correct |
442 ms |
13536 KB |
Output is correct |
31 |
Correct |
681 ms |
54684 KB |
Output is correct |
32 |
Correct |
676 ms |
51524 KB |
Output is correct |
33 |
Correct |
403 ms |
12476 KB |
Output is correct |
34 |
Correct |
686 ms |
54148 KB |
Output is correct |
35 |
Correct |
528 ms |
46280 KB |
Output is correct |
36 |
Correct |
400 ms |
13796 KB |
Output is correct |
37 |
Correct |
400 ms |
13296 KB |
Output is correct |
38 |
Correct |
610 ms |
53112 KB |
Output is correct |
39 |
Correct |
403 ms |
54400 KB |
Output is correct |
40 |
Correct |
518 ms |
36424 KB |
Output is correct |
41 |
Correct |
898 ms |
54404 KB |
Output is correct |
42 |
Correct |
76 ms |
53124 KB |
Output is correct |
43 |
Correct |
244 ms |
8960 KB |
Output is correct |
44 |
Correct |
204 ms |
9164 KB |
Output is correct |
45 |
Correct |
206 ms |
9416 KB |
Output is correct |
46 |
Correct |
181 ms |
9164 KB |
Output is correct |
47 |
Correct |
205 ms |
9148 KB |
Output is correct |
48 |
Correct |
200 ms |
9136 KB |
Output is correct |
49 |
Correct |
208 ms |
9008 KB |
Output is correct |
50 |
Correct |
189 ms |
9140 KB |
Output is correct |
51 |
Correct |
206 ms |
8912 KB |
Output is correct |
52 |
Correct |
183 ms |
9404 KB |
Output is correct |
53 |
Correct |
211 ms |
9296 KB |
Output is correct |
54 |
Correct |
178 ms |
8628 KB |
Output is correct |
55 |
Correct |
205 ms |
9412 KB |
Output is correct |
56 |
Correct |
204 ms |
8908 KB |
Output is correct |
57 |
Correct |
215 ms |
9396 KB |
Output is correct |
58 |
Correct |
186 ms |
8648 KB |
Output is correct |
59 |
Correct |
206 ms |
9168 KB |
Output is correct |
60 |
Correct |
216 ms |
8912 KB |
Output is correct |
61 |
Correct |
206 ms |
9164 KB |
Output is correct |
62 |
Correct |
212 ms |
8896 KB |
Output is correct |
63 |
Correct |
206 ms |
8908 KB |
Output is correct |
64 |
Correct |
213 ms |
9260 KB |
Output is correct |
65 |
Correct |
208 ms |
9312 KB |
Output is correct |
66 |
Correct |
213 ms |
8628 KB |
Output is correct |
67 |
Correct |
209 ms |
9908 KB |
Output is correct |
68 |
Correct |
213 ms |
9152 KB |
Output is correct |
69 |
Correct |
709 ms |
48844 KB |
Output is correct |
70 |
Correct |
757 ms |
53572 KB |
Output is correct |
71 |
Correct |
390 ms |
13112 KB |
Output is correct |
72 |
Correct |
400 ms |
12652 KB |
Output is correct |
73 |
Correct |
393 ms |
12856 KB |
Output is correct |
74 |
Correct |
566 ms |
48604 KB |
Output is correct |
75 |
Correct |
398 ms |
12796 KB |
Output is correct |
76 |
Correct |
599 ms |
53120 KB |
Output is correct |
77 |
Correct |
565 ms |
49356 KB |
Output is correct |
78 |
Correct |
392 ms |
12608 KB |
Output is correct |
79 |
Correct |
390 ms |
12816 KB |
Output is correct |
80 |
Correct |
535 ms |
44916 KB |
Output is correct |
81 |
Correct |
389 ms |
13908 KB |
Output is correct |
82 |
Correct |
607 ms |
54028 KB |
Output is correct |
83 |
Correct |
576 ms |
51448 KB |
Output is correct |
84 |
Correct |
395 ms |
12656 KB |
Output is correct |
85 |
Correct |
393 ms |
12584 KB |
Output is correct |
86 |
Correct |
659 ms |
47976 KB |
Output is correct |
87 |
Correct |
698 ms |
53272 KB |
Output is correct |
88 |
Correct |
443 ms |
13240 KB |
Output is correct |
89 |
Correct |
643 ms |
50068 KB |
Output is correct |
90 |
Correct |
683 ms |
54656 KB |
Output is correct |
91 |
Correct |
437 ms |
13896 KB |
Output is correct |
92 |
Correct |
531 ms |
47412 KB |
Output is correct |
93 |
Correct |
394 ms |
12540 KB |
Output is correct |
94 |
Correct |
392 ms |
13444 KB |
Output is correct |
95 |
Correct |
392 ms |
12600 KB |
Output is correct |
96 |
Correct |
613 ms |
53124 KB |
Output is correct |
97 |
Correct |
405 ms |
53304 KB |
Output is correct |
98 |
Correct |
506 ms |
37140 KB |
Output is correct |
99 |
Correct |
906 ms |
53440 KB |
Output is correct |
100 |
Correct |
86 ms |
54212 KB |
Output is correct |