#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#pragma GCC optimize "O3"
#define _strfy(s) #s
#define strfy(s) _strfy(s)
#define ALPHABET "JOI"
#define MAX_N 200000
int seq_len;
char seqA[MAX_N+1], seqB[MAX_N+1], seqC[MAX_N+1];
char seqAB[MAX_N+1], seqBC[MAX_N+1], seqAC[MAX_N+1];
char seqABC[MAX_N+1], seqBCA[MAX_N+1], seqACB[MAX_N+1];
char seqT[MAX_N+1];
#define MAX_Q 200000
int num_mods;
struct mod {
int left, right;
char chr;
} mods[MAX_Q];
bool posbl[MAX_Q+1];
static inline void validate(const char *seq) {
assert(strlen(seq) == seq_len);
for(; *seq != 0; seq++) assert(*seq == ALPHABET[0] || *seq == ALPHABET[1] || *seq == ALPHABET[2]);
}
static inline void cross(const char *seq1, const char *seq2, char *seqO) {
for(int i = 0; i < seq_len; i++) {
if(seq1[i] == seq2[i]) seqO[i] = seq1[i];
else if(seq1[i] == ALPHABET[1] && seq2[i] == ALPHABET[2]) seqO[i] = ALPHABET[0];
else if(seq1[i] == ALPHABET[2] && seq2[i] == ALPHABET[1]) seqO[i] = ALPHABET[0];
else if(seq1[i] == ALPHABET[0] && seq2[i] == ALPHABET[2]) seqO[i] = ALPHABET[1];
else if(seq1[i] == ALPHABET[2] && seq2[i] == ALPHABET[0]) seqO[i] = ALPHABET[1];
else if(seq1[i] == ALPHABET[0] && seq2[i] == ALPHABET[1]) seqO[i] = ALPHABET[2];
else if(seq1[i] == ALPHABET[1] && seq2[i] == ALPHABET[0]) seqO[i] = ALPHABET[2];
else assert(false);
}
}
struct node {
struct node *lchild, *rchild;
int left, right;
int lazy_c;
int numA, numB, numC;
int numM; //numMatch
} nodes[2*MAX_N], *next_node;
struct node *create_tree(const char *seq, int l = -1, int r = -1) {
if(l < 0 && r < 0) {
next_node = nodes;
l = 0;
r = seq_len;
}
assert(0 <= l && l < r && r <= seq_len);
assert(next_node < nodes + 2*MAX_N);
struct node *node = next_node++;
node->left = l;
node->right = r;
node->lazy_c = -1;
if(l == r - 1) {
node->lchild = NULL;
node->rchild = NULL;
node->numA = (seq[l] == ALPHABET[0]) ? 1 : 0;
node->numB = (seq[l] == ALPHABET[1]) ? 1 : 0;
node->numC = (seq[l] == ALPHABET[2]) ? 1 : 0;
node->numM = (seq[l] == seqT[l]) ? 1 : 0;
} else {
int m = l + (r - l) / 2;
node->lchild = create_tree(seq, l, m);
node->rchild = create_tree(seq, m, r);
node->numA = node->lchild->numA + node->rchild->numA;
node->numB = node->lchild->numB + node->rchild->numB;
node->numC = node->lchild->numC + node->rchild->numC;
node->numM = node->lchild->numM + node->rchild->numM;
}
return node;
}
void update_lazy(struct node *node) {
if(node->lazy_c < 0) return;
switch(node->lazy_c) {
case(ALPHABET[0]): { node->numM = node->numA; } break;
case(ALPHABET[1]): { node->numM = node->numB; } break;
case(ALPHABET[2]): { node->numM = node->numC; } break;
default: assert(false);
}
if(node->lchild != NULL) node->lchild->lazy_c = node->lazy_c;
if(node->rchild != NULL) node->rchild->lazy_c = node->lazy_c;
node->lazy_c = -1;
}
void update_tree(struct node *node, int l, int r, char c) {
update_lazy(node);
assert(0 <= l && l < r && r <= seq_len);
assert(0 <= node->left && node->left < node->right && node->right <= seq_len);
if(r <= node->left || node->right <= l) return;
if(l <= node->left && node->right <= r) {
node->lazy_c = c;
update_lazy(node);
return;
}
assert(node->lchild != NULL && node->rchild != NULL);
update_tree(node->lchild, l, r, c);
update_tree(node->rchild, l, r, c);
node->numM = node->lchild->numM + node->rchild->numM;
}
void check_seq(const char *seq) {
struct node *tree = create_tree(seq);
for(int m = -1; m < num_mods; m++) {
if(m >= 0) update_tree(tree, mods[m].left, mods[m].right, mods[m].chr);
assert(0 <= tree->numM && tree->numM <= seq_len);
posbl[m+1] = posbl[m+1] || tree->numM == seq_len;
}
}
int main() {
assert(scanf("%d", &seq_len) == 1);
assert(1 <= seq_len && seq_len <= MAX_N);
assert(scanf("%" strfy(MAX_N) "s", seqA) == 1);
validate(seqA);
assert(scanf("%" strfy(MAX_N) "s", seqB) == 1);
validate(seqB);
assert(scanf("%" strfy(MAX_N) "s", seqC) == 1);
validate(seqC);
cross(seqA, seqB, seqAB);
cross(seqB, seqC, seqBC);
cross(seqA, seqC, seqAC);
cross(seqAB, seqC, seqABC);
cross(seqBC, seqA, seqBCA);
cross(seqAC, seqB, seqACB);
assert(scanf("%d", &num_mods) == 1);
assert(1 <= num_mods && num_mods <= MAX_Q);
assert(scanf("%" strfy(MAX_N) "s", seqT) == 1);
validate(seqT);
posbl[0] = false;
for(int m = 0; m < num_mods; m++) {
int l, r;
char c;
assert(scanf("%d %d %c", &l, &r, &c) == 3);
assert(1 <= l && l <= r && r <= seq_len);
assert(c == ALPHABET[0] || c == ALPHABET[1] || c == ALPHABET[2]);
mods[m].left = l-1;
mods[m].right = r;
mods[m].chr = c;
posbl[m+1] = false;
}
check_seq(seqA);
check_seq(seqB);
check_seq(seqC);
check_seq(seqAB);
check_seq(seqBC);
check_seq(seqAC);
check_seq(seqABC);
check_seq(seqBCA);
check_seq(seqACB);
for(int m = 0; m <= num_mods; m++) {
if(posbl[m]) puts("Yes");
else puts("No");
}
return EXIT_SUCCESS;
}
Compilation message
In file included from Main.cpp:4:
Main.cpp: In function 'void validate(const char*)':
Main.cpp:29:24: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
29 | assert(strlen(seq) == seq_len);
| ~~~~~~~~~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
377 ms |
4592 KB |
Output is correct |
2 |
Correct |
434 ms |
4920 KB |
Output is correct |
3 |
Correct |
406 ms |
4784 KB |
Output is correct |
4 |
Correct |
348 ms |
4780 KB |
Output is correct |
5 |
Correct |
286 ms |
4812 KB |
Output is correct |
6 |
Correct |
315 ms |
4680 KB |
Output is correct |
7 |
Correct |
303 ms |
4844 KB |
Output is correct |
8 |
Correct |
314 ms |
4924 KB |
Output is correct |
9 |
Correct |
340 ms |
4916 KB |
Output is correct |
10 |
Correct |
367 ms |
4916 KB |
Output is correct |
11 |
Correct |
338 ms |
4984 KB |
Output is correct |
12 |
Correct |
328 ms |
4972 KB |
Output is correct |
13 |
Correct |
336 ms |
4912 KB |
Output is correct |
14 |
Correct |
312 ms |
4912 KB |
Output is correct |
15 |
Correct |
351 ms |
5004 KB |
Output is correct |
16 |
Correct |
324 ms |
4920 KB |
Output is correct |
17 |
Correct |
335 ms |
4960 KB |
Output is correct |
18 |
Correct |
354 ms |
4816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
377 ms |
4592 KB |
Output is correct |
2 |
Correct |
434 ms |
4920 KB |
Output is correct |
3 |
Correct |
406 ms |
4784 KB |
Output is correct |
4 |
Correct |
348 ms |
4780 KB |
Output is correct |
5 |
Correct |
286 ms |
4812 KB |
Output is correct |
6 |
Correct |
315 ms |
4680 KB |
Output is correct |
7 |
Correct |
303 ms |
4844 KB |
Output is correct |
8 |
Correct |
314 ms |
4924 KB |
Output is correct |
9 |
Correct |
340 ms |
4916 KB |
Output is correct |
10 |
Correct |
367 ms |
4916 KB |
Output is correct |
11 |
Correct |
338 ms |
4984 KB |
Output is correct |
12 |
Correct |
328 ms |
4972 KB |
Output is correct |
13 |
Correct |
336 ms |
4912 KB |
Output is correct |
14 |
Correct |
312 ms |
4912 KB |
Output is correct |
15 |
Correct |
351 ms |
5004 KB |
Output is correct |
16 |
Correct |
324 ms |
4920 KB |
Output is correct |
17 |
Correct |
335 ms |
4960 KB |
Output is correct |
18 |
Correct |
354 ms |
4816 KB |
Output is correct |
19 |
Correct |
2142 ms |
27756 KB |
Output is correct |
20 |
Correct |
1586 ms |
27788 KB |
Output is correct |
21 |
Correct |
1193 ms |
26224 KB |
Output is correct |
22 |
Correct |
1254 ms |
24040 KB |
Output is correct |
23 |
Correct |
610 ms |
6780 KB |
Output is correct |
24 |
Correct |
662 ms |
6764 KB |
Output is correct |
25 |
Correct |
1308 ms |
27848 KB |
Output is correct |
26 |
Correct |
1380 ms |
27816 KB |
Output is correct |
27 |
Correct |
1680 ms |
27748 KB |
Output is correct |
28 |
Correct |
1816 ms |
27744 KB |
Output is correct |
29 |
Correct |
1612 ms |
27088 KB |
Output is correct |
30 |
Correct |
767 ms |
6784 KB |
Output is correct |
31 |
Correct |
1530 ms |
27740 KB |
Output is correct |
32 |
Correct |
1653 ms |
25704 KB |
Output is correct |
33 |
Correct |
640 ms |
6744 KB |
Output is correct |
34 |
Correct |
1814 ms |
27736 KB |
Output is correct |
35 |
Correct |
1330 ms |
21876 KB |
Output is correct |
36 |
Correct |
646 ms |
6772 KB |
Output is correct |
37 |
Correct |
701 ms |
6792 KB |
Output is correct |
38 |
Correct |
1385 ms |
27528 KB |
Output is correct |
39 |
Correct |
549 ms |
27796 KB |
Output is correct |
40 |
Correct |
1324 ms |
20276 KB |
Output is correct |
41 |
Correct |
2424 ms |
28008 KB |
Output is correct |
42 |
Correct |
160 ms |
27232 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
377 ms |
4592 KB |
Output is correct |
2 |
Correct |
434 ms |
4920 KB |
Output is correct |
3 |
Correct |
406 ms |
4784 KB |
Output is correct |
4 |
Correct |
348 ms |
4780 KB |
Output is correct |
5 |
Correct |
286 ms |
4812 KB |
Output is correct |
6 |
Correct |
315 ms |
4680 KB |
Output is correct |
7 |
Correct |
303 ms |
4844 KB |
Output is correct |
8 |
Correct |
314 ms |
4924 KB |
Output is correct |
9 |
Correct |
340 ms |
4916 KB |
Output is correct |
10 |
Correct |
367 ms |
4916 KB |
Output is correct |
11 |
Correct |
338 ms |
4984 KB |
Output is correct |
12 |
Correct |
328 ms |
4972 KB |
Output is correct |
13 |
Correct |
336 ms |
4912 KB |
Output is correct |
14 |
Correct |
312 ms |
4912 KB |
Output is correct |
15 |
Correct |
351 ms |
5004 KB |
Output is correct |
16 |
Correct |
324 ms |
4920 KB |
Output is correct |
17 |
Correct |
335 ms |
4960 KB |
Output is correct |
18 |
Correct |
354 ms |
4816 KB |
Output is correct |
19 |
Correct |
432 ms |
4744 KB |
Output is correct |
20 |
Correct |
438 ms |
4788 KB |
Output is correct |
21 |
Correct |
345 ms |
5000 KB |
Output is correct |
22 |
Correct |
284 ms |
4476 KB |
Output is correct |
23 |
Correct |
324 ms |
4912 KB |
Output is correct |
24 |
Correct |
325 ms |
4804 KB |
Output is correct |
25 |
Correct |
338 ms |
4912 KB |
Output is correct |
26 |
Correct |
311 ms |
4796 KB |
Output is correct |
27 |
Correct |
315 ms |
4908 KB |
Output is correct |
28 |
Correct |
283 ms |
4540 KB |
Output is correct |
29 |
Correct |
347 ms |
4916 KB |
Output is correct |
30 |
Correct |
277 ms |
4616 KB |
Output is correct |
31 |
Correct |
370 ms |
4944 KB |
Output is correct |
32 |
Correct |
304 ms |
4880 KB |
Output is correct |
33 |
Correct |
375 ms |
4916 KB |
Output is correct |
34 |
Correct |
288 ms |
4676 KB |
Output is correct |
35 |
Correct |
345 ms |
4916 KB |
Output is correct |
36 |
Correct |
334 ms |
4908 KB |
Output is correct |
37 |
Correct |
340 ms |
4912 KB |
Output is correct |
38 |
Correct |
354 ms |
4968 KB |
Output is correct |
39 |
Correct |
317 ms |
4908 KB |
Output is correct |
40 |
Correct |
357 ms |
4952 KB |
Output is correct |
41 |
Correct |
319 ms |
5036 KB |
Output is correct |
42 |
Correct |
329 ms |
4992 KB |
Output is correct |
43 |
Correct |
326 ms |
4904 KB |
Output is correct |
44 |
Correct |
329 ms |
4900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
377 ms |
4592 KB |
Output is correct |
2 |
Correct |
434 ms |
4920 KB |
Output is correct |
3 |
Correct |
406 ms |
4784 KB |
Output is correct |
4 |
Correct |
348 ms |
4780 KB |
Output is correct |
5 |
Correct |
286 ms |
4812 KB |
Output is correct |
6 |
Correct |
315 ms |
4680 KB |
Output is correct |
7 |
Correct |
303 ms |
4844 KB |
Output is correct |
8 |
Correct |
314 ms |
4924 KB |
Output is correct |
9 |
Correct |
340 ms |
4916 KB |
Output is correct |
10 |
Correct |
367 ms |
4916 KB |
Output is correct |
11 |
Correct |
338 ms |
4984 KB |
Output is correct |
12 |
Correct |
328 ms |
4972 KB |
Output is correct |
13 |
Correct |
336 ms |
4912 KB |
Output is correct |
14 |
Correct |
312 ms |
4912 KB |
Output is correct |
15 |
Correct |
351 ms |
5004 KB |
Output is correct |
16 |
Correct |
324 ms |
4920 KB |
Output is correct |
17 |
Correct |
335 ms |
4960 KB |
Output is correct |
18 |
Correct |
354 ms |
4816 KB |
Output is correct |
19 |
Correct |
2142 ms |
27756 KB |
Output is correct |
20 |
Correct |
1586 ms |
27788 KB |
Output is correct |
21 |
Correct |
1193 ms |
26224 KB |
Output is correct |
22 |
Correct |
1254 ms |
24040 KB |
Output is correct |
23 |
Correct |
610 ms |
6780 KB |
Output is correct |
24 |
Correct |
662 ms |
6764 KB |
Output is correct |
25 |
Correct |
1308 ms |
27848 KB |
Output is correct |
26 |
Correct |
1380 ms |
27816 KB |
Output is correct |
27 |
Correct |
1680 ms |
27748 KB |
Output is correct |
28 |
Correct |
1816 ms |
27744 KB |
Output is correct |
29 |
Correct |
1612 ms |
27088 KB |
Output is correct |
30 |
Correct |
767 ms |
6784 KB |
Output is correct |
31 |
Correct |
1530 ms |
27740 KB |
Output is correct |
32 |
Correct |
1653 ms |
25704 KB |
Output is correct |
33 |
Correct |
640 ms |
6744 KB |
Output is correct |
34 |
Correct |
1814 ms |
27736 KB |
Output is correct |
35 |
Correct |
1330 ms |
21876 KB |
Output is correct |
36 |
Correct |
646 ms |
6772 KB |
Output is correct |
37 |
Correct |
701 ms |
6792 KB |
Output is correct |
38 |
Correct |
1385 ms |
27528 KB |
Output is correct |
39 |
Correct |
549 ms |
27796 KB |
Output is correct |
40 |
Correct |
1324 ms |
20276 KB |
Output is correct |
41 |
Correct |
2424 ms |
28008 KB |
Output is correct |
42 |
Correct |
160 ms |
27232 KB |
Output is correct |
43 |
Correct |
432 ms |
4744 KB |
Output is correct |
44 |
Correct |
438 ms |
4788 KB |
Output is correct |
45 |
Correct |
345 ms |
5000 KB |
Output is correct |
46 |
Correct |
284 ms |
4476 KB |
Output is correct |
47 |
Correct |
324 ms |
4912 KB |
Output is correct |
48 |
Correct |
325 ms |
4804 KB |
Output is correct |
49 |
Correct |
338 ms |
4912 KB |
Output is correct |
50 |
Correct |
311 ms |
4796 KB |
Output is correct |
51 |
Correct |
315 ms |
4908 KB |
Output is correct |
52 |
Correct |
283 ms |
4540 KB |
Output is correct |
53 |
Correct |
347 ms |
4916 KB |
Output is correct |
54 |
Correct |
277 ms |
4616 KB |
Output is correct |
55 |
Correct |
370 ms |
4944 KB |
Output is correct |
56 |
Correct |
304 ms |
4880 KB |
Output is correct |
57 |
Correct |
375 ms |
4916 KB |
Output is correct |
58 |
Correct |
288 ms |
4676 KB |
Output is correct |
59 |
Correct |
345 ms |
4916 KB |
Output is correct |
60 |
Correct |
334 ms |
4908 KB |
Output is correct |
61 |
Correct |
340 ms |
4912 KB |
Output is correct |
62 |
Correct |
354 ms |
4968 KB |
Output is correct |
63 |
Correct |
317 ms |
4908 KB |
Output is correct |
64 |
Correct |
357 ms |
4952 KB |
Output is correct |
65 |
Correct |
319 ms |
5036 KB |
Output is correct |
66 |
Correct |
329 ms |
4992 KB |
Output is correct |
67 |
Correct |
326 ms |
4904 KB |
Output is correct |
68 |
Correct |
329 ms |
4900 KB |
Output is correct |
69 |
Correct |
1842 ms |
23772 KB |
Output is correct |
70 |
Correct |
1657 ms |
27660 KB |
Output is correct |
71 |
Correct |
650 ms |
6852 KB |
Output is correct |
72 |
Correct |
676 ms |
6800 KB |
Output is correct |
73 |
Correct |
626 ms |
6852 KB |
Output is correct |
74 |
Correct |
1173 ms |
23772 KB |
Output is correct |
75 |
Correct |
635 ms |
6752 KB |
Output is correct |
76 |
Correct |
1316 ms |
27836 KB |
Output is correct |
77 |
Correct |
1248 ms |
23976 KB |
Output is correct |
78 |
Correct |
612 ms |
6764 KB |
Output is correct |
79 |
Correct |
630 ms |
6784 KB |
Output is correct |
80 |
Correct |
1089 ms |
21116 KB |
Output is correct |
81 |
Correct |
624 ms |
6744 KB |
Output is correct |
82 |
Correct |
1406 ms |
27748 KB |
Output is correct |
83 |
Correct |
1298 ms |
26384 KB |
Output is correct |
84 |
Correct |
628 ms |
6756 KB |
Output is correct |
85 |
Correct |
642 ms |
6744 KB |
Output is correct |
86 |
Correct |
1555 ms |
22224 KB |
Output is correct |
87 |
Correct |
1789 ms |
27736 KB |
Output is correct |
88 |
Correct |
800 ms |
6776 KB |
Output is correct |
89 |
Correct |
1510 ms |
24840 KB |
Output is correct |
90 |
Correct |
1618 ms |
27844 KB |
Output is correct |
91 |
Correct |
716 ms |
6760 KB |
Output is correct |
92 |
Correct |
1181 ms |
22140 KB |
Output is correct |
93 |
Correct |
633 ms |
6804 KB |
Output is correct |
94 |
Correct |
653 ms |
6776 KB |
Output is correct |
95 |
Correct |
643 ms |
6784 KB |
Output is correct |
96 |
Correct |
1317 ms |
27524 KB |
Output is correct |
97 |
Correct |
518 ms |
27844 KB |
Output is correct |
98 |
Correct |
1264 ms |
20272 KB |
Output is correct |
99 |
Correct |
2250 ms |
28068 KB |
Output is correct |
100 |
Correct |
112 ms |
27288 KB |
Output is correct |