#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 2;
const int OFF = 1 << 19;
const char let[] = {'J', 'O', 'I'};
inline int g(char& c){
for(int i = 0; i < 3; ++i) if(let[i] == c) return i;
}
int n, q;
bool ans[MAXN];
struct Change {
int l, r;
char c;
} a[MAXN];
string poc[3];
string t;
struct Node{
int cnt[3][2];
int equal = 0;
int prop = -1;
} tour[OFF];
Node merge(Node& a, Node& b){
Node ret;
for(int i = 0; i < 3; ++i){
for(int j = 0; j < 2; ++j){
ret.cnt[i][j] = a.cnt[i][j] + b.cnt[i][j];
}
}
ret.equal = a.equal + b.equal;
ret.prop = -1;
return ret;
}
void propaj(int x, int l, int r){
for(int i = 0; i < 3; ++i) tour[x].cnt[i][0] = 0;
tour[x].cnt[tour[x].prop][0] = r - l + 1;
tour[x].equal = tour[x].cnt[tour[x].prop][1];
if(l != r){
tour[x * 2 + 1].prop = tour[x].prop;
tour[x * 2 + 2].prop = tour[x].prop;
}
tour[x].prop = -1;
}
void con(int x, int l, int r, string& s, bool t){
tour[x].prop = -1;
if(l == r){
for(int i = 0; i < 3; ++i) tour[x].cnt[i][t] = 0;
tour[x].cnt[g(s[l])][t] = 1;
tour[x].equal = tour[x].cnt[g(s[l])][!t];
return ;
}
int mid = (l + r) >> 1;
con(x * 2 + 1, l, mid, s, t);
con(x * 2 + 2, mid + 1, r, s, t);
tour[x] = merge(tour[x * 2 + 1], tour[x * 2 + 2]);
}
void upd(int x, int l, int r, int ql, int qr, int val){
if(tour[x].prop != -1) propaj(x, l, r);
if(ql > r || l > qr) return ;
if(ql <= l && r <= qr){
tour[x].prop = val;
propaj(x, l, r);
return ;
}
int mid = (l + r) >> 1;
upd(x * 2 + 1, l, mid, ql, qr, val);
upd(x * 2 + 2, mid + 1, r, ql, qr, val);
tour[x] = merge(tour[x * 2 + 1], tour[x * 2 + 2]);
}
string comp(string& a, string& b){
string ret = "";
for(int i = 0; i < n; ++i){
if(a[i] == b[i]) ret += a[i];
else for(char c : {'J', 'O', 'I'}){
if(c != a[i] && c != b[i]) ret += c;
}
}
return ret;
}
void solve(string s){
con(0, 0, n - 1, s, 1);
con(0, 0, n - 1, t, 0);
ans[0] |= (tour[0].equal == n);
for(int i = 1; i <= q; ++i){
upd(0, 0, n - 1, a[i].l, a[i].r, g(a[i].c));
ans[i] |= (tour[0].equal == n);
}
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n;
for(int i = 0; i < 3; ++i) cin >> poc[i];
cin >> q >> t;
for(int i = 1; i <= q; ++i){
cin >> a[i].l >> a[i].r >> a[i].c;
--a[i].l, --a[i].r;
}
for(int i = 1; i < 8; ++i){
string cur = "";
vector<int> tmp;
for(int j = 0; j < 3; ++j){
if(i & 1 << j) tmp.push_back(j);
}
do{
cur = poc[tmp[0]];
for(int j = 1; j < (int)tmp.size(); ++j) cur = comp(cur, poc[tmp[j]]);
solve(cur);
} while(next_permutation(tmp.begin(), tmp.end()));
}
for(int i = 0; i <= q; ++i){
if(ans[i]) cout << "Yes\n";
else cout << "No\n";
}
return 0;
}
Compilation message
Main.cpp: In function 'int g(char&)':
Main.cpp:9:1: warning: control reaches end of non-void function [-Wreturn-type]
9 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
804 ms |
19852 KB |
Output is correct |
2 |
Correct |
927 ms |
20028 KB |
Output is correct |
3 |
Correct |
981 ms |
20032 KB |
Output is correct |
4 |
Correct |
743 ms |
19960 KB |
Output is correct |
5 |
Correct |
703 ms |
19948 KB |
Output is correct |
6 |
Correct |
674 ms |
20000 KB |
Output is correct |
7 |
Correct |
689 ms |
20040 KB |
Output is correct |
8 |
Correct |
727 ms |
20024 KB |
Output is correct |
9 |
Correct |
754 ms |
20032 KB |
Output is correct |
10 |
Correct |
730 ms |
20036 KB |
Output is correct |
11 |
Correct |
723 ms |
20056 KB |
Output is correct |
12 |
Correct |
711 ms |
20028 KB |
Output is correct |
13 |
Correct |
730 ms |
20064 KB |
Output is correct |
14 |
Correct |
708 ms |
20032 KB |
Output is correct |
15 |
Correct |
715 ms |
20028 KB |
Output is correct |
16 |
Correct |
716 ms |
20036 KB |
Output is correct |
17 |
Correct |
730 ms |
20056 KB |
Output is correct |
18 |
Correct |
824 ms |
20028 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
804 ms |
19852 KB |
Output is correct |
2 |
Correct |
927 ms |
20028 KB |
Output is correct |
3 |
Correct |
981 ms |
20032 KB |
Output is correct |
4 |
Correct |
743 ms |
19960 KB |
Output is correct |
5 |
Correct |
703 ms |
19948 KB |
Output is correct |
6 |
Correct |
674 ms |
20000 KB |
Output is correct |
7 |
Correct |
689 ms |
20040 KB |
Output is correct |
8 |
Correct |
727 ms |
20024 KB |
Output is correct |
9 |
Correct |
754 ms |
20032 KB |
Output is correct |
10 |
Correct |
730 ms |
20036 KB |
Output is correct |
11 |
Correct |
723 ms |
20056 KB |
Output is correct |
12 |
Correct |
711 ms |
20028 KB |
Output is correct |
13 |
Correct |
730 ms |
20064 KB |
Output is correct |
14 |
Correct |
708 ms |
20032 KB |
Output is correct |
15 |
Correct |
715 ms |
20028 KB |
Output is correct |
16 |
Correct |
716 ms |
20036 KB |
Output is correct |
17 |
Correct |
730 ms |
20056 KB |
Output is correct |
18 |
Correct |
824 ms |
20028 KB |
Output is correct |
19 |
Correct |
4158 ms |
21288 KB |
Output is correct |
20 |
Correct |
3797 ms |
24512 KB |
Output is correct |
21 |
Correct |
2417 ms |
24332 KB |
Output is correct |
22 |
Correct |
2406 ms |
24132 KB |
Output is correct |
23 |
Correct |
1535 ms |
22236 KB |
Output is correct |
24 |
Correct |
1458 ms |
22300 KB |
Output is correct |
25 |
Correct |
2529 ms |
24620 KB |
Output is correct |
26 |
Correct |
2711 ms |
24744 KB |
Output is correct |
27 |
Correct |
3013 ms |
24668 KB |
Output is correct |
28 |
Correct |
3156 ms |
24644 KB |
Output is correct |
29 |
Correct |
2941 ms |
24448 KB |
Output is correct |
30 |
Correct |
1663 ms |
22236 KB |
Output is correct |
31 |
Correct |
2998 ms |
24740 KB |
Output is correct |
32 |
Correct |
2997 ms |
24352 KB |
Output is correct |
33 |
Correct |
1518 ms |
22344 KB |
Output is correct |
34 |
Correct |
3106 ms |
24580 KB |
Output is correct |
35 |
Correct |
2299 ms |
23772 KB |
Output is correct |
36 |
Correct |
1529 ms |
22224 KB |
Output is correct |
37 |
Correct |
1495 ms |
22220 KB |
Output is correct |
38 |
Correct |
3021 ms |
24444 KB |
Output is correct |
39 |
Correct |
1825 ms |
24768 KB |
Output is correct |
40 |
Correct |
2195 ms |
23964 KB |
Output is correct |
41 |
Correct |
4448 ms |
24932 KB |
Output is correct |
42 |
Correct |
254 ms |
24072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
804 ms |
19852 KB |
Output is correct |
2 |
Correct |
927 ms |
20028 KB |
Output is correct |
3 |
Correct |
981 ms |
20032 KB |
Output is correct |
4 |
Correct |
743 ms |
19960 KB |
Output is correct |
5 |
Correct |
703 ms |
19948 KB |
Output is correct |
6 |
Correct |
674 ms |
20000 KB |
Output is correct |
7 |
Correct |
689 ms |
20040 KB |
Output is correct |
8 |
Correct |
727 ms |
20024 KB |
Output is correct |
9 |
Correct |
754 ms |
20032 KB |
Output is correct |
10 |
Correct |
730 ms |
20036 KB |
Output is correct |
11 |
Correct |
723 ms |
20056 KB |
Output is correct |
12 |
Correct |
711 ms |
20028 KB |
Output is correct |
13 |
Correct |
730 ms |
20064 KB |
Output is correct |
14 |
Correct |
708 ms |
20032 KB |
Output is correct |
15 |
Correct |
715 ms |
20028 KB |
Output is correct |
16 |
Correct |
716 ms |
20036 KB |
Output is correct |
17 |
Correct |
730 ms |
20056 KB |
Output is correct |
18 |
Correct |
824 ms |
20028 KB |
Output is correct |
19 |
Correct |
852 ms |
19960 KB |
Output is correct |
20 |
Correct |
943 ms |
20036 KB |
Output is correct |
21 |
Correct |
716 ms |
20036 KB |
Output is correct |
22 |
Correct |
620 ms |
19836 KB |
Output is correct |
23 |
Correct |
778 ms |
20036 KB |
Output is correct |
24 |
Correct |
683 ms |
19916 KB |
Output is correct |
25 |
Correct |
748 ms |
20028 KB |
Output is correct |
26 |
Correct |
663 ms |
19948 KB |
Output is correct |
27 |
Correct |
738 ms |
20032 KB |
Output is correct |
28 |
Correct |
685 ms |
19916 KB |
Output is correct |
29 |
Correct |
742 ms |
20028 KB |
Output is correct |
30 |
Correct |
613 ms |
19864 KB |
Output is correct |
31 |
Correct |
735 ms |
20140 KB |
Output is correct |
32 |
Correct |
706 ms |
20028 KB |
Output is correct |
33 |
Correct |
763 ms |
20032 KB |
Output is correct |
34 |
Correct |
643 ms |
19892 KB |
Output is correct |
35 |
Correct |
784 ms |
20036 KB |
Output is correct |
36 |
Correct |
731 ms |
20016 KB |
Output is correct |
37 |
Correct |
745 ms |
20056 KB |
Output is correct |
38 |
Correct |
729 ms |
20056 KB |
Output is correct |
39 |
Correct |
724 ms |
20144 KB |
Output is correct |
40 |
Correct |
751 ms |
20032 KB |
Output is correct |
41 |
Correct |
789 ms |
20032 KB |
Output is correct |
42 |
Correct |
813 ms |
20032 KB |
Output is correct |
43 |
Correct |
754 ms |
20136 KB |
Output is correct |
44 |
Correct |
793 ms |
20164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
804 ms |
19852 KB |
Output is correct |
2 |
Correct |
927 ms |
20028 KB |
Output is correct |
3 |
Correct |
981 ms |
20032 KB |
Output is correct |
4 |
Correct |
743 ms |
19960 KB |
Output is correct |
5 |
Correct |
703 ms |
19948 KB |
Output is correct |
6 |
Correct |
674 ms |
20000 KB |
Output is correct |
7 |
Correct |
689 ms |
20040 KB |
Output is correct |
8 |
Correct |
727 ms |
20024 KB |
Output is correct |
9 |
Correct |
754 ms |
20032 KB |
Output is correct |
10 |
Correct |
730 ms |
20036 KB |
Output is correct |
11 |
Correct |
723 ms |
20056 KB |
Output is correct |
12 |
Correct |
711 ms |
20028 KB |
Output is correct |
13 |
Correct |
730 ms |
20064 KB |
Output is correct |
14 |
Correct |
708 ms |
20032 KB |
Output is correct |
15 |
Correct |
715 ms |
20028 KB |
Output is correct |
16 |
Correct |
716 ms |
20036 KB |
Output is correct |
17 |
Correct |
730 ms |
20056 KB |
Output is correct |
18 |
Correct |
824 ms |
20028 KB |
Output is correct |
19 |
Correct |
4158 ms |
21288 KB |
Output is correct |
20 |
Correct |
3797 ms |
24512 KB |
Output is correct |
21 |
Correct |
2417 ms |
24332 KB |
Output is correct |
22 |
Correct |
2406 ms |
24132 KB |
Output is correct |
23 |
Correct |
1535 ms |
22236 KB |
Output is correct |
24 |
Correct |
1458 ms |
22300 KB |
Output is correct |
25 |
Correct |
2529 ms |
24620 KB |
Output is correct |
26 |
Correct |
2711 ms |
24744 KB |
Output is correct |
27 |
Correct |
3013 ms |
24668 KB |
Output is correct |
28 |
Correct |
3156 ms |
24644 KB |
Output is correct |
29 |
Correct |
2941 ms |
24448 KB |
Output is correct |
30 |
Correct |
1663 ms |
22236 KB |
Output is correct |
31 |
Correct |
2998 ms |
24740 KB |
Output is correct |
32 |
Correct |
2997 ms |
24352 KB |
Output is correct |
33 |
Correct |
1518 ms |
22344 KB |
Output is correct |
34 |
Correct |
3106 ms |
24580 KB |
Output is correct |
35 |
Correct |
2299 ms |
23772 KB |
Output is correct |
36 |
Correct |
1529 ms |
22224 KB |
Output is correct |
37 |
Correct |
1495 ms |
22220 KB |
Output is correct |
38 |
Correct |
3021 ms |
24444 KB |
Output is correct |
39 |
Correct |
1825 ms |
24768 KB |
Output is correct |
40 |
Correct |
2195 ms |
23964 KB |
Output is correct |
41 |
Correct |
4448 ms |
24932 KB |
Output is correct |
42 |
Correct |
254 ms |
24072 KB |
Output is correct |
43 |
Correct |
852 ms |
19960 KB |
Output is correct |
44 |
Correct |
943 ms |
20036 KB |
Output is correct |
45 |
Correct |
716 ms |
20036 KB |
Output is correct |
46 |
Correct |
620 ms |
19836 KB |
Output is correct |
47 |
Correct |
778 ms |
20036 KB |
Output is correct |
48 |
Correct |
683 ms |
19916 KB |
Output is correct |
49 |
Correct |
748 ms |
20028 KB |
Output is correct |
50 |
Correct |
663 ms |
19948 KB |
Output is correct |
51 |
Correct |
738 ms |
20032 KB |
Output is correct |
52 |
Correct |
685 ms |
19916 KB |
Output is correct |
53 |
Correct |
742 ms |
20028 KB |
Output is correct |
54 |
Correct |
613 ms |
19864 KB |
Output is correct |
55 |
Correct |
735 ms |
20140 KB |
Output is correct |
56 |
Correct |
706 ms |
20028 KB |
Output is correct |
57 |
Correct |
763 ms |
20032 KB |
Output is correct |
58 |
Correct |
643 ms |
19892 KB |
Output is correct |
59 |
Correct |
784 ms |
20036 KB |
Output is correct |
60 |
Correct |
731 ms |
20016 KB |
Output is correct |
61 |
Correct |
745 ms |
20056 KB |
Output is correct |
62 |
Correct |
729 ms |
20056 KB |
Output is correct |
63 |
Correct |
724 ms |
20144 KB |
Output is correct |
64 |
Correct |
751 ms |
20032 KB |
Output is correct |
65 |
Correct |
789 ms |
20032 KB |
Output is correct |
66 |
Correct |
813 ms |
20032 KB |
Output is correct |
67 |
Correct |
754 ms |
20136 KB |
Output is correct |
68 |
Correct |
793 ms |
20164 KB |
Output is correct |
69 |
Correct |
4514 ms |
23780 KB |
Output is correct |
70 |
Correct |
4558 ms |
24516 KB |
Output is correct |
71 |
Correct |
1557 ms |
22328 KB |
Output is correct |
72 |
Correct |
1500 ms |
22236 KB |
Output is correct |
73 |
Correct |
1470 ms |
22372 KB |
Output is correct |
74 |
Correct |
2386 ms |
23896 KB |
Output is correct |
75 |
Correct |
1475 ms |
22236 KB |
Output is correct |
76 |
Correct |
2638 ms |
24748 KB |
Output is correct |
77 |
Correct |
2531 ms |
24104 KB |
Output is correct |
78 |
Correct |
1490 ms |
22224 KB |
Output is correct |
79 |
Correct |
1474 ms |
22248 KB |
Output is correct |
80 |
Correct |
2258 ms |
23612 KB |
Output is correct |
81 |
Correct |
1485 ms |
22312 KB |
Output is correct |
82 |
Correct |
2699 ms |
24608 KB |
Output is correct |
83 |
Correct |
2708 ms |
24264 KB |
Output is correct |
84 |
Correct |
1488 ms |
22324 KB |
Output is correct |
85 |
Correct |
1478 ms |
22220 KB |
Output is correct |
86 |
Correct |
3007 ms |
23808 KB |
Output is correct |
87 |
Correct |
3377 ms |
24656 KB |
Output is correct |
88 |
Correct |
1708 ms |
22240 KB |
Output is correct |
89 |
Correct |
2992 ms |
24124 KB |
Output is correct |
90 |
Correct |
3628 ms |
24652 KB |
Output is correct |
91 |
Correct |
1795 ms |
22216 KB |
Output is correct |
92 |
Correct |
2631 ms |
23752 KB |
Output is correct |
93 |
Correct |
1620 ms |
22204 KB |
Output is correct |
94 |
Correct |
1692 ms |
22216 KB |
Output is correct |
95 |
Correct |
1711 ms |
22228 KB |
Output is correct |
96 |
Correct |
3401 ms |
24376 KB |
Output is correct |
97 |
Correct |
2054 ms |
24640 KB |
Output is correct |
98 |
Correct |
2524 ms |
23948 KB |
Output is correct |
99 |
Correct |
5188 ms |
24888 KB |
Output is correct |
100 |
Correct |
304 ms |
24224 KB |
Output is correct |