#include <bits/stdc++.h>
#define se second
#define fs first
#define mp make_pair
#define pb push_back
#define ll long long
#define ii pair<ll,ll>
#define ld long double
#define SZ(v) (int)v.size()
#define ALL(v) v.begin(), v.end()
#define bit(msk, i) ((msk >> i) & 1)
#define iter(id, v) for(auto id : v)
#define rep(i,m,n) for(int i=(m); i<=(n); i++)
#define reb(i,m,n) for(int i=(m); i>=(n); i--)
using namespace std;
mt19937_64 rd(chrono :: steady_clock :: now().time_since_epoch().count());
ll Rand(ll l, ll r) { return uniform_int_distribution<ll> (l, r)(rd); }
const int N = 1e6 + 7;
const ll Mod = 1e9 + 7;
const int szBL = 916;
const ll INF = 1e9;
const int BASE = 293;
int n, Q;
string T;
ll pw[N], hs[30][N];
struct Segment_Tree {
int Range;
ll st[N << 2], lz[N << 2];
void init (int n) {
Range = n;
rep (i, 1, n << 2) lz[i] = -1;
}
void build (int id, int l, int r) {
if (l == r) {
st[id] = T[l - 1] - 'A';
return;
}
int mid = l + r >> 1;
build (id << 1, l, mid);
build (id << 1| 1, mid + 1, r);
st[id] = (st[id << 1] * pw[r - mid] % Mod + st[id << 1 | 1]) % Mod;
}
void down (int id, int l, int r) {
int mid = l + r >> 1;
if (lz[id] != -1) {
st[id << 1] = hs[lz[id]][mid - l + 1];
st[id << 1 | 1] = hs[lz[id]][r - mid];
lz[id << 1] = lz[id];
lz[id << 1 | 1] = lz[id];
}
lz[id] = -1;
}
void update (int id, int l, int r, int u, int v, int C) {
if (l > v || r < u) return;
if (l >= u && r <= v) {
st[id] = hs[C - 'A'][r - l + 1];
lz[id] = C - 'A';
return;
}
int mid = l + r >> 1;
down (id, l, r);
update (id << 1, l, mid, u, v, C);
update (id << 1 | 1, mid + 1, r, u, v, C);
st[id] = (st[id << 1] * pw[r - mid] % Mod + st[id << 1 | 1]) % Mod;
}
void update (int u, int v, int C) {
return update (1, 1, Range, u, v, C);
}
}ST;
void initHS () {
pw[0] = 1;
rep (i, 1, n * 2) pw[i] = pw[i - 1] * BASE % Mod;
vector<char> c = {'J', 'O', 'I'};
iter (id, c)
rep (i, 1, n)
hs[id - 'A'][i] = (hs[id - 'A'][i - 1] * BASE % Mod + id - 'A') % Mod;
}
ll getHS (string S) {
ll res = 0;
rep (i, 1, n) res = (res * BASE % Mod + S[i - 1] - 'A') % Mod;
return res;
}
void solution () {
cin >> n;
string A, B, C;
cin >> A >> B >> C;
vector<char> c = {'J', 'O', 'I'};
set<string> S = {A, B, C};
auto Merge = [] (string A, string B) {
static string res;
res.resize(SZ(A));
rep (i, 0, SZ(A) - 1)
if (A[i] == B[i]) res[i] = A[i];
else {
static set<char> c;
c = {'J', 'O', 'I'};
c.erase(A[i]);
c.erase(B[i]);
res[i] = *c.begin();
}
return res;
};
int prevsz = SZ(S);
while (1) {
static set<string> newStr;
newStr.clear();
iter (&id1, S)
iter( &id2, S) newStr.insert(Merge(id1, id2));
iter (&id, newStr) S.insert(id);
if (SZ(S) == prevsz) break;
else prevsz = SZ(S);
}
set<ll> vecHS;
initHS();
iter (&id, S) vecHS.insert(getHS(id));
cin >> Q;
cin >> T;
ST.init(n);
ST.build(1, 1, n);
if (vecHS.find(ST.st[1]) != vecHS.end()) cout <<"Yes\n";
else cout <<"No\n";
rep (i, 1, Q) {
int L, R;
char C;
cin >> L >> R >> C;
ST.update(L, R, C);
if (vecHS.find(ST.st[1]) != vecHS.end()) cout <<"Yes\n";
else cout <<"No\n";
}
}
#define file(name) freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout);
int main () {
// file("c");
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll num_Test = 1;
// cin >> num_Test;
while(num_Test--)
solution();
}
/*
18 3
2 5
6 21
13 19
9 17
14 17
19 20
2 16
2 10
9 14
19 20
14 16
1 3
17 19
14 21
18 19
4 7
5 12
1 13
*/
Compilation message
Main.cpp: In member function 'void Segment_Tree::build(int, int, int)':
Main.cpp:43:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
43 | int mid = l + r >> 1;
| ~~^~~
Main.cpp: In member function 'void Segment_Tree::down(int, int, int)':
Main.cpp:49:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
49 | int mid = l + r >> 1;
| ~~^~~
Main.cpp: In member function 'void Segment_Tree::update(int, int, int, int, int, int)':
Main.cpp:65:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
65 | int mid = l + r >> 1;
| ~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
6232 KB |
Output is correct |
2 |
Correct |
51 ms |
6228 KB |
Output is correct |
3 |
Correct |
50 ms |
6236 KB |
Output is correct |
4 |
Correct |
50 ms |
6224 KB |
Output is correct |
5 |
Correct |
47 ms |
6140 KB |
Output is correct |
6 |
Correct |
46 ms |
6228 KB |
Output is correct |
7 |
Correct |
45 ms |
6232 KB |
Output is correct |
8 |
Correct |
48 ms |
6448 KB |
Output is correct |
9 |
Correct |
48 ms |
6220 KB |
Output is correct |
10 |
Correct |
52 ms |
6796 KB |
Output is correct |
11 |
Correct |
50 ms |
6248 KB |
Output is correct |
12 |
Correct |
49 ms |
6392 KB |
Output is correct |
13 |
Correct |
49 ms |
6228 KB |
Output is correct |
14 |
Correct |
49 ms |
6208 KB |
Output is correct |
15 |
Correct |
49 ms |
6224 KB |
Output is correct |
16 |
Correct |
48 ms |
6228 KB |
Output is correct |
17 |
Correct |
49 ms |
6224 KB |
Output is correct |
18 |
Correct |
49 ms |
6228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
6232 KB |
Output is correct |
2 |
Correct |
51 ms |
6228 KB |
Output is correct |
3 |
Correct |
50 ms |
6236 KB |
Output is correct |
4 |
Correct |
50 ms |
6224 KB |
Output is correct |
5 |
Correct |
47 ms |
6140 KB |
Output is correct |
6 |
Correct |
46 ms |
6228 KB |
Output is correct |
7 |
Correct |
45 ms |
6232 KB |
Output is correct |
8 |
Correct |
48 ms |
6448 KB |
Output is correct |
9 |
Correct |
48 ms |
6220 KB |
Output is correct |
10 |
Correct |
52 ms |
6796 KB |
Output is correct |
11 |
Correct |
50 ms |
6248 KB |
Output is correct |
12 |
Correct |
49 ms |
6392 KB |
Output is correct |
13 |
Correct |
49 ms |
6228 KB |
Output is correct |
14 |
Correct |
49 ms |
6208 KB |
Output is correct |
15 |
Correct |
49 ms |
6224 KB |
Output is correct |
16 |
Correct |
48 ms |
6228 KB |
Output is correct |
17 |
Correct |
49 ms |
6224 KB |
Output is correct |
18 |
Correct |
49 ms |
6228 KB |
Output is correct |
19 |
Correct |
158 ms |
32176 KB |
Output is correct |
20 |
Correct |
154 ms |
31968 KB |
Output is correct |
21 |
Correct |
113 ms |
31660 KB |
Output is correct |
22 |
Correct |
114 ms |
29388 KB |
Output is correct |
23 |
Correct |
82 ms |
10064 KB |
Output is correct |
24 |
Correct |
85 ms |
10064 KB |
Output is correct |
25 |
Correct |
124 ms |
32176 KB |
Output is correct |
26 |
Correct |
122 ms |
31924 KB |
Output is correct |
27 |
Correct |
134 ms |
32152 KB |
Output is correct |
28 |
Correct |
137 ms |
31916 KB |
Output is correct |
29 |
Correct |
129 ms |
31944 KB |
Output is correct |
30 |
Correct |
100 ms |
10032 KB |
Output is correct |
31 |
Correct |
136 ms |
32136 KB |
Output is correct |
32 |
Correct |
147 ms |
29944 KB |
Output is correct |
33 |
Correct |
83 ms |
9944 KB |
Output is correct |
34 |
Correct |
133 ms |
31920 KB |
Output is correct |
35 |
Correct |
107 ms |
29052 KB |
Output is correct |
36 |
Correct |
87 ms |
10064 KB |
Output is correct |
37 |
Correct |
81 ms |
9828 KB |
Output is correct |
38 |
Correct |
133 ms |
31784 KB |
Output is correct |
39 |
Correct |
101 ms |
32176 KB |
Output is correct |
40 |
Correct |
112 ms |
25036 KB |
Output is correct |
41 |
Correct |
162 ms |
32172 KB |
Output is correct |
42 |
Correct |
45 ms |
31592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
6232 KB |
Output is correct |
2 |
Correct |
51 ms |
6228 KB |
Output is correct |
3 |
Correct |
50 ms |
6236 KB |
Output is correct |
4 |
Correct |
50 ms |
6224 KB |
Output is correct |
5 |
Correct |
47 ms |
6140 KB |
Output is correct |
6 |
Correct |
46 ms |
6228 KB |
Output is correct |
7 |
Correct |
45 ms |
6232 KB |
Output is correct |
8 |
Correct |
48 ms |
6448 KB |
Output is correct |
9 |
Correct |
48 ms |
6220 KB |
Output is correct |
10 |
Correct |
52 ms |
6796 KB |
Output is correct |
11 |
Correct |
50 ms |
6248 KB |
Output is correct |
12 |
Correct |
49 ms |
6392 KB |
Output is correct |
13 |
Correct |
49 ms |
6228 KB |
Output is correct |
14 |
Correct |
49 ms |
6208 KB |
Output is correct |
15 |
Correct |
49 ms |
6224 KB |
Output is correct |
16 |
Correct |
48 ms |
6228 KB |
Output is correct |
17 |
Correct |
49 ms |
6224 KB |
Output is correct |
18 |
Correct |
49 ms |
6228 KB |
Output is correct |
19 |
Correct |
59 ms |
6512 KB |
Output is correct |
20 |
Correct |
53 ms |
6224 KB |
Output is correct |
21 |
Correct |
50 ms |
6392 KB |
Output is correct |
22 |
Correct |
42 ms |
6228 KB |
Output is correct |
23 |
Correct |
50 ms |
6444 KB |
Output is correct |
24 |
Correct |
57 ms |
6204 KB |
Output is correct |
25 |
Correct |
51 ms |
6424 KB |
Output is correct |
26 |
Correct |
46 ms |
6232 KB |
Output is correct |
27 |
Correct |
48 ms |
6448 KB |
Output is correct |
28 |
Correct |
45 ms |
6224 KB |
Output is correct |
29 |
Correct |
52 ms |
6208 KB |
Output is correct |
30 |
Correct |
44 ms |
6232 KB |
Output is correct |
31 |
Correct |
54 ms |
6380 KB |
Output is correct |
32 |
Correct |
53 ms |
6228 KB |
Output is correct |
33 |
Correct |
53 ms |
5972 KB |
Output is correct |
34 |
Correct |
48 ms |
6036 KB |
Output is correct |
35 |
Correct |
53 ms |
5972 KB |
Output is correct |
36 |
Correct |
54 ms |
6172 KB |
Output is correct |
37 |
Correct |
53 ms |
5972 KB |
Output is correct |
38 |
Correct |
53 ms |
5972 KB |
Output is correct |
39 |
Correct |
53 ms |
5976 KB |
Output is correct |
40 |
Correct |
54 ms |
6168 KB |
Output is correct |
41 |
Correct |
52 ms |
5992 KB |
Output is correct |
42 |
Correct |
53 ms |
6136 KB |
Output is correct |
43 |
Correct |
51 ms |
6016 KB |
Output is correct |
44 |
Correct |
54 ms |
5972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
46 ms |
6232 KB |
Output is correct |
2 |
Correct |
51 ms |
6228 KB |
Output is correct |
3 |
Correct |
50 ms |
6236 KB |
Output is correct |
4 |
Correct |
50 ms |
6224 KB |
Output is correct |
5 |
Correct |
47 ms |
6140 KB |
Output is correct |
6 |
Correct |
46 ms |
6228 KB |
Output is correct |
7 |
Correct |
45 ms |
6232 KB |
Output is correct |
8 |
Correct |
48 ms |
6448 KB |
Output is correct |
9 |
Correct |
48 ms |
6220 KB |
Output is correct |
10 |
Correct |
52 ms |
6796 KB |
Output is correct |
11 |
Correct |
50 ms |
6248 KB |
Output is correct |
12 |
Correct |
49 ms |
6392 KB |
Output is correct |
13 |
Correct |
49 ms |
6228 KB |
Output is correct |
14 |
Correct |
49 ms |
6208 KB |
Output is correct |
15 |
Correct |
49 ms |
6224 KB |
Output is correct |
16 |
Correct |
48 ms |
6228 KB |
Output is correct |
17 |
Correct |
49 ms |
6224 KB |
Output is correct |
18 |
Correct |
49 ms |
6228 KB |
Output is correct |
19 |
Correct |
158 ms |
32176 KB |
Output is correct |
20 |
Correct |
154 ms |
31968 KB |
Output is correct |
21 |
Correct |
113 ms |
31660 KB |
Output is correct |
22 |
Correct |
114 ms |
29388 KB |
Output is correct |
23 |
Correct |
82 ms |
10064 KB |
Output is correct |
24 |
Correct |
85 ms |
10064 KB |
Output is correct |
25 |
Correct |
124 ms |
32176 KB |
Output is correct |
26 |
Correct |
122 ms |
31924 KB |
Output is correct |
27 |
Correct |
134 ms |
32152 KB |
Output is correct |
28 |
Correct |
137 ms |
31916 KB |
Output is correct |
29 |
Correct |
129 ms |
31944 KB |
Output is correct |
30 |
Correct |
100 ms |
10032 KB |
Output is correct |
31 |
Correct |
136 ms |
32136 KB |
Output is correct |
32 |
Correct |
147 ms |
29944 KB |
Output is correct |
33 |
Correct |
83 ms |
9944 KB |
Output is correct |
34 |
Correct |
133 ms |
31920 KB |
Output is correct |
35 |
Correct |
107 ms |
29052 KB |
Output is correct |
36 |
Correct |
87 ms |
10064 KB |
Output is correct |
37 |
Correct |
81 ms |
9828 KB |
Output is correct |
38 |
Correct |
133 ms |
31784 KB |
Output is correct |
39 |
Correct |
101 ms |
32176 KB |
Output is correct |
40 |
Correct |
112 ms |
25036 KB |
Output is correct |
41 |
Correct |
162 ms |
32172 KB |
Output is correct |
42 |
Correct |
45 ms |
31592 KB |
Output is correct |
43 |
Correct |
59 ms |
6512 KB |
Output is correct |
44 |
Correct |
53 ms |
6224 KB |
Output is correct |
45 |
Correct |
50 ms |
6392 KB |
Output is correct |
46 |
Correct |
42 ms |
6228 KB |
Output is correct |
47 |
Correct |
50 ms |
6444 KB |
Output is correct |
48 |
Correct |
57 ms |
6204 KB |
Output is correct |
49 |
Correct |
51 ms |
6424 KB |
Output is correct |
50 |
Correct |
46 ms |
6232 KB |
Output is correct |
51 |
Correct |
48 ms |
6448 KB |
Output is correct |
52 |
Correct |
45 ms |
6224 KB |
Output is correct |
53 |
Correct |
52 ms |
6208 KB |
Output is correct |
54 |
Correct |
44 ms |
6232 KB |
Output is correct |
55 |
Correct |
54 ms |
6380 KB |
Output is correct |
56 |
Correct |
53 ms |
6228 KB |
Output is correct |
57 |
Correct |
53 ms |
5972 KB |
Output is correct |
58 |
Correct |
48 ms |
6036 KB |
Output is correct |
59 |
Correct |
53 ms |
5972 KB |
Output is correct |
60 |
Correct |
54 ms |
6172 KB |
Output is correct |
61 |
Correct |
53 ms |
5972 KB |
Output is correct |
62 |
Correct |
53 ms |
5972 KB |
Output is correct |
63 |
Correct |
53 ms |
5976 KB |
Output is correct |
64 |
Correct |
54 ms |
6168 KB |
Output is correct |
65 |
Correct |
52 ms |
5992 KB |
Output is correct |
66 |
Correct |
53 ms |
6136 KB |
Output is correct |
67 |
Correct |
51 ms |
6016 KB |
Output is correct |
68 |
Correct |
54 ms |
5972 KB |
Output is correct |
69 |
Correct |
1507 ms |
31976 KB |
Output is correct |
70 |
Correct |
1839 ms |
35312 KB |
Output is correct |
71 |
Correct |
91 ms |
10120 KB |
Output is correct |
72 |
Correct |
91 ms |
10004 KB |
Output is correct |
73 |
Correct |
90 ms |
12136 KB |
Output is correct |
74 |
Correct |
191 ms |
29940 KB |
Output is correct |
75 |
Correct |
88 ms |
9880 KB |
Output is correct |
76 |
Correct |
217 ms |
32764 KB |
Output is correct |
77 |
Correct |
198 ms |
30028 KB |
Output is correct |
78 |
Correct |
89 ms |
10068 KB |
Output is correct |
79 |
Correct |
88 ms |
9900 KB |
Output is correct |
80 |
Correct |
1303 ms |
29536 KB |
Output is correct |
81 |
Correct |
167 ms |
10068 KB |
Output is correct |
82 |
Correct |
1851 ms |
35492 KB |
Output is correct |
83 |
Correct |
1689 ms |
35152 KB |
Output is correct |
84 |
Correct |
169 ms |
10068 KB |
Output is correct |
85 |
Correct |
171 ms |
10032 KB |
Output is correct |
86 |
Correct |
1249 ms |
31592 KB |
Output is correct |
87 |
Correct |
1580 ms |
35664 KB |
Output is correct |
88 |
Correct |
172 ms |
10068 KB |
Output is correct |
89 |
Correct |
1424 ms |
32624 KB |
Output is correct |
90 |
Correct |
1582 ms |
35428 KB |
Output is correct |
91 |
Correct |
189 ms |
10028 KB |
Output is correct |
92 |
Correct |
1409 ms |
31524 KB |
Output is correct |
93 |
Correct |
174 ms |
10064 KB |
Output is correct |
94 |
Correct |
169 ms |
10068 KB |
Output is correct |
95 |
Correct |
171 ms |
10064 KB |
Output is correct |
96 |
Correct |
135 ms |
32172 KB |
Output is correct |
97 |
Correct |
155 ms |
35488 KB |
Output is correct |
98 |
Correct |
1177 ms |
27376 KB |
Output is correct |
99 |
Correct |
1843 ms |
35536 KB |
Output is correct |
100 |
Correct |
1651 ms |
34720 KB |
Output is correct |