// Hallelujah, praise the one who set me free
// Hallelujah, death has lost its grip on me
// You have broken every chain, There's salvation in your name
// Jesus Christ, my living hope
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define RREP(i, s, e) for (int i = (s); i >= (e); i--)
template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1: 0;}
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define SZ(_a) (int) _a.size()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<iii> viii;
#ifndef DEBUG
#define cerr if (0) cerr
#endif
const int INF = 1000000005;
const ll LINF = 1000000000000000005ll;
const int MAXN = 200005;
const ll MOD = 998244353998244393;
#define submod(x) if (x >= MOD) x -= MOD
#define addmod(x) if (x < 0) x += MOD
int key[100];
int n;
ll pw[MAXN], pfxpw[MAXN];
set<string> st, nst;
set<ll> gd;
int q;
string t;
ll v[MAXN * 4];
int lz[MAXN * 4];
#define MLR int mid = lo + hi >> 1, lc = u << 1, rc = u << 1 ^ 1
void apply(int x, int u, int lo, int hi) {
lz[u] = x;
ll tmp = pfxpw[hi] - (lo == 0 ? 0 : pfxpw[lo - 1]);
addmod(tmp);
v[u] = tmp * x % MOD;
}
void propo(int u, int lo, int hi) {
if (lz[u] == -1) {
return;
}
MLR;
apply(lz[u], lc, lo, mid);
apply(lz[u], rc, mid + 1, hi);
lz[u] = -1;
}
void init(int u = 1, int lo = 0, int hi = n - 1) {
lz[u] = -1;
if (lo == hi) {
v[u] = key[t[lo]] * pw[lo] % MOD;
} else {
MLR;
init(lc, lo, mid);
init(rc, mid + 1, hi);
v[u] = v[lc] + v[rc];
submod(v[u]);
}
}
void upd(int s, int e, int x, int u = 1, int lo = 0, int hi = n - 1) {
if (lo >= s && hi <= e) {
apply(x, u, lo, hi);
return;
}
MLR;
propo(u, lo, hi);
if (s <= mid) {
upd(s, e, x, lc, lo, mid);
}
if (e > mid) {
upd(s, e, x, rc, mid + 1, hi);
}
v[u] = v[lc] + v[rc];
submod(v[u]);
}
int main() {
key['J'] = 0; key['O'] = 1; key['I'] = 2;
#ifndef DEBUG
ios::sync_with_stdio(0), cin.tie(0);
#endif
cin >> n;
pw[0] = pfxpw[0] = 1;
REP (i, 1, n + 1) {
pw[i] = pw[i - 1] * 3 % MOD;
pfxpw[i] = pw[i] + pfxpw[i - 1];
submod(pfxpw[i]);
}
REP (i, 0, 3) {
string s; cin >> s;
st.insert(s);
}
while (1) {
for (string a : st) {
for (string b : st) {
string c = a;
REP (i, 0, n) {
if (a[i] == b[i]) {
c[i] = a[i];
} else {
c[i] = 'J' + 'O' + 'I' - a[i] - b[i];
}
}
nst.insert(c);
}
}
if (SZ(nst) == SZ(st)) {
break;
}
swap(st, nst);
}
for (string s : st) {
ll hsh = 0;
REP (i, 0, n) {
hsh = (hsh + key[s[i]] * pw[i]) % MOD;
}
gd.insert(hsh);
}
cin >> q;
cin >> t;
init();
if (gd.find(v[1]) != gd.end()) {
cout << "Yes\n";
} else {
cout << "No\n";
}
while (q--) {
int l, r; char c; cin >> l >> r >> c;
l--; r--;
upd(l, r, key[c]);
if (gd.find(v[1]) != gd.end()) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
return 0;
}
Compilation message
Main.cpp: In function 'void propo(int, int, int)':
Main.cpp:55:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
55 | #define MLR int mid = lo + hi >> 1, lc = u << 1, rc = u << 1 ^ 1
| ~~~^~~~
Main.cpp:66:5: note: in expansion of macro 'MLR'
66 | MLR;
| ^~~
Main.cpp: In function 'void init(int, int, int)':
Main.cpp:74:25: warning: array subscript has type 'char' [-Wchar-subscripts]
74 | v[u] = key[t[lo]] * pw[lo] % MOD;
| ^
Main.cpp:55:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
55 | #define MLR int mid = lo + hi >> 1, lc = u << 1, rc = u << 1 ^ 1
| ~~~^~~~
Main.cpp:76:9: note: in expansion of macro 'MLR'
76 | MLR;
| ^~~
Main.cpp: In function 'void upd(int, int, int, int, int, int)':
Main.cpp:55:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
55 | #define MLR int mid = lo + hi >> 1, lc = u << 1, rc = u << 1 ^ 1
| ~~~^~~~
Main.cpp:88:5: note: in expansion of macro 'MLR'
88 | MLR;
| ^~~
Main.cpp: In function 'int main()':
Main.cpp:138:34: warning: array subscript has type 'char' [-Wchar-subscripts]
138 | hsh = (hsh + key[s[i]] * pw[i]) % MOD;
| ^
Main.cpp:153:23: warning: array subscript has type 'char' [-Wchar-subscripts]
153 | upd(l, r, key[c]);
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
888 KB |
Output is correct |
2 |
Correct |
59 ms |
936 KB |
Output is correct |
3 |
Correct |
57 ms |
920 KB |
Output is correct |
4 |
Correct |
47 ms |
856 KB |
Output is correct |
5 |
Correct |
47 ms |
800 KB |
Output is correct |
6 |
Correct |
48 ms |
876 KB |
Output is correct |
7 |
Correct |
47 ms |
912 KB |
Output is correct |
8 |
Correct |
50 ms |
928 KB |
Output is correct |
9 |
Correct |
54 ms |
836 KB |
Output is correct |
10 |
Correct |
51 ms |
936 KB |
Output is correct |
11 |
Correct |
52 ms |
908 KB |
Output is correct |
12 |
Correct |
51 ms |
832 KB |
Output is correct |
13 |
Correct |
52 ms |
880 KB |
Output is correct |
14 |
Correct |
52 ms |
920 KB |
Output is correct |
15 |
Correct |
52 ms |
924 KB |
Output is correct |
16 |
Correct |
51 ms |
844 KB |
Output is correct |
17 |
Correct |
51 ms |
828 KB |
Output is correct |
18 |
Correct |
51 ms |
904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
888 KB |
Output is correct |
2 |
Correct |
59 ms |
936 KB |
Output is correct |
3 |
Correct |
57 ms |
920 KB |
Output is correct |
4 |
Correct |
47 ms |
856 KB |
Output is correct |
5 |
Correct |
47 ms |
800 KB |
Output is correct |
6 |
Correct |
48 ms |
876 KB |
Output is correct |
7 |
Correct |
47 ms |
912 KB |
Output is correct |
8 |
Correct |
50 ms |
928 KB |
Output is correct |
9 |
Correct |
54 ms |
836 KB |
Output is correct |
10 |
Correct |
51 ms |
936 KB |
Output is correct |
11 |
Correct |
52 ms |
908 KB |
Output is correct |
12 |
Correct |
51 ms |
832 KB |
Output is correct |
13 |
Correct |
52 ms |
880 KB |
Output is correct |
14 |
Correct |
52 ms |
920 KB |
Output is correct |
15 |
Correct |
52 ms |
924 KB |
Output is correct |
16 |
Correct |
51 ms |
844 KB |
Output is correct |
17 |
Correct |
51 ms |
828 KB |
Output is correct |
18 |
Correct |
51 ms |
904 KB |
Output is correct |
19 |
Correct |
195 ms |
11260 KB |
Output is correct |
20 |
Correct |
188 ms |
12804 KB |
Output is correct |
21 |
Correct |
119 ms |
14584 KB |
Output is correct |
22 |
Correct |
119 ms |
14000 KB |
Output is correct |
23 |
Correct |
87 ms |
3824 KB |
Output is correct |
24 |
Correct |
88 ms |
3860 KB |
Output is correct |
25 |
Correct |
127 ms |
14824 KB |
Output is correct |
26 |
Correct |
126 ms |
14836 KB |
Output is correct |
27 |
Correct |
168 ms |
14792 KB |
Output is correct |
28 |
Correct |
152 ms |
14808 KB |
Output is correct |
29 |
Correct |
147 ms |
14616 KB |
Output is correct |
30 |
Correct |
100 ms |
3868 KB |
Output is correct |
31 |
Correct |
156 ms |
14856 KB |
Output is correct |
32 |
Correct |
140 ms |
14392 KB |
Output is correct |
33 |
Correct |
89 ms |
3860 KB |
Output is correct |
34 |
Correct |
148 ms |
14880 KB |
Output is correct |
35 |
Correct |
111 ms |
13364 KB |
Output is correct |
36 |
Correct |
90 ms |
3784 KB |
Output is correct |
37 |
Correct |
88 ms |
3836 KB |
Output is correct |
38 |
Correct |
176 ms |
14840 KB |
Output is correct |
39 |
Correct |
92 ms |
14916 KB |
Output is correct |
40 |
Correct |
119 ms |
10152 KB |
Output is correct |
41 |
Correct |
188 ms |
15076 KB |
Output is correct |
42 |
Correct |
38 ms |
14228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
888 KB |
Output is correct |
2 |
Correct |
59 ms |
936 KB |
Output is correct |
3 |
Correct |
57 ms |
920 KB |
Output is correct |
4 |
Correct |
47 ms |
856 KB |
Output is correct |
5 |
Correct |
47 ms |
800 KB |
Output is correct |
6 |
Correct |
48 ms |
876 KB |
Output is correct |
7 |
Correct |
47 ms |
912 KB |
Output is correct |
8 |
Correct |
50 ms |
928 KB |
Output is correct |
9 |
Correct |
54 ms |
836 KB |
Output is correct |
10 |
Correct |
51 ms |
936 KB |
Output is correct |
11 |
Correct |
52 ms |
908 KB |
Output is correct |
12 |
Correct |
51 ms |
832 KB |
Output is correct |
13 |
Correct |
52 ms |
880 KB |
Output is correct |
14 |
Correct |
52 ms |
920 KB |
Output is correct |
15 |
Correct |
52 ms |
924 KB |
Output is correct |
16 |
Correct |
51 ms |
844 KB |
Output is correct |
17 |
Correct |
51 ms |
828 KB |
Output is correct |
18 |
Correct |
51 ms |
904 KB |
Output is correct |
19 |
Correct |
58 ms |
892 KB |
Output is correct |
20 |
Correct |
60 ms |
932 KB |
Output is correct |
21 |
Correct |
51 ms |
872 KB |
Output is correct |
22 |
Correct |
44 ms |
876 KB |
Output is correct |
23 |
Correct |
64 ms |
936 KB |
Output is correct |
24 |
Correct |
49 ms |
864 KB |
Output is correct |
25 |
Correct |
52 ms |
856 KB |
Output is correct |
26 |
Correct |
47 ms |
876 KB |
Output is correct |
27 |
Correct |
51 ms |
892 KB |
Output is correct |
28 |
Correct |
46 ms |
864 KB |
Output is correct |
29 |
Correct |
51 ms |
848 KB |
Output is correct |
30 |
Correct |
45 ms |
804 KB |
Output is correct |
31 |
Correct |
53 ms |
884 KB |
Output is correct |
32 |
Correct |
52 ms |
932 KB |
Output is correct |
33 |
Correct |
54 ms |
900 KB |
Output is correct |
34 |
Correct |
47 ms |
848 KB |
Output is correct |
35 |
Correct |
53 ms |
844 KB |
Output is correct |
36 |
Correct |
54 ms |
896 KB |
Output is correct |
37 |
Correct |
53 ms |
848 KB |
Output is correct |
38 |
Correct |
54 ms |
860 KB |
Output is correct |
39 |
Correct |
53 ms |
904 KB |
Output is correct |
40 |
Correct |
53 ms |
884 KB |
Output is correct |
41 |
Correct |
57 ms |
916 KB |
Output is correct |
42 |
Correct |
54 ms |
952 KB |
Output is correct |
43 |
Correct |
50 ms |
868 KB |
Output is correct |
44 |
Correct |
55 ms |
844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
49 ms |
888 KB |
Output is correct |
2 |
Correct |
59 ms |
936 KB |
Output is correct |
3 |
Correct |
57 ms |
920 KB |
Output is correct |
4 |
Correct |
47 ms |
856 KB |
Output is correct |
5 |
Correct |
47 ms |
800 KB |
Output is correct |
6 |
Correct |
48 ms |
876 KB |
Output is correct |
7 |
Correct |
47 ms |
912 KB |
Output is correct |
8 |
Correct |
50 ms |
928 KB |
Output is correct |
9 |
Correct |
54 ms |
836 KB |
Output is correct |
10 |
Correct |
51 ms |
936 KB |
Output is correct |
11 |
Correct |
52 ms |
908 KB |
Output is correct |
12 |
Correct |
51 ms |
832 KB |
Output is correct |
13 |
Correct |
52 ms |
880 KB |
Output is correct |
14 |
Correct |
52 ms |
920 KB |
Output is correct |
15 |
Correct |
52 ms |
924 KB |
Output is correct |
16 |
Correct |
51 ms |
844 KB |
Output is correct |
17 |
Correct |
51 ms |
828 KB |
Output is correct |
18 |
Correct |
51 ms |
904 KB |
Output is correct |
19 |
Correct |
195 ms |
11260 KB |
Output is correct |
20 |
Correct |
188 ms |
12804 KB |
Output is correct |
21 |
Correct |
119 ms |
14584 KB |
Output is correct |
22 |
Correct |
119 ms |
14000 KB |
Output is correct |
23 |
Correct |
87 ms |
3824 KB |
Output is correct |
24 |
Correct |
88 ms |
3860 KB |
Output is correct |
25 |
Correct |
127 ms |
14824 KB |
Output is correct |
26 |
Correct |
126 ms |
14836 KB |
Output is correct |
27 |
Correct |
168 ms |
14792 KB |
Output is correct |
28 |
Correct |
152 ms |
14808 KB |
Output is correct |
29 |
Correct |
147 ms |
14616 KB |
Output is correct |
30 |
Correct |
100 ms |
3868 KB |
Output is correct |
31 |
Correct |
156 ms |
14856 KB |
Output is correct |
32 |
Correct |
140 ms |
14392 KB |
Output is correct |
33 |
Correct |
89 ms |
3860 KB |
Output is correct |
34 |
Correct |
148 ms |
14880 KB |
Output is correct |
35 |
Correct |
111 ms |
13364 KB |
Output is correct |
36 |
Correct |
90 ms |
3784 KB |
Output is correct |
37 |
Correct |
88 ms |
3836 KB |
Output is correct |
38 |
Correct |
176 ms |
14840 KB |
Output is correct |
39 |
Correct |
92 ms |
14916 KB |
Output is correct |
40 |
Correct |
119 ms |
10152 KB |
Output is correct |
41 |
Correct |
188 ms |
15076 KB |
Output is correct |
42 |
Correct |
38 ms |
14228 KB |
Output is correct |
43 |
Correct |
58 ms |
892 KB |
Output is correct |
44 |
Correct |
60 ms |
932 KB |
Output is correct |
45 |
Correct |
51 ms |
872 KB |
Output is correct |
46 |
Correct |
44 ms |
876 KB |
Output is correct |
47 |
Correct |
64 ms |
936 KB |
Output is correct |
48 |
Correct |
49 ms |
864 KB |
Output is correct |
49 |
Correct |
52 ms |
856 KB |
Output is correct |
50 |
Correct |
47 ms |
876 KB |
Output is correct |
51 |
Correct |
51 ms |
892 KB |
Output is correct |
52 |
Correct |
46 ms |
864 KB |
Output is correct |
53 |
Correct |
51 ms |
848 KB |
Output is correct |
54 |
Correct |
45 ms |
804 KB |
Output is correct |
55 |
Correct |
53 ms |
884 KB |
Output is correct |
56 |
Correct |
52 ms |
932 KB |
Output is correct |
57 |
Correct |
54 ms |
900 KB |
Output is correct |
58 |
Correct |
47 ms |
848 KB |
Output is correct |
59 |
Correct |
53 ms |
844 KB |
Output is correct |
60 |
Correct |
54 ms |
896 KB |
Output is correct |
61 |
Correct |
53 ms |
848 KB |
Output is correct |
62 |
Correct |
54 ms |
860 KB |
Output is correct |
63 |
Correct |
53 ms |
904 KB |
Output is correct |
64 |
Correct |
53 ms |
884 KB |
Output is correct |
65 |
Correct |
57 ms |
916 KB |
Output is correct |
66 |
Correct |
54 ms |
952 KB |
Output is correct |
67 |
Correct |
50 ms |
868 KB |
Output is correct |
68 |
Correct |
55 ms |
844 KB |
Output is correct |
69 |
Correct |
200 ms |
16456 KB |
Output is correct |
70 |
Correct |
249 ms |
17916 KB |
Output is correct |
71 |
Correct |
89 ms |
3884 KB |
Output is correct |
72 |
Correct |
88 ms |
3908 KB |
Output is correct |
73 |
Correct |
87 ms |
3820 KB |
Output is correct |
74 |
Correct |
115 ms |
14476 KB |
Output is correct |
75 |
Correct |
87 ms |
3904 KB |
Output is correct |
76 |
Correct |
134 ms |
15668 KB |
Output is correct |
77 |
Correct |
126 ms |
14600 KB |
Output is correct |
78 |
Correct |
87 ms |
3924 KB |
Output is correct |
79 |
Correct |
88 ms |
3916 KB |
Output is correct |
80 |
Correct |
138 ms |
15420 KB |
Output is correct |
81 |
Correct |
91 ms |
3916 KB |
Output is correct |
82 |
Correct |
162 ms |
17920 KB |
Output is correct |
83 |
Correct |
172 ms |
17548 KB |
Output is correct |
84 |
Correct |
91 ms |
4008 KB |
Output is correct |
85 |
Correct |
93 ms |
4052 KB |
Output is correct |
86 |
Correct |
175 ms |
15708 KB |
Output is correct |
87 |
Correct |
189 ms |
17924 KB |
Output is correct |
88 |
Correct |
101 ms |
3968 KB |
Output is correct |
89 |
Correct |
175 ms |
16812 KB |
Output is correct |
90 |
Correct |
183 ms |
17936 KB |
Output is correct |
91 |
Correct |
128 ms |
3992 KB |
Output is correct |
92 |
Correct |
149 ms |
15688 KB |
Output is correct |
93 |
Correct |
91 ms |
3988 KB |
Output is correct |
94 |
Correct |
90 ms |
3996 KB |
Output is correct |
95 |
Correct |
93 ms |
4024 KB |
Output is correct |
96 |
Correct |
161 ms |
14596 KB |
Output is correct |
97 |
Correct |
132 ms |
18004 KB |
Output is correct |
98 |
Correct |
140 ms |
12124 KB |
Output is correct |
99 |
Correct |
226 ms |
18136 KB |
Output is correct |
100 |
Correct |
75 ms |
17404 KB |
Output is correct |