#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
typedef long long ll;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);
const int N = 200005;
int myctoi(char c)
{
if (c == 'J')
return 0;
else if (c == 'O')
return 1;
else if (c == 'I')
return 2;
assert(false);
return 0;
}
int n;
char a[3][N];
char b[N];
struct ban
{
int a[3][3][3];
ban()
{
memset(a, 0, sizeof a);
}
};
ban mer(const ban& l, const ban& r)
{
ban res;
for (int i = 0; i < 3; ++i)
{
for (int j = 0; j < 3; ++j)
{
for (int k = 0; k < 3; ++k)
{
if (l.a[i][j][k] * r.a[i][j][k] == 0)
res.a[i][j][k] = l.a[i][j][k] + r.a[i][j][k];
else if (l.a[i][j][k] == r.a[i][j][k])
res.a[i][j][k] = l.a[i][j][k];
else
res.a[i][j][k] = -1;
}
}
}
return res;
}
ban c[N * 4], t[N * 4];
int laz[N * 4];
void ave(int pos, int g)
{
assert(g);
laz[pos] = g;
for (int i = 0; i < 3; ++i)
{
for (int j = 0; j < 3; ++j)
{
for (int k = 0; k < 3; ++k)
{
t[pos].a[i][j][k] = c[pos].a[i][j][k] * g;
}
}
}
}
void shi(int pos)
{
if (!laz[pos])
return;
ave(pos * 2, laz[pos]);
ave(pos * 2 + 1, laz[pos]);
laz[pos] = 0;
}
void bil(int tl, int tr, int pos)
{
for (int i = tl; i <= tr; ++i)
{
c[pos].a[a[0][i]][a[1][i]][a[2][i]] = 1;
}
if (tl == tr)
{
int i = tl;
t[pos].a[a[0][i]][a[1][i]][a[2][i]] = b[i] + 1;
return;
}
int m = (tl + tr) / 2;
bil(tl, m, pos * 2);
bil(m + 1, tr, pos * 2 + 1);
t[pos] = mer(t[pos * 2], t[pos * 2 + 1]);
}
void ubd(int tl, int tr, int l, int r, int y, int pos)
{
if (l > r)
return;
if (tl == l && tr == r)
{
ave(pos, y);
return;
}
shi(pos);
int m = (tl + tr) / 2;
ubd(tl, m, l, min(m, r), y, pos * 2);
ubd(m + 1, tr, max(m + 1, l), r, y, pos * 2 + 1);
t[pos] = mer(t[pos * 2], t[pos * 2 + 1]);
}
vector<int> gor(const vector<int>& a, const vector<int>& b)
{
vector<int> c;
assert(sz(a) == sz(b));
for (int i = 0; i < sz(a); ++i)
{
if (a[i] == b[i])
c.push_back(a[i]);
else
c.push_back(0 + 1 + 2 - a[i] - b[i]);
}
return c;
}
bool qryy()
{
vector<int> v[4];
for (int i = 0; i < 3; ++i)
{
for (int j = 0; j < 3; ++j)
{
for (int k = 0; k < 3; ++k)
{
if (t[1].a[i][j][k] == -1)
return false;
if (t[1].a[i][j][k])
{
v[0].push_back(i);
v[1].push_back(j);
v[2].push_back(k);
v[3].push_back(t[1].a[i][j][k] - 1);
}
}
}
}
vector<vector<int> > vv;
for (int i = 0; i < 3; ++i)
vv.push_back(v[i]);
for (int i = 0; i < sz(vv); ++i)
{
for (int j = 0; j < i; ++j)
{
vector<int> t = gor(vv[i], vv[j]);
bool z = false;
for (int k = 0; k < sz(vv); ++k)
{
if (vv[k] == t)
{
z = true;
break;
}
}
if (!z)
vv.push_back(t);
}
if (vv[i] == v[3])
return true;
}
return false;
}
void solv()
{
cin >> n;
for (int i = 0; i < 3; ++i)
cin >> (a[i] + 1);
int qq;
cin >> qq;
cin >> (b + 1);
for (int i = 0; i < 3; ++i)
{
for (int j = 1; j <= n; ++j)
a[i][j] = myctoi(a[i][j]);
}
for (int i = 1; i <= n; ++i)
b[i] = myctoi(b[i]);
bil(1, n, 1);
if (qryy())
cout << "Yes\n";
else
cout << "No\n";
while (qq--)
{
int l, r;
char y;
cin >> l >> r >> y;
ubd(1, n, l, r, myctoi(y) + 1, 1);
if (qryy())
cout << "Yes\n";
else
cout << "No\n";
}
}
int main()
{
#ifdef SOMETHING
freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif // SOMETHING
ios_base::sync_with_stdio(false), cin.tie(0);
int tt = 1;
//cin >> tt;
while (tt--)
{
solv();
}
return 0;
}
Compilation message
Main.cpp: In function 'void bil(int, int, int)':
Main.cpp:91:24: warning: array subscript has type 'char' [-Wchar-subscripts]
91 | c[pos].a[a[0][i]][a[1][i]][a[2][i]] = 1;
| ~~~~~~^
Main.cpp:91:33: warning: array subscript has type 'char' [-Wchar-subscripts]
91 | c[pos].a[a[0][i]][a[1][i]][a[2][i]] = 1;
| ~~~~~~^
Main.cpp:91:42: warning: array subscript has type 'char' [-Wchar-subscripts]
91 | c[pos].a[a[0][i]][a[1][i]][a[2][i]] = 1;
| ~~~~~~^
Main.cpp:96:24: warning: array subscript has type 'char' [-Wchar-subscripts]
96 | t[pos].a[a[0][i]][a[1][i]][a[2][i]] = b[i] + 1;
| ~~~~~~^
Main.cpp:96:33: warning: array subscript has type 'char' [-Wchar-subscripts]
96 | t[pos].a[a[0][i]][a[1][i]][a[2][i]] = b[i] + 1;
| ~~~~~~^
Main.cpp:96:42: warning: array subscript has type 'char' [-Wchar-subscripts]
96 | t[pos].a[a[0][i]][a[1][i]][a[2][i]] = b[i] + 1;
| ~~~~~~^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
209 ms |
170248 KB |
Output is correct |
2 |
Correct |
229 ms |
169996 KB |
Output is correct |
3 |
Correct |
256 ms |
169976 KB |
Output is correct |
4 |
Correct |
207 ms |
170184 KB |
Output is correct |
5 |
Correct |
200 ms |
169924 KB |
Output is correct |
6 |
Correct |
216 ms |
169940 KB |
Output is correct |
7 |
Correct |
211 ms |
170196 KB |
Output is correct |
8 |
Correct |
210 ms |
169968 KB |
Output is correct |
9 |
Correct |
214 ms |
169996 KB |
Output is correct |
10 |
Correct |
211 ms |
170124 KB |
Output is correct |
11 |
Correct |
208 ms |
169980 KB |
Output is correct |
12 |
Correct |
207 ms |
170000 KB |
Output is correct |
13 |
Correct |
213 ms |
170116 KB |
Output is correct |
14 |
Correct |
204 ms |
170024 KB |
Output is correct |
15 |
Correct |
209 ms |
169988 KB |
Output is correct |
16 |
Correct |
211 ms |
169956 KB |
Output is correct |
17 |
Correct |
208 ms |
170016 KB |
Output is correct |
18 |
Correct |
245 ms |
169956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
209 ms |
170248 KB |
Output is correct |
2 |
Correct |
229 ms |
169996 KB |
Output is correct |
3 |
Correct |
256 ms |
169976 KB |
Output is correct |
4 |
Correct |
207 ms |
170184 KB |
Output is correct |
5 |
Correct |
200 ms |
169924 KB |
Output is correct |
6 |
Correct |
216 ms |
169940 KB |
Output is correct |
7 |
Correct |
211 ms |
170196 KB |
Output is correct |
8 |
Correct |
210 ms |
169968 KB |
Output is correct |
9 |
Correct |
214 ms |
169996 KB |
Output is correct |
10 |
Correct |
211 ms |
170124 KB |
Output is correct |
11 |
Correct |
208 ms |
169980 KB |
Output is correct |
12 |
Correct |
207 ms |
170000 KB |
Output is correct |
13 |
Correct |
213 ms |
170116 KB |
Output is correct |
14 |
Correct |
204 ms |
170024 KB |
Output is correct |
15 |
Correct |
209 ms |
169988 KB |
Output is correct |
16 |
Correct |
211 ms |
169956 KB |
Output is correct |
17 |
Correct |
208 ms |
170016 KB |
Output is correct |
18 |
Correct |
245 ms |
169956 KB |
Output is correct |
19 |
Correct |
858 ms |
175464 KB |
Output is correct |
20 |
Correct |
747 ms |
174788 KB |
Output is correct |
21 |
Correct |
508 ms |
176208 KB |
Output is correct |
22 |
Correct |
535 ms |
176020 KB |
Output is correct |
23 |
Correct |
315 ms |
172532 KB |
Output is correct |
24 |
Correct |
327 ms |
172600 KB |
Output is correct |
25 |
Correct |
533 ms |
176544 KB |
Output is correct |
26 |
Correct |
592 ms |
176616 KB |
Output is correct |
27 |
Correct |
679 ms |
176512 KB |
Output is correct |
28 |
Correct |
700 ms |
176444 KB |
Output is correct |
29 |
Correct |
633 ms |
176436 KB |
Output is correct |
30 |
Correct |
364 ms |
172492 KB |
Output is correct |
31 |
Correct |
644 ms |
176416 KB |
Output is correct |
32 |
Correct |
635 ms |
176268 KB |
Output is correct |
33 |
Correct |
327 ms |
172436 KB |
Output is correct |
34 |
Correct |
670 ms |
176524 KB |
Output is correct |
35 |
Correct |
481 ms |
176000 KB |
Output is correct |
36 |
Correct |
320 ms |
172540 KB |
Output is correct |
37 |
Correct |
319 ms |
172428 KB |
Output is correct |
38 |
Correct |
679 ms |
174664 KB |
Output is correct |
39 |
Correct |
365 ms |
174576 KB |
Output is correct |
40 |
Correct |
510 ms |
174864 KB |
Output is correct |
41 |
Correct |
980 ms |
176904 KB |
Output is correct |
42 |
Correct |
177 ms |
173828 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
209 ms |
170248 KB |
Output is correct |
2 |
Correct |
229 ms |
169996 KB |
Output is correct |
3 |
Correct |
256 ms |
169976 KB |
Output is correct |
4 |
Correct |
207 ms |
170184 KB |
Output is correct |
5 |
Correct |
200 ms |
169924 KB |
Output is correct |
6 |
Correct |
216 ms |
169940 KB |
Output is correct |
7 |
Correct |
211 ms |
170196 KB |
Output is correct |
8 |
Correct |
210 ms |
169968 KB |
Output is correct |
9 |
Correct |
214 ms |
169996 KB |
Output is correct |
10 |
Correct |
211 ms |
170124 KB |
Output is correct |
11 |
Correct |
208 ms |
169980 KB |
Output is correct |
12 |
Correct |
207 ms |
170000 KB |
Output is correct |
13 |
Correct |
213 ms |
170116 KB |
Output is correct |
14 |
Correct |
204 ms |
170024 KB |
Output is correct |
15 |
Correct |
209 ms |
169988 KB |
Output is correct |
16 |
Correct |
211 ms |
169956 KB |
Output is correct |
17 |
Correct |
208 ms |
170016 KB |
Output is correct |
18 |
Correct |
245 ms |
169956 KB |
Output is correct |
19 |
Correct |
243 ms |
169972 KB |
Output is correct |
20 |
Correct |
445 ms |
170004 KB |
Output is correct |
21 |
Correct |
223 ms |
169944 KB |
Output is correct |
22 |
Correct |
217 ms |
169944 KB |
Output is correct |
23 |
Correct |
224 ms |
169936 KB |
Output is correct |
24 |
Correct |
220 ms |
169980 KB |
Output is correct |
25 |
Correct |
229 ms |
170032 KB |
Output is correct |
26 |
Correct |
216 ms |
169988 KB |
Output is correct |
27 |
Correct |
226 ms |
169932 KB |
Output is correct |
28 |
Correct |
207 ms |
169948 KB |
Output is correct |
29 |
Correct |
230 ms |
169936 KB |
Output is correct |
30 |
Correct |
203 ms |
170032 KB |
Output is correct |
31 |
Correct |
297 ms |
169936 KB |
Output is correct |
32 |
Correct |
284 ms |
169996 KB |
Output is correct |
33 |
Correct |
285 ms |
170052 KB |
Output is correct |
34 |
Correct |
261 ms |
169984 KB |
Output is correct |
35 |
Correct |
248 ms |
169928 KB |
Output is correct |
36 |
Correct |
241 ms |
169940 KB |
Output is correct |
37 |
Correct |
245 ms |
169928 KB |
Output is correct |
38 |
Correct |
248 ms |
169992 KB |
Output is correct |
39 |
Correct |
247 ms |
169920 KB |
Output is correct |
40 |
Correct |
242 ms |
169916 KB |
Output is correct |
41 |
Correct |
263 ms |
169996 KB |
Output is correct |
42 |
Correct |
249 ms |
170040 KB |
Output is correct |
43 |
Correct |
278 ms |
170008 KB |
Output is correct |
44 |
Correct |
271 ms |
169932 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
209 ms |
170248 KB |
Output is correct |
2 |
Correct |
229 ms |
169996 KB |
Output is correct |
3 |
Correct |
256 ms |
169976 KB |
Output is correct |
4 |
Correct |
207 ms |
170184 KB |
Output is correct |
5 |
Correct |
200 ms |
169924 KB |
Output is correct |
6 |
Correct |
216 ms |
169940 KB |
Output is correct |
7 |
Correct |
211 ms |
170196 KB |
Output is correct |
8 |
Correct |
210 ms |
169968 KB |
Output is correct |
9 |
Correct |
214 ms |
169996 KB |
Output is correct |
10 |
Correct |
211 ms |
170124 KB |
Output is correct |
11 |
Correct |
208 ms |
169980 KB |
Output is correct |
12 |
Correct |
207 ms |
170000 KB |
Output is correct |
13 |
Correct |
213 ms |
170116 KB |
Output is correct |
14 |
Correct |
204 ms |
170024 KB |
Output is correct |
15 |
Correct |
209 ms |
169988 KB |
Output is correct |
16 |
Correct |
211 ms |
169956 KB |
Output is correct |
17 |
Correct |
208 ms |
170016 KB |
Output is correct |
18 |
Correct |
245 ms |
169956 KB |
Output is correct |
19 |
Correct |
858 ms |
175464 KB |
Output is correct |
20 |
Correct |
747 ms |
174788 KB |
Output is correct |
21 |
Correct |
508 ms |
176208 KB |
Output is correct |
22 |
Correct |
535 ms |
176020 KB |
Output is correct |
23 |
Correct |
315 ms |
172532 KB |
Output is correct |
24 |
Correct |
327 ms |
172600 KB |
Output is correct |
25 |
Correct |
533 ms |
176544 KB |
Output is correct |
26 |
Correct |
592 ms |
176616 KB |
Output is correct |
27 |
Correct |
679 ms |
176512 KB |
Output is correct |
28 |
Correct |
700 ms |
176444 KB |
Output is correct |
29 |
Correct |
633 ms |
176436 KB |
Output is correct |
30 |
Correct |
364 ms |
172492 KB |
Output is correct |
31 |
Correct |
644 ms |
176416 KB |
Output is correct |
32 |
Correct |
635 ms |
176268 KB |
Output is correct |
33 |
Correct |
327 ms |
172436 KB |
Output is correct |
34 |
Correct |
670 ms |
176524 KB |
Output is correct |
35 |
Correct |
481 ms |
176000 KB |
Output is correct |
36 |
Correct |
320 ms |
172540 KB |
Output is correct |
37 |
Correct |
319 ms |
172428 KB |
Output is correct |
38 |
Correct |
679 ms |
174664 KB |
Output is correct |
39 |
Correct |
365 ms |
174576 KB |
Output is correct |
40 |
Correct |
510 ms |
174864 KB |
Output is correct |
41 |
Correct |
980 ms |
176904 KB |
Output is correct |
42 |
Correct |
177 ms |
173828 KB |
Output is correct |
43 |
Correct |
243 ms |
169972 KB |
Output is correct |
44 |
Correct |
445 ms |
170004 KB |
Output is correct |
45 |
Correct |
223 ms |
169944 KB |
Output is correct |
46 |
Correct |
217 ms |
169944 KB |
Output is correct |
47 |
Correct |
224 ms |
169936 KB |
Output is correct |
48 |
Correct |
220 ms |
169980 KB |
Output is correct |
49 |
Correct |
229 ms |
170032 KB |
Output is correct |
50 |
Correct |
216 ms |
169988 KB |
Output is correct |
51 |
Correct |
226 ms |
169932 KB |
Output is correct |
52 |
Correct |
207 ms |
169948 KB |
Output is correct |
53 |
Correct |
230 ms |
169936 KB |
Output is correct |
54 |
Correct |
203 ms |
170032 KB |
Output is correct |
55 |
Correct |
297 ms |
169936 KB |
Output is correct |
56 |
Correct |
284 ms |
169996 KB |
Output is correct |
57 |
Correct |
285 ms |
170052 KB |
Output is correct |
58 |
Correct |
261 ms |
169984 KB |
Output is correct |
59 |
Correct |
248 ms |
169928 KB |
Output is correct |
60 |
Correct |
241 ms |
169940 KB |
Output is correct |
61 |
Correct |
245 ms |
169928 KB |
Output is correct |
62 |
Correct |
248 ms |
169992 KB |
Output is correct |
63 |
Correct |
247 ms |
169920 KB |
Output is correct |
64 |
Correct |
242 ms |
169916 KB |
Output is correct |
65 |
Correct |
263 ms |
169996 KB |
Output is correct |
66 |
Correct |
249 ms |
170040 KB |
Output is correct |
67 |
Correct |
278 ms |
170008 KB |
Output is correct |
68 |
Correct |
271 ms |
169932 KB |
Output is correct |
69 |
Correct |
911 ms |
175936 KB |
Output is correct |
70 |
Correct |
1002 ms |
174936 KB |
Output is correct |
71 |
Correct |
355 ms |
172620 KB |
Output is correct |
72 |
Correct |
355 ms |
172532 KB |
Output is correct |
73 |
Correct |
365 ms |
172620 KB |
Output is correct |
74 |
Correct |
530 ms |
175976 KB |
Output is correct |
75 |
Correct |
348 ms |
172468 KB |
Output is correct |
76 |
Correct |
588 ms |
176580 KB |
Output is correct |
77 |
Correct |
573 ms |
176088 KB |
Output is correct |
78 |
Correct |
353 ms |
172464 KB |
Output is correct |
79 |
Correct |
357 ms |
172492 KB |
Output is correct |
80 |
Correct |
596 ms |
175652 KB |
Output is correct |
81 |
Correct |
401 ms |
172492 KB |
Output is correct |
82 |
Correct |
651 ms |
176484 KB |
Output is correct |
83 |
Correct |
664 ms |
176252 KB |
Output is correct |
84 |
Correct |
409 ms |
172492 KB |
Output is correct |
85 |
Correct |
397 ms |
172448 KB |
Output is correct |
86 |
Correct |
709 ms |
175872 KB |
Output is correct |
87 |
Correct |
807 ms |
176528 KB |
Output is correct |
88 |
Correct |
431 ms |
172504 KB |
Output is correct |
89 |
Correct |
731 ms |
176072 KB |
Output is correct |
90 |
Correct |
759 ms |
176500 KB |
Output is correct |
91 |
Correct |
418 ms |
172548 KB |
Output is correct |
92 |
Correct |
601 ms |
175816 KB |
Output is correct |
93 |
Correct |
393 ms |
172500 KB |
Output is correct |
94 |
Correct |
408 ms |
172540 KB |
Output is correct |
95 |
Correct |
404 ms |
172520 KB |
Output is correct |
96 |
Correct |
644 ms |
174632 KB |
Output is correct |
97 |
Correct |
508 ms |
174560 KB |
Output is correct |
98 |
Correct |
585 ms |
174840 KB |
Output is correct |
99 |
Correct |
1161 ms |
176700 KB |
Output is correct |
100 |
Correct |
276 ms |
173820 KB |
Output is correct |