#include <bits/stdc++.h>
using namespace std;
#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(0);
using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using ld = long double;
const int INF = 0x3f3f3f3f;
const ll LINF = ll(4e18) + ll(2e15);
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
static int LamyIsCute = []() {
EmiliaMyWife
return 48763;
}();
const int N = 2e5 + 25, C = 48763;
struct segtree {
ll fac[N], sum[N], arr[N << 2], tag[N << 2];
int n;
void init(int _n) {
n = _n;
fac[0] = sum[0] = 1;
for(int i = 1; i <= n; i++) {
fac[i] = fac[i - 1] * C % MOD;
sum[i] = (sum[i - 1] + fac[i]) % MOD;
}
}
void build(int l, int r, int id, string &s) {
if(l == r - 1) {
arr[id] = s[l] * fac[l] % MOD;
return;
}
int m = l + r >> 1;
build(l, m, id << 1, s);
build(m, r, id << 1 | 1, s);
arr[id] = (arr[id << 1] + arr[id << 1 | 1]) % MOD;
};
inline void build(string &s) { build(0, n, 1, s); }
inline ll que_sum(int l, int r) {
if(!l)
return sum[r - 1];
return (sum[r - 1] - sum[l - 1] + MOD) % MOD;
}
inline void upd(int id, int l, int r, char c) {
tag[id] = c;
arr[id] = c * que_sum(l, r) % MOD;
}
inline void push(int id, int l, int r) {
if(!tag[id])
return;
int m = l + r >> 1;
upd(id << 1, l, m, tag[id]);
upd(id << 1 | 1, m, r, tag[id]);
tag[id] = 0;
}
void edt(int l, int r, int id, int ql, int qr, char c) {
if(r <= ql || qr <= l)
return;
if(ql <= l && r <= qr) {
upd(id, l, r, c);
return;
}
push(id, l, r);
int m = l + r >> 1;
edt(l, m, id << 1, ql, qr, c);
edt(m, r, id << 1 | 1, ql, qr, c);
arr[id] = (arr[id << 1] + arr[id << 1 | 1]) % MOD;
}
inline void edt(int l, int r, char c) { edt(0, n, 1, l, r, c); }
inline ll que() { return arr[1]; }
} tree;
signed main() {
int n;
cin >> n;
tree.init(n);
string arr[3];
for(int i = 0; i < 3; i++)
cin >> arr[i];
const string tmp = "JOI";
auto solve = [&](auto a, auto b) {
string res(n, 'a');
for(int i = 0; i < n; i++) {
if(a[i] == b[i])
res[i] = a[i];
else {
int it = 0;
while(tmp[it] == a[i] || tmp[it] == b[i])
it++;
res[i] = tmp[it];
}
}
return res;
};
vector<int> ord = {0, 1, 2};
vector<string> owo;
for(int i = 0; i < 3; i++)
owo.push_back(arr[i]);
do {
if(ord[0] < ord[1])
owo.push_back(solve(arr[ord[0]], arr[ord[1]]));
owo.push_back(solve(solve(arr[ord[0]], arr[ord[1]]), arr[ord[2]]));
} while(next_permutation(ord.begin(), ord.end()));
set<int> has;
for(auto x : owo) {
tree.build(x);
has.insert(tree.que());
}
auto test = [&]() {
return has.count(tree.que());
};
int q;
cin >> q;
string s;
cin >> s;
tree.build(s);
cout << (test() ? "Yes" : "No") << '\n';
while(q--) {
int l, r;
char c;
cin >> l >> r >> c;
tree.edt(l - 1, r, c);
cout << (test() ? "Yes" : "No") << '\n';
}
}
Compilation message
Main.cpp: In member function 'void segtree::build(int, int, int, std::string&)':
Main.cpp:36:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
36 | int m = l + r >> 1;
| ~~^~~
Main.cpp: In member function 'void segtree::push(int, int, int)':
Main.cpp:55:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
55 | int m = l + r >> 1;
| ~~^~~
Main.cpp: In member function 'void segtree::edt(int, int, int, int, int, char)':
Main.cpp:69:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
69 | int m = l + r >> 1;
| ~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
844 KB |
Output is correct |
2 |
Correct |
80 ms |
932 KB |
Output is correct |
3 |
Correct |
70 ms |
912 KB |
Output is correct |
4 |
Correct |
65 ms |
908 KB |
Output is correct |
5 |
Correct |
75 ms |
844 KB |
Output is correct |
6 |
Correct |
64 ms |
844 KB |
Output is correct |
7 |
Correct |
63 ms |
904 KB |
Output is correct |
8 |
Correct |
66 ms |
912 KB |
Output is correct |
9 |
Correct |
67 ms |
948 KB |
Output is correct |
10 |
Correct |
64 ms |
892 KB |
Output is correct |
11 |
Correct |
69 ms |
844 KB |
Output is correct |
12 |
Correct |
70 ms |
848 KB |
Output is correct |
13 |
Correct |
64 ms |
828 KB |
Output is correct |
14 |
Correct |
63 ms |
896 KB |
Output is correct |
15 |
Correct |
66 ms |
856 KB |
Output is correct |
16 |
Correct |
65 ms |
936 KB |
Output is correct |
17 |
Correct |
66 ms |
940 KB |
Output is correct |
18 |
Correct |
66 ms |
884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
844 KB |
Output is correct |
2 |
Correct |
80 ms |
932 KB |
Output is correct |
3 |
Correct |
70 ms |
912 KB |
Output is correct |
4 |
Correct |
65 ms |
908 KB |
Output is correct |
5 |
Correct |
75 ms |
844 KB |
Output is correct |
6 |
Correct |
64 ms |
844 KB |
Output is correct |
7 |
Correct |
63 ms |
904 KB |
Output is correct |
8 |
Correct |
66 ms |
912 KB |
Output is correct |
9 |
Correct |
67 ms |
948 KB |
Output is correct |
10 |
Correct |
64 ms |
892 KB |
Output is correct |
11 |
Correct |
69 ms |
844 KB |
Output is correct |
12 |
Correct |
70 ms |
848 KB |
Output is correct |
13 |
Correct |
64 ms |
828 KB |
Output is correct |
14 |
Correct |
63 ms |
896 KB |
Output is correct |
15 |
Correct |
66 ms |
856 KB |
Output is correct |
16 |
Correct |
65 ms |
936 KB |
Output is correct |
17 |
Correct |
66 ms |
940 KB |
Output is correct |
18 |
Correct |
66 ms |
884 KB |
Output is correct |
19 |
Correct |
295 ms |
17284 KB |
Output is correct |
20 |
Correct |
270 ms |
16556 KB |
Output is correct |
21 |
Correct |
235 ms |
19144 KB |
Output is correct |
22 |
Correct |
187 ms |
18432 KB |
Output is correct |
23 |
Correct |
102 ms |
4152 KB |
Output is correct |
24 |
Correct |
102 ms |
4096 KB |
Output is correct |
25 |
Correct |
208 ms |
19832 KB |
Output is correct |
26 |
Correct |
212 ms |
19812 KB |
Output is correct |
27 |
Correct |
222 ms |
19772 KB |
Output is correct |
28 |
Correct |
236 ms |
19764 KB |
Output is correct |
29 |
Correct |
202 ms |
19500 KB |
Output is correct |
30 |
Correct |
148 ms |
4208 KB |
Output is correct |
31 |
Correct |
197 ms |
19868 KB |
Output is correct |
32 |
Correct |
203 ms |
19072 KB |
Output is correct |
33 |
Correct |
101 ms |
4168 KB |
Output is correct |
34 |
Correct |
207 ms |
19780 KB |
Output is correct |
35 |
Correct |
161 ms |
17544 KB |
Output is correct |
36 |
Correct |
100 ms |
4096 KB |
Output is correct |
37 |
Correct |
133 ms |
4036 KB |
Output is correct |
38 |
Correct |
207 ms |
16332 KB |
Output is correct |
39 |
Correct |
149 ms |
15812 KB |
Output is correct |
40 |
Correct |
160 ms |
12984 KB |
Output is correct |
41 |
Correct |
342 ms |
20036 KB |
Output is correct |
42 |
Correct |
85 ms |
15212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
844 KB |
Output is correct |
2 |
Correct |
80 ms |
932 KB |
Output is correct |
3 |
Correct |
70 ms |
912 KB |
Output is correct |
4 |
Correct |
65 ms |
908 KB |
Output is correct |
5 |
Correct |
75 ms |
844 KB |
Output is correct |
6 |
Correct |
64 ms |
844 KB |
Output is correct |
7 |
Correct |
63 ms |
904 KB |
Output is correct |
8 |
Correct |
66 ms |
912 KB |
Output is correct |
9 |
Correct |
67 ms |
948 KB |
Output is correct |
10 |
Correct |
64 ms |
892 KB |
Output is correct |
11 |
Correct |
69 ms |
844 KB |
Output is correct |
12 |
Correct |
70 ms |
848 KB |
Output is correct |
13 |
Correct |
64 ms |
828 KB |
Output is correct |
14 |
Correct |
63 ms |
896 KB |
Output is correct |
15 |
Correct |
66 ms |
856 KB |
Output is correct |
16 |
Correct |
65 ms |
936 KB |
Output is correct |
17 |
Correct |
66 ms |
940 KB |
Output is correct |
18 |
Correct |
66 ms |
884 KB |
Output is correct |
19 |
Correct |
74 ms |
892 KB |
Output is correct |
20 |
Correct |
75 ms |
908 KB |
Output is correct |
21 |
Correct |
70 ms |
904 KB |
Output is correct |
22 |
Correct |
59 ms |
872 KB |
Output is correct |
23 |
Correct |
74 ms |
948 KB |
Output is correct |
24 |
Correct |
66 ms |
880 KB |
Output is correct |
25 |
Correct |
70 ms |
864 KB |
Output is correct |
26 |
Correct |
61 ms |
972 KB |
Output is correct |
27 |
Correct |
83 ms |
836 KB |
Output is correct |
28 |
Correct |
58 ms |
844 KB |
Output is correct |
29 |
Correct |
76 ms |
856 KB |
Output is correct |
30 |
Correct |
58 ms |
828 KB |
Output is correct |
31 |
Correct |
72 ms |
892 KB |
Output is correct |
32 |
Correct |
74 ms |
840 KB |
Output is correct |
33 |
Correct |
69 ms |
836 KB |
Output is correct |
34 |
Correct |
61 ms |
860 KB |
Output is correct |
35 |
Correct |
65 ms |
844 KB |
Output is correct |
36 |
Correct |
68 ms |
964 KB |
Output is correct |
37 |
Correct |
72 ms |
856 KB |
Output is correct |
38 |
Correct |
86 ms |
832 KB |
Output is correct |
39 |
Correct |
70 ms |
892 KB |
Output is correct |
40 |
Correct |
66 ms |
844 KB |
Output is correct |
41 |
Correct |
71 ms |
840 KB |
Output is correct |
42 |
Correct |
69 ms |
896 KB |
Output is correct |
43 |
Correct |
64 ms |
912 KB |
Output is correct |
44 |
Correct |
76 ms |
972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
67 ms |
844 KB |
Output is correct |
2 |
Correct |
80 ms |
932 KB |
Output is correct |
3 |
Correct |
70 ms |
912 KB |
Output is correct |
4 |
Correct |
65 ms |
908 KB |
Output is correct |
5 |
Correct |
75 ms |
844 KB |
Output is correct |
6 |
Correct |
64 ms |
844 KB |
Output is correct |
7 |
Correct |
63 ms |
904 KB |
Output is correct |
8 |
Correct |
66 ms |
912 KB |
Output is correct |
9 |
Correct |
67 ms |
948 KB |
Output is correct |
10 |
Correct |
64 ms |
892 KB |
Output is correct |
11 |
Correct |
69 ms |
844 KB |
Output is correct |
12 |
Correct |
70 ms |
848 KB |
Output is correct |
13 |
Correct |
64 ms |
828 KB |
Output is correct |
14 |
Correct |
63 ms |
896 KB |
Output is correct |
15 |
Correct |
66 ms |
856 KB |
Output is correct |
16 |
Correct |
65 ms |
936 KB |
Output is correct |
17 |
Correct |
66 ms |
940 KB |
Output is correct |
18 |
Correct |
66 ms |
884 KB |
Output is correct |
19 |
Correct |
295 ms |
17284 KB |
Output is correct |
20 |
Correct |
270 ms |
16556 KB |
Output is correct |
21 |
Correct |
235 ms |
19144 KB |
Output is correct |
22 |
Correct |
187 ms |
18432 KB |
Output is correct |
23 |
Correct |
102 ms |
4152 KB |
Output is correct |
24 |
Correct |
102 ms |
4096 KB |
Output is correct |
25 |
Correct |
208 ms |
19832 KB |
Output is correct |
26 |
Correct |
212 ms |
19812 KB |
Output is correct |
27 |
Correct |
222 ms |
19772 KB |
Output is correct |
28 |
Correct |
236 ms |
19764 KB |
Output is correct |
29 |
Correct |
202 ms |
19500 KB |
Output is correct |
30 |
Correct |
148 ms |
4208 KB |
Output is correct |
31 |
Correct |
197 ms |
19868 KB |
Output is correct |
32 |
Correct |
203 ms |
19072 KB |
Output is correct |
33 |
Correct |
101 ms |
4168 KB |
Output is correct |
34 |
Correct |
207 ms |
19780 KB |
Output is correct |
35 |
Correct |
161 ms |
17544 KB |
Output is correct |
36 |
Correct |
100 ms |
4096 KB |
Output is correct |
37 |
Correct |
133 ms |
4036 KB |
Output is correct |
38 |
Correct |
207 ms |
16332 KB |
Output is correct |
39 |
Correct |
149 ms |
15812 KB |
Output is correct |
40 |
Correct |
160 ms |
12984 KB |
Output is correct |
41 |
Correct |
342 ms |
20036 KB |
Output is correct |
42 |
Correct |
85 ms |
15212 KB |
Output is correct |
43 |
Correct |
74 ms |
892 KB |
Output is correct |
44 |
Correct |
75 ms |
908 KB |
Output is correct |
45 |
Correct |
70 ms |
904 KB |
Output is correct |
46 |
Correct |
59 ms |
872 KB |
Output is correct |
47 |
Correct |
74 ms |
948 KB |
Output is correct |
48 |
Correct |
66 ms |
880 KB |
Output is correct |
49 |
Correct |
70 ms |
864 KB |
Output is correct |
50 |
Correct |
61 ms |
972 KB |
Output is correct |
51 |
Correct |
83 ms |
836 KB |
Output is correct |
52 |
Correct |
58 ms |
844 KB |
Output is correct |
53 |
Correct |
76 ms |
856 KB |
Output is correct |
54 |
Correct |
58 ms |
828 KB |
Output is correct |
55 |
Correct |
72 ms |
892 KB |
Output is correct |
56 |
Correct |
74 ms |
840 KB |
Output is correct |
57 |
Correct |
69 ms |
836 KB |
Output is correct |
58 |
Correct |
61 ms |
860 KB |
Output is correct |
59 |
Correct |
65 ms |
844 KB |
Output is correct |
60 |
Correct |
68 ms |
964 KB |
Output is correct |
61 |
Correct |
72 ms |
856 KB |
Output is correct |
62 |
Correct |
86 ms |
832 KB |
Output is correct |
63 |
Correct |
70 ms |
892 KB |
Output is correct |
64 |
Correct |
66 ms |
844 KB |
Output is correct |
65 |
Correct |
71 ms |
840 KB |
Output is correct |
66 |
Correct |
69 ms |
896 KB |
Output is correct |
67 |
Correct |
64 ms |
912 KB |
Output is correct |
68 |
Correct |
76 ms |
972 KB |
Output is correct |
69 |
Correct |
251 ms |
18236 KB |
Output is correct |
70 |
Correct |
263 ms |
16492 KB |
Output is correct |
71 |
Correct |
111 ms |
4172 KB |
Output is correct |
72 |
Correct |
102 ms |
4092 KB |
Output is correct |
73 |
Correct |
105 ms |
4236 KB |
Output is correct |
74 |
Correct |
211 ms |
18216 KB |
Output is correct |
75 |
Correct |
115 ms |
4144 KB |
Output is correct |
76 |
Correct |
205 ms |
19784 KB |
Output is correct |
77 |
Correct |
195 ms |
18380 KB |
Output is correct |
78 |
Correct |
100 ms |
4036 KB |
Output is correct |
79 |
Correct |
108 ms |
4208 KB |
Output is correct |
80 |
Correct |
179 ms |
17264 KB |
Output is correct |
81 |
Correct |
119 ms |
4100 KB |
Output is correct |
82 |
Correct |
220 ms |
19852 KB |
Output is correct |
83 |
Correct |
258 ms |
19228 KB |
Output is correct |
84 |
Correct |
110 ms |
4072 KB |
Output is correct |
85 |
Correct |
109 ms |
4084 KB |
Output is correct |
86 |
Correct |
219 ms |
17712 KB |
Output is correct |
87 |
Correct |
222 ms |
19860 KB |
Output is correct |
88 |
Correct |
118 ms |
4148 KB |
Output is correct |
89 |
Correct |
209 ms |
18636 KB |
Output is correct |
90 |
Correct |
249 ms |
19820 KB |
Output is correct |
91 |
Correct |
114 ms |
4148 KB |
Output is correct |
92 |
Correct |
185 ms |
17800 KB |
Output is correct |
93 |
Correct |
121 ms |
4072 KB |
Output is correct |
94 |
Correct |
143 ms |
4048 KB |
Output is correct |
95 |
Correct |
114 ms |
4040 KB |
Output is correct |
96 |
Correct |
232 ms |
16420 KB |
Output is correct |
97 |
Correct |
163 ms |
15792 KB |
Output is correct |
98 |
Correct |
199 ms |
12996 KB |
Output is correct |
99 |
Correct |
345 ms |
20020 KB |
Output is correct |
100 |
Correct |
102 ms |
15332 KB |
Output is correct |