#include <iostream>
#include <set>
#include <algorithm>
#include <cassert>
using namespace std;
#define ll long long
const int MAX = 2e5 + 69;
const int BLOCK = 777;
const int prime = 991;
const int mod = 1e9 + 9;
inline int add(ll x, ll y) { return (int)((x + y) % mod); }
inline int sub(ll x, ll y) { return (int)((x - y + mod) % mod); }
inline int mul(ll x, ll y) { return (int)((x * y) % mod); }
inline int fpow(ll x, ll y)
{
int res = 1;
while (y)
{
if (y & 1) res = mul(res, x);
x = mul(x, x); y >>= 1;
}
return res;
}
int n, q;
int pwr[MAX], inv[MAX];
int ALLSAME[3]; //0: 'J', 1: 'O', 2: 'I', length: BLOCK
int value[MAX / BLOCK + 5]; //hash value for each block
char lazy[MAX / BLOCK + 5];
string s[3], t;
set<int> flower;
inline string combine(const string &a, const string &b)
{
string res = "";
for (int i = 0; i < n; ++i)
{
if (a[i] == b[i]) res += a[i];
else if (a[i] != 'J' && b[i] != 'J') res += 'J';
else if (a[i] != 'O' && b[i] != 'O') res += 'O';
else if (a[i] != 'I' && b[i] != 'I') res += 'I';
}
if ((int)res.size() != n) cerr << a << " " << b << '\n';
return res;
}
inline void genFlower()
{
set<string> st;
for (int i = 0; i < 3; ++i)
st.insert(s[i]);
while (true)
{
bool ok = true;
for (const string &a : st)
{
for (const string &b : st)
{
if (!st.count(combine(a, b)))
{
st.insert(combine(a, b));
ok = false;
}
}
}
if (ok) break;
}
for (const string &x : st)
{
int sum = 0;
for (int i = 0; i < n; ++i)
sum = add(sum, mul(x[i], pwr[i]));
flower.insert(sum);
}
return;
}
inline void update(int l, int r, char c)
{
int id;
if (c == 'J') id = 0;
if (c == 'O') id = 1;
if (c == 'I') id = 2;
int b1 = l / BLOCK, b2 = r / BLOCK;
if (b1 == b2)
{
if (lazy[b1])
{
for (int i = b1 * BLOCK; i < min(n, (b1 + 1) * BLOCK); ++i)
t[i] = lazy[b1];
lazy[b1] = 0;
}
for (int i = l; i <= r; ++i)
t[i] = c;
int sum = 0;
for (int i = b1 * BLOCK; i < min(n, (b1 + 1) * BLOCK); ++i)
sum = add(sum, mul(t[i], pwr[i - b1 * BLOCK]));
value[b1] = sum;
}
else
{
update(l, (b1 + 1) * BLOCK - 1, c);
update(b2 * BLOCK, r, c);
for (int i = b1 + 1; i < b2; ++i)
lazy[i] = c, value[i] = ALLSAME[id];
}
}
inline void out()
{
int sum = 0;
for (int B = 0; B <= (n-1) / BLOCK; ++B)
sum = add(sum, mul(value[B], pwr[B * BLOCK]));
if (flower.count(sum)) cout << "Yes\n";
else cout << "No\n";
}
int main()
{
ios :: sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// The number of flower (after cross breeding) is small
// Generate all Flower
// Maintain current generation (string T)
// using blocks, (size of sqrt(N))
// Complexity: O(N + Q sqrt N)
pwr[0] = 1;
for (int i = 1; i < MAX; ++i)
pwr[i] = mul(prime, pwr[i-1]);
inv[MAX-1] = fpow(pwr[MAX-1], mod-2);
for (int i = MAX-2; i >= 0; --i)
inv[i] = mul(prime, inv[i+1]);
for (int i = 0; i < 3; ++i)
{
int sum = 0;
for (int j = 0; j < BLOCK; ++j)
sum = add(sum, mul("JOI"[i], pwr[j]));
ALLSAME[i] = sum;
}
cin >> n;
for (int i = 0; i < 3; ++i)
cin >> s[i];
genFlower();
cin >> q >> t;
//generating value
for (int B = 0; B <= (n-1) / BLOCK; ++B)
{
int sum = 0;
for (int i = B * BLOCK; i < min(n, (B+1) * BLOCK); ++i)
sum = add(sum, mul(t[i], pwr[i - B * BLOCK]));
value[B] = sum;
}
out();
while (q--)
{
int l, r;
char c;
cin >> l >> r >> c;
update(l-1, r-1, c);
out();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
92 ms |
3788 KB |
Output is correct |
2 |
Correct |
114 ms |
3904 KB |
Output is correct |
3 |
Correct |
119 ms |
3856 KB |
Output is correct |
4 |
Correct |
108 ms |
3864 KB |
Output is correct |
5 |
Correct |
109 ms |
4036 KB |
Output is correct |
6 |
Correct |
105 ms |
3820 KB |
Output is correct |
7 |
Correct |
92 ms |
3912 KB |
Output is correct |
8 |
Correct |
115 ms |
3988 KB |
Output is correct |
9 |
Correct |
113 ms |
3920 KB |
Output is correct |
10 |
Correct |
114 ms |
3928 KB |
Output is correct |
11 |
Correct |
113 ms |
3912 KB |
Output is correct |
12 |
Correct |
112 ms |
3972 KB |
Output is correct |
13 |
Correct |
116 ms |
3980 KB |
Output is correct |
14 |
Correct |
115 ms |
3956 KB |
Output is correct |
15 |
Correct |
112 ms |
3916 KB |
Output is correct |
16 |
Correct |
113 ms |
3900 KB |
Output is correct |
17 |
Correct |
118 ms |
4008 KB |
Output is correct |
18 |
Correct |
120 ms |
3844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
92 ms |
3788 KB |
Output is correct |
2 |
Correct |
114 ms |
3904 KB |
Output is correct |
3 |
Correct |
119 ms |
3856 KB |
Output is correct |
4 |
Correct |
108 ms |
3864 KB |
Output is correct |
5 |
Correct |
109 ms |
4036 KB |
Output is correct |
6 |
Correct |
105 ms |
3820 KB |
Output is correct |
7 |
Correct |
92 ms |
3912 KB |
Output is correct |
8 |
Correct |
115 ms |
3988 KB |
Output is correct |
9 |
Correct |
113 ms |
3920 KB |
Output is correct |
10 |
Correct |
114 ms |
3928 KB |
Output is correct |
11 |
Correct |
113 ms |
3912 KB |
Output is correct |
12 |
Correct |
112 ms |
3972 KB |
Output is correct |
13 |
Correct |
116 ms |
3980 KB |
Output is correct |
14 |
Correct |
115 ms |
3956 KB |
Output is correct |
15 |
Correct |
112 ms |
3916 KB |
Output is correct |
16 |
Correct |
113 ms |
3900 KB |
Output is correct |
17 |
Correct |
118 ms |
4008 KB |
Output is correct |
18 |
Correct |
120 ms |
3844 KB |
Output is correct |
19 |
Correct |
1602 ms |
7268 KB |
Output is correct |
20 |
Correct |
1824 ms |
7104 KB |
Output is correct |
21 |
Correct |
898 ms |
6868 KB |
Output is correct |
22 |
Correct |
864 ms |
6972 KB |
Output is correct |
23 |
Correct |
727 ms |
4980 KB |
Output is correct |
24 |
Correct |
727 ms |
4912 KB |
Output is correct |
25 |
Correct |
974 ms |
7152 KB |
Output is correct |
26 |
Correct |
977 ms |
7116 KB |
Output is correct |
27 |
Correct |
1204 ms |
7080 KB |
Output is correct |
28 |
Correct |
1190 ms |
7080 KB |
Output is correct |
29 |
Correct |
1220 ms |
7148 KB |
Output is correct |
30 |
Correct |
786 ms |
4896 KB |
Output is correct |
31 |
Correct |
1229 ms |
7148 KB |
Output is correct |
32 |
Correct |
1080 ms |
7012 KB |
Output is correct |
33 |
Correct |
742 ms |
4800 KB |
Output is correct |
34 |
Correct |
1151 ms |
7116 KB |
Output is correct |
35 |
Correct |
837 ms |
6524 KB |
Output is correct |
36 |
Correct |
731 ms |
4876 KB |
Output is correct |
37 |
Correct |
735 ms |
4816 KB |
Output is correct |
38 |
Correct |
1699 ms |
6996 KB |
Output is correct |
39 |
Correct |
890 ms |
7232 KB |
Output is correct |
40 |
Correct |
888 ms |
6616 KB |
Output is correct |
41 |
Correct |
1846 ms |
7372 KB |
Output is correct |
42 |
Correct |
1254 ms |
6564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
92 ms |
3788 KB |
Output is correct |
2 |
Correct |
114 ms |
3904 KB |
Output is correct |
3 |
Correct |
119 ms |
3856 KB |
Output is correct |
4 |
Correct |
108 ms |
3864 KB |
Output is correct |
5 |
Correct |
109 ms |
4036 KB |
Output is correct |
6 |
Correct |
105 ms |
3820 KB |
Output is correct |
7 |
Correct |
92 ms |
3912 KB |
Output is correct |
8 |
Correct |
115 ms |
3988 KB |
Output is correct |
9 |
Correct |
113 ms |
3920 KB |
Output is correct |
10 |
Correct |
114 ms |
3928 KB |
Output is correct |
11 |
Correct |
113 ms |
3912 KB |
Output is correct |
12 |
Correct |
112 ms |
3972 KB |
Output is correct |
13 |
Correct |
116 ms |
3980 KB |
Output is correct |
14 |
Correct |
115 ms |
3956 KB |
Output is correct |
15 |
Correct |
112 ms |
3916 KB |
Output is correct |
16 |
Correct |
113 ms |
3900 KB |
Output is correct |
17 |
Correct |
118 ms |
4008 KB |
Output is correct |
18 |
Correct |
120 ms |
3844 KB |
Output is correct |
19 |
Correct |
113 ms |
4032 KB |
Output is correct |
20 |
Correct |
122 ms |
3836 KB |
Output is correct |
21 |
Correct |
120 ms |
3992 KB |
Output is correct |
22 |
Correct |
81 ms |
3772 KB |
Output is correct |
23 |
Correct |
117 ms |
3992 KB |
Output is correct |
24 |
Correct |
103 ms |
3836 KB |
Output is correct |
25 |
Correct |
118 ms |
3940 KB |
Output is correct |
26 |
Correct |
92 ms |
3912 KB |
Output is correct |
27 |
Correct |
116 ms |
3916 KB |
Output is correct |
28 |
Correct |
99 ms |
3732 KB |
Output is correct |
29 |
Correct |
116 ms |
3912 KB |
Output is correct |
30 |
Correct |
84 ms |
3912 KB |
Output is correct |
31 |
Correct |
118 ms |
3916 KB |
Output is correct |
32 |
Correct |
111 ms |
3988 KB |
Output is correct |
33 |
Correct |
117 ms |
3996 KB |
Output is correct |
34 |
Correct |
89 ms |
3860 KB |
Output is correct |
35 |
Correct |
121 ms |
3916 KB |
Output is correct |
36 |
Correct |
117 ms |
3916 KB |
Output is correct |
37 |
Correct |
117 ms |
3916 KB |
Output is correct |
38 |
Correct |
117 ms |
3964 KB |
Output is correct |
39 |
Correct |
117 ms |
3920 KB |
Output is correct |
40 |
Correct |
117 ms |
3916 KB |
Output is correct |
41 |
Correct |
115 ms |
3948 KB |
Output is correct |
42 |
Correct |
119 ms |
3984 KB |
Output is correct |
43 |
Correct |
96 ms |
3936 KB |
Output is correct |
44 |
Correct |
118 ms |
3984 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
92 ms |
3788 KB |
Output is correct |
2 |
Correct |
114 ms |
3904 KB |
Output is correct |
3 |
Correct |
119 ms |
3856 KB |
Output is correct |
4 |
Correct |
108 ms |
3864 KB |
Output is correct |
5 |
Correct |
109 ms |
4036 KB |
Output is correct |
6 |
Correct |
105 ms |
3820 KB |
Output is correct |
7 |
Correct |
92 ms |
3912 KB |
Output is correct |
8 |
Correct |
115 ms |
3988 KB |
Output is correct |
9 |
Correct |
113 ms |
3920 KB |
Output is correct |
10 |
Correct |
114 ms |
3928 KB |
Output is correct |
11 |
Correct |
113 ms |
3912 KB |
Output is correct |
12 |
Correct |
112 ms |
3972 KB |
Output is correct |
13 |
Correct |
116 ms |
3980 KB |
Output is correct |
14 |
Correct |
115 ms |
3956 KB |
Output is correct |
15 |
Correct |
112 ms |
3916 KB |
Output is correct |
16 |
Correct |
113 ms |
3900 KB |
Output is correct |
17 |
Correct |
118 ms |
4008 KB |
Output is correct |
18 |
Correct |
120 ms |
3844 KB |
Output is correct |
19 |
Correct |
1602 ms |
7268 KB |
Output is correct |
20 |
Correct |
1824 ms |
7104 KB |
Output is correct |
21 |
Correct |
898 ms |
6868 KB |
Output is correct |
22 |
Correct |
864 ms |
6972 KB |
Output is correct |
23 |
Correct |
727 ms |
4980 KB |
Output is correct |
24 |
Correct |
727 ms |
4912 KB |
Output is correct |
25 |
Correct |
974 ms |
7152 KB |
Output is correct |
26 |
Correct |
977 ms |
7116 KB |
Output is correct |
27 |
Correct |
1204 ms |
7080 KB |
Output is correct |
28 |
Correct |
1190 ms |
7080 KB |
Output is correct |
29 |
Correct |
1220 ms |
7148 KB |
Output is correct |
30 |
Correct |
786 ms |
4896 KB |
Output is correct |
31 |
Correct |
1229 ms |
7148 KB |
Output is correct |
32 |
Correct |
1080 ms |
7012 KB |
Output is correct |
33 |
Correct |
742 ms |
4800 KB |
Output is correct |
34 |
Correct |
1151 ms |
7116 KB |
Output is correct |
35 |
Correct |
837 ms |
6524 KB |
Output is correct |
36 |
Correct |
731 ms |
4876 KB |
Output is correct |
37 |
Correct |
735 ms |
4816 KB |
Output is correct |
38 |
Correct |
1699 ms |
6996 KB |
Output is correct |
39 |
Correct |
890 ms |
7232 KB |
Output is correct |
40 |
Correct |
888 ms |
6616 KB |
Output is correct |
41 |
Correct |
1846 ms |
7372 KB |
Output is correct |
42 |
Correct |
1254 ms |
6564 KB |
Output is correct |
43 |
Correct |
113 ms |
4032 KB |
Output is correct |
44 |
Correct |
122 ms |
3836 KB |
Output is correct |
45 |
Correct |
120 ms |
3992 KB |
Output is correct |
46 |
Correct |
81 ms |
3772 KB |
Output is correct |
47 |
Correct |
117 ms |
3992 KB |
Output is correct |
48 |
Correct |
103 ms |
3836 KB |
Output is correct |
49 |
Correct |
118 ms |
3940 KB |
Output is correct |
50 |
Correct |
92 ms |
3912 KB |
Output is correct |
51 |
Correct |
116 ms |
3916 KB |
Output is correct |
52 |
Correct |
99 ms |
3732 KB |
Output is correct |
53 |
Correct |
116 ms |
3912 KB |
Output is correct |
54 |
Correct |
84 ms |
3912 KB |
Output is correct |
55 |
Correct |
118 ms |
3916 KB |
Output is correct |
56 |
Correct |
111 ms |
3988 KB |
Output is correct |
57 |
Correct |
117 ms |
3996 KB |
Output is correct |
58 |
Correct |
89 ms |
3860 KB |
Output is correct |
59 |
Correct |
121 ms |
3916 KB |
Output is correct |
60 |
Correct |
117 ms |
3916 KB |
Output is correct |
61 |
Correct |
117 ms |
3916 KB |
Output is correct |
62 |
Correct |
117 ms |
3964 KB |
Output is correct |
63 |
Correct |
117 ms |
3920 KB |
Output is correct |
64 |
Correct |
117 ms |
3916 KB |
Output is correct |
65 |
Correct |
115 ms |
3948 KB |
Output is correct |
66 |
Correct |
119 ms |
3984 KB |
Output is correct |
67 |
Correct |
96 ms |
3936 KB |
Output is correct |
68 |
Correct |
118 ms |
3984 KB |
Output is correct |
69 |
Correct |
1642 ms |
6720 KB |
Output is correct |
70 |
Correct |
1999 ms |
7160 KB |
Output is correct |
71 |
Correct |
729 ms |
4976 KB |
Output is correct |
72 |
Correct |
723 ms |
5040 KB |
Output is correct |
73 |
Correct |
721 ms |
4948 KB |
Output is correct |
74 |
Correct |
870 ms |
6852 KB |
Output is correct |
75 |
Correct |
737 ms |
4832 KB |
Output is correct |
76 |
Correct |
980 ms |
7192 KB |
Output is correct |
77 |
Correct |
902 ms |
6740 KB |
Output is correct |
78 |
Correct |
728 ms |
4796 KB |
Output is correct |
79 |
Correct |
723 ms |
4924 KB |
Output is correct |
80 |
Correct |
1036 ms |
6648 KB |
Output is correct |
81 |
Correct |
749 ms |
4968 KB |
Output is correct |
82 |
Correct |
1238 ms |
7256 KB |
Output is correct |
83 |
Correct |
1180 ms |
7268 KB |
Output is correct |
84 |
Correct |
763 ms |
4928 KB |
Output is correct |
85 |
Correct |
745 ms |
4948 KB |
Output is correct |
86 |
Correct |
1213 ms |
6560 KB |
Output is correct |
87 |
Correct |
1274 ms |
7388 KB |
Output is correct |
88 |
Correct |
796 ms |
4964 KB |
Output is correct |
89 |
Correct |
1111 ms |
6840 KB |
Output is correct |
90 |
Correct |
1192 ms |
7252 KB |
Output is correct |
91 |
Correct |
777 ms |
4976 KB |
Output is correct |
92 |
Correct |
1054 ms |
6768 KB |
Output is correct |
93 |
Correct |
736 ms |
4976 KB |
Output is correct |
94 |
Correct |
740 ms |
4888 KB |
Output is correct |
95 |
Correct |
740 ms |
4972 KB |
Output is correct |
96 |
Correct |
1697 ms |
6948 KB |
Output is correct |
97 |
Correct |
954 ms |
7380 KB |
Output is correct |
98 |
Correct |
1018 ms |
6776 KB |
Output is correct |
99 |
Correct |
2013 ms |
7632 KB |
Output is correct |
100 |
Correct |
1456 ms |
6892 KB |
Output is correct |