#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb emplace_back
#define AI(i) begin(i), end(i)
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() { cerr << endl; }
template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
template<class T> void debug(T l, T r) { while (l != r) cerr << *l << " \n"[next(l)==r], ++l; }
#else
#define DE(...) 0
#define debug(...) 0
#endif
const int MAX_N = 300010;
int n, q;
vector<string> s(3);
string t;
char trans(char a, char b) { if (a == b) return a; return 'J' + 'O' + 'I' - a - b; }
string comb(string a, const string &b) {
for (int i = 0;i < a.size();++i)
a[i] = trans(a[i], b[i]);
return a;
}
string yn(bool t) { return t ? "Yes" : "No"; }
struct sgt {
int n;
struct node {
int sym, bad, tg;
node () : sym(-1), bad(0), tg(-1) {}
void operator = (int c) {
tg = c;
bad = sym != c;
}
node (node a, node b) {
if (a.sym == b.sym) sym = a.sym;
else sym = -1;
bad = a.bad + b.bad;
tg = -1;
}
};
vector<node> val;
void upd(int i) {
if (i >= n) return;
push(i);
val[i] = node(val[i<<1], val[i<<1|1]);
}
void push(int i) {
if (i >= n || val[i].tg == -1) return;
int &t = val[i].tg;
val[i<<1] = t, val[i<<1|1] = t;
t = -1;
}
sgt(string s, string t) {
n = s.size();
val.resize(n<<1);
for (int i = 0;i < n;++i) {
val[i+n].sym = s[i];
val[i+n] = t[i];
}
for (int i = n-1;i > 0;--i) {
upd(i);
}
}
bool ok() {
int l = 0, r = n, bad = 0;
l += n, r += n;
for (int i = 18;i > 0;--i) push(l>>i), push(r>>i);
for (;l < r;l>>=1, r>>=1) {
if (l&1) bad += val[l++].bad;
if (r&1) bad += val[--r].bad;
}
return bad == 0;
}
//bool ok() { DE(val[1].bad); return val[1].bad == 0; }
void modify(int l, int r, int c) {
int sl = l += n, sr = r += n;
for (int i = 18;i > 0;--i) push(l>>i), push(r>>i);
for (;l < r;l>>=1, r>>=1) {
if (l&1) val[l++] = c;
if (r&1) val[--r] = c;
}
for (;sl>>=1, sr>>=1;) upd(sl), upd(sr);
}
};
int32_t main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> n;
for (auto &i : s) cin >> i;
for (int i = 0;i < s.size();++i)
for (int j = i+1;j < s.size();++j) {
string x = comb(s[i], s[j]);
if (!count(AI(s), x))
s.pb(x);
assert(s.size() <= 9);
}
cin >> q >> t;
vector<sgt> tree;
for (int i = 0;i < s.size();++i)
tree.pb(sgt(s[i], t));
auto exist = [&]() {
for (int i = 0;i < s.size();++i)
if (tree[i].ok()) return true;
return false;
};
cout << yn(exist()) << '\n';
while (q--) {
int l, r;
char c;
cin >> l >> r >> c; --l;
for (int i = 0;i < s.size();++i)
tree[i].modify(l, r, c);
cout << yn(exist()) << '\n';
}
}
Compilation message
Main.cpp: In function 'std::string comb(std::string, const string&)':
Main.cpp:27:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | for (int i = 0;i < a.size();++i)
| ~~^~~~~~~~~~
Main.cpp: In function 'int32_t main()':
Main.cpp:101:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
101 | for (int i = 0;i < s.size();++i)
| ~~^~~~~~~~~~
Main.cpp:102:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
102 | for (int j = i+1;j < s.size();++j) {
| ~~^~~~~~~~~~
Main.cpp:113:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
113 | for (int i = 0;i < s.size();++i)
| ~~^~~~~~~~~~
Main.cpp: In lambda function:
Main.cpp:117:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
117 | for (int i = 0;i < s.size();++i)
| ~~^~~~~~~~~~
Main.cpp: In function 'int32_t main()':
Main.cpp:129:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
129 | for (int i = 0;i < s.size();++i)
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
175 ms |
764 KB |
Output is correct |
2 |
Correct |
199 ms |
844 KB |
Output is correct |
3 |
Correct |
196 ms |
852 KB |
Output is correct |
4 |
Correct |
181 ms |
880 KB |
Output is correct |
5 |
Correct |
173 ms |
872 KB |
Output is correct |
6 |
Correct |
174 ms |
776 KB |
Output is correct |
7 |
Correct |
183 ms |
848 KB |
Output is correct |
8 |
Correct |
187 ms |
976 KB |
Output is correct |
9 |
Correct |
182 ms |
876 KB |
Output is correct |
10 |
Correct |
189 ms |
912 KB |
Output is correct |
11 |
Correct |
191 ms |
884 KB |
Output is correct |
12 |
Correct |
183 ms |
904 KB |
Output is correct |
13 |
Correct |
191 ms |
836 KB |
Output is correct |
14 |
Correct |
185 ms |
888 KB |
Output is correct |
15 |
Correct |
186 ms |
836 KB |
Output is correct |
16 |
Correct |
184 ms |
872 KB |
Output is correct |
17 |
Correct |
184 ms |
836 KB |
Output is correct |
18 |
Correct |
193 ms |
868 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
175 ms |
764 KB |
Output is correct |
2 |
Correct |
199 ms |
844 KB |
Output is correct |
3 |
Correct |
196 ms |
852 KB |
Output is correct |
4 |
Correct |
181 ms |
880 KB |
Output is correct |
5 |
Correct |
173 ms |
872 KB |
Output is correct |
6 |
Correct |
174 ms |
776 KB |
Output is correct |
7 |
Correct |
183 ms |
848 KB |
Output is correct |
8 |
Correct |
187 ms |
976 KB |
Output is correct |
9 |
Correct |
182 ms |
876 KB |
Output is correct |
10 |
Correct |
189 ms |
912 KB |
Output is correct |
11 |
Correct |
191 ms |
884 KB |
Output is correct |
12 |
Correct |
183 ms |
904 KB |
Output is correct |
13 |
Correct |
191 ms |
836 KB |
Output is correct |
14 |
Correct |
185 ms |
888 KB |
Output is correct |
15 |
Correct |
186 ms |
836 KB |
Output is correct |
16 |
Correct |
184 ms |
872 KB |
Output is correct |
17 |
Correct |
184 ms |
836 KB |
Output is correct |
18 |
Correct |
193 ms |
868 KB |
Output is correct |
19 |
Correct |
515 ms |
16344 KB |
Output is correct |
20 |
Correct |
469 ms |
16292 KB |
Output is correct |
21 |
Correct |
362 ms |
15240 KB |
Output is correct |
22 |
Correct |
374 ms |
13744 KB |
Output is correct |
23 |
Correct |
247 ms |
1800 KB |
Output is correct |
24 |
Correct |
269 ms |
1696 KB |
Output is correct |
25 |
Correct |
387 ms |
16244 KB |
Output is correct |
26 |
Correct |
405 ms |
16160 KB |
Output is correct |
27 |
Correct |
437 ms |
16104 KB |
Output is correct |
28 |
Correct |
434 ms |
16148 KB |
Output is correct |
29 |
Correct |
385 ms |
15720 KB |
Output is correct |
30 |
Correct |
260 ms |
1604 KB |
Output is correct |
31 |
Correct |
408 ms |
16080 KB |
Output is correct |
32 |
Correct |
396 ms |
14768 KB |
Output is correct |
33 |
Correct |
252 ms |
1688 KB |
Output is correct |
34 |
Correct |
467 ms |
16168 KB |
Output is correct |
35 |
Correct |
367 ms |
12140 KB |
Output is correct |
36 |
Correct |
247 ms |
1588 KB |
Output is correct |
37 |
Correct |
261 ms |
1660 KB |
Output is correct |
38 |
Correct |
410 ms |
16112 KB |
Output is correct |
39 |
Correct |
288 ms |
16144 KB |
Output is correct |
40 |
Correct |
371 ms |
10876 KB |
Output is correct |
41 |
Correct |
522 ms |
16444 KB |
Output is correct |
42 |
Correct |
255 ms |
16356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
175 ms |
764 KB |
Output is correct |
2 |
Correct |
199 ms |
844 KB |
Output is correct |
3 |
Correct |
196 ms |
852 KB |
Output is correct |
4 |
Correct |
181 ms |
880 KB |
Output is correct |
5 |
Correct |
173 ms |
872 KB |
Output is correct |
6 |
Correct |
174 ms |
776 KB |
Output is correct |
7 |
Correct |
183 ms |
848 KB |
Output is correct |
8 |
Correct |
187 ms |
976 KB |
Output is correct |
9 |
Correct |
182 ms |
876 KB |
Output is correct |
10 |
Correct |
189 ms |
912 KB |
Output is correct |
11 |
Correct |
191 ms |
884 KB |
Output is correct |
12 |
Correct |
183 ms |
904 KB |
Output is correct |
13 |
Correct |
191 ms |
836 KB |
Output is correct |
14 |
Correct |
185 ms |
888 KB |
Output is correct |
15 |
Correct |
186 ms |
836 KB |
Output is correct |
16 |
Correct |
184 ms |
872 KB |
Output is correct |
17 |
Correct |
184 ms |
836 KB |
Output is correct |
18 |
Correct |
193 ms |
868 KB |
Output is correct |
19 |
Correct |
429 ms |
932 KB |
Output is correct |
20 |
Correct |
446 ms |
912 KB |
Output is correct |
21 |
Correct |
229 ms |
948 KB |
Output is correct |
22 |
Correct |
194 ms |
824 KB |
Output is correct |
23 |
Correct |
227 ms |
836 KB |
Output is correct |
24 |
Correct |
227 ms |
884 KB |
Output is correct |
25 |
Correct |
221 ms |
832 KB |
Output is correct |
26 |
Correct |
210 ms |
836 KB |
Output is correct |
27 |
Correct |
183 ms |
840 KB |
Output is correct |
28 |
Correct |
166 ms |
764 KB |
Output is correct |
29 |
Correct |
184 ms |
852 KB |
Output is correct |
30 |
Correct |
166 ms |
1048 KB |
Output is correct |
31 |
Correct |
424 ms |
912 KB |
Output is correct |
32 |
Correct |
422 ms |
840 KB |
Output is correct |
33 |
Correct |
422 ms |
804 KB |
Output is correct |
34 |
Correct |
382 ms |
844 KB |
Output is correct |
35 |
Correct |
418 ms |
1032 KB |
Output is correct |
36 |
Correct |
426 ms |
828 KB |
Output is correct |
37 |
Correct |
424 ms |
924 KB |
Output is correct |
38 |
Correct |
417 ms |
876 KB |
Output is correct |
39 |
Correct |
416 ms |
876 KB |
Output is correct |
40 |
Correct |
427 ms |
836 KB |
Output is correct |
41 |
Correct |
419 ms |
984 KB |
Output is correct |
42 |
Correct |
430 ms |
940 KB |
Output is correct |
43 |
Correct |
394 ms |
836 KB |
Output is correct |
44 |
Correct |
434 ms |
836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
175 ms |
764 KB |
Output is correct |
2 |
Correct |
199 ms |
844 KB |
Output is correct |
3 |
Correct |
196 ms |
852 KB |
Output is correct |
4 |
Correct |
181 ms |
880 KB |
Output is correct |
5 |
Correct |
173 ms |
872 KB |
Output is correct |
6 |
Correct |
174 ms |
776 KB |
Output is correct |
7 |
Correct |
183 ms |
848 KB |
Output is correct |
8 |
Correct |
187 ms |
976 KB |
Output is correct |
9 |
Correct |
182 ms |
876 KB |
Output is correct |
10 |
Correct |
189 ms |
912 KB |
Output is correct |
11 |
Correct |
191 ms |
884 KB |
Output is correct |
12 |
Correct |
183 ms |
904 KB |
Output is correct |
13 |
Correct |
191 ms |
836 KB |
Output is correct |
14 |
Correct |
185 ms |
888 KB |
Output is correct |
15 |
Correct |
186 ms |
836 KB |
Output is correct |
16 |
Correct |
184 ms |
872 KB |
Output is correct |
17 |
Correct |
184 ms |
836 KB |
Output is correct |
18 |
Correct |
193 ms |
868 KB |
Output is correct |
19 |
Correct |
515 ms |
16344 KB |
Output is correct |
20 |
Correct |
469 ms |
16292 KB |
Output is correct |
21 |
Correct |
362 ms |
15240 KB |
Output is correct |
22 |
Correct |
374 ms |
13744 KB |
Output is correct |
23 |
Correct |
247 ms |
1800 KB |
Output is correct |
24 |
Correct |
269 ms |
1696 KB |
Output is correct |
25 |
Correct |
387 ms |
16244 KB |
Output is correct |
26 |
Correct |
405 ms |
16160 KB |
Output is correct |
27 |
Correct |
437 ms |
16104 KB |
Output is correct |
28 |
Correct |
434 ms |
16148 KB |
Output is correct |
29 |
Correct |
385 ms |
15720 KB |
Output is correct |
30 |
Correct |
260 ms |
1604 KB |
Output is correct |
31 |
Correct |
408 ms |
16080 KB |
Output is correct |
32 |
Correct |
396 ms |
14768 KB |
Output is correct |
33 |
Correct |
252 ms |
1688 KB |
Output is correct |
34 |
Correct |
467 ms |
16168 KB |
Output is correct |
35 |
Correct |
367 ms |
12140 KB |
Output is correct |
36 |
Correct |
247 ms |
1588 KB |
Output is correct |
37 |
Correct |
261 ms |
1660 KB |
Output is correct |
38 |
Correct |
410 ms |
16112 KB |
Output is correct |
39 |
Correct |
288 ms |
16144 KB |
Output is correct |
40 |
Correct |
371 ms |
10876 KB |
Output is correct |
41 |
Correct |
522 ms |
16444 KB |
Output is correct |
42 |
Correct |
255 ms |
16356 KB |
Output is correct |
43 |
Correct |
429 ms |
932 KB |
Output is correct |
44 |
Correct |
446 ms |
912 KB |
Output is correct |
45 |
Correct |
229 ms |
948 KB |
Output is correct |
46 |
Correct |
194 ms |
824 KB |
Output is correct |
47 |
Correct |
227 ms |
836 KB |
Output is correct |
48 |
Correct |
227 ms |
884 KB |
Output is correct |
49 |
Correct |
221 ms |
832 KB |
Output is correct |
50 |
Correct |
210 ms |
836 KB |
Output is correct |
51 |
Correct |
183 ms |
840 KB |
Output is correct |
52 |
Correct |
166 ms |
764 KB |
Output is correct |
53 |
Correct |
184 ms |
852 KB |
Output is correct |
54 |
Correct |
166 ms |
1048 KB |
Output is correct |
55 |
Correct |
424 ms |
912 KB |
Output is correct |
56 |
Correct |
422 ms |
840 KB |
Output is correct |
57 |
Correct |
422 ms |
804 KB |
Output is correct |
58 |
Correct |
382 ms |
844 KB |
Output is correct |
59 |
Correct |
418 ms |
1032 KB |
Output is correct |
60 |
Correct |
426 ms |
828 KB |
Output is correct |
61 |
Correct |
424 ms |
924 KB |
Output is correct |
62 |
Correct |
417 ms |
876 KB |
Output is correct |
63 |
Correct |
416 ms |
876 KB |
Output is correct |
64 |
Correct |
427 ms |
836 KB |
Output is correct |
65 |
Correct |
419 ms |
984 KB |
Output is correct |
66 |
Correct |
430 ms |
940 KB |
Output is correct |
67 |
Correct |
394 ms |
836 KB |
Output is correct |
68 |
Correct |
434 ms |
836 KB |
Output is correct |
69 |
Correct |
1433 ms |
38268 KB |
Output is correct |
70 |
Correct |
1421 ms |
45408 KB |
Output is correct |
71 |
Correct |
322 ms |
2012 KB |
Output is correct |
72 |
Correct |
315 ms |
1948 KB |
Output is correct |
73 |
Correct |
310 ms |
1912 KB |
Output is correct |
74 |
Correct |
344 ms |
13684 KB |
Output is correct |
75 |
Correct |
254 ms |
1732 KB |
Output is correct |
76 |
Correct |
400 ms |
16064 KB |
Output is correct |
77 |
Correct |
397 ms |
13620 KB |
Output is correct |
78 |
Correct |
275 ms |
1588 KB |
Output is correct |
79 |
Correct |
253 ms |
1676 KB |
Output is correct |
80 |
Correct |
1180 ms |
32688 KB |
Output is correct |
81 |
Correct |
640 ms |
3132 KB |
Output is correct |
82 |
Correct |
1258 ms |
45544 KB |
Output is correct |
83 |
Correct |
1207 ms |
42968 KB |
Output is correct |
84 |
Correct |
638 ms |
3188 KB |
Output is correct |
85 |
Correct |
635 ms |
3176 KB |
Output is correct |
86 |
Correct |
1279 ms |
34876 KB |
Output is correct |
87 |
Correct |
1444 ms |
45516 KB |
Output is correct |
88 |
Correct |
674 ms |
3148 KB |
Output is correct |
89 |
Correct |
1230 ms |
40256 KB |
Output is correct |
90 |
Correct |
1407 ms |
45620 KB |
Output is correct |
91 |
Correct |
681 ms |
3172 KB |
Output is correct |
92 |
Correct |
1069 ms |
34304 KB |
Output is correct |
93 |
Correct |
650 ms |
3092 KB |
Output is correct |
94 |
Correct |
661 ms |
3044 KB |
Output is correct |
95 |
Correct |
634 ms |
3256 KB |
Output is correct |
96 |
Correct |
440 ms |
16152 KB |
Output is correct |
97 |
Correct |
744 ms |
45520 KB |
Output is correct |
98 |
Correct |
1311 ms |
30276 KB |
Output is correct |
99 |
Correct |
1648 ms |
45660 KB |
Output is correct |
100 |
Correct |
670 ms |
45648 KB |
Output is correct |