JOI '21 Open P1 - Crossing

View as PDF

Submit solution

Points: 20 (partial)
Time limit: 2.0s
Memory limit: 512M

Problem type

Do you know Just Odd Investigations Laboratory? The business of this laboratory is to do "just odd investigations." In the following, we call it JOI Laboratory for short.

In recent years, broad gardens with splendid flowers were discovered in several historical ruins in the world.

JOI Laboratory discovered that the flowers in these gardens are new species, and their genes have similar features. The genes of these new flowers are strings of length N consisting of J, O, I. These strings are called gene sequences.

You are a researcher working in JOI Laboratory. You initially have three flowers of new species. Their gene sequences are S_A, S_B, S_C, respectively.

You can obtain a flower of new species from two flowers of new species by an operation called crossing. The i-th character (1 \le i \le N) of the gene sequence of the new flower is determined by the following rule.

  • If the i-th characters of the gene sequences of the two flowers are the same, the i-th character of the gene sequence of the new flower will be the same character.
  • If the i-th characters of the gene sequences of the two flowers are different, the i-th character of the gene sequence of the new flower will be one of J, O, or I which is different from these two characters.

In other words, if the i-th characters of the gene sequences of the two flowers are c_1 and c_2, the i-th character c_3 of the gene sequence of the new flower is given by the following table.

c_1
c_2
J
J
J
O
J
I
O
J
O
O
O
I
I
J
I
O
I
I
c_3 J I O I O J O J I

You may use the same flower for crossing as many times as you want. If you obtain a new flower by crossing, you may use it for subsequent crossings.

In order to obtain more beautiful flowers, JOI Laboratory proposed Q+1 gene sequences numbered from 0 to Q as candidate gene sequences. You are given a list describing the candidate gene sequences. The list contains a string T_0 and, for each j (1 \le j \le Q), integers L_j, R_j and a character C_j. The candidate gene sequences are given as follows:

  • The candidate gene sequence 0 is T_0.
  • The candidate gene sequence j (1 \le j \le Q) is obtained from the candidate gene sequence j-1 by replacing the characters from the L_j-th position to the R_j-th position by the character C_j.

Write a program which, given an integer N, the gene sequences of the three initial flowers, and the list describing the candidate gene sequences, determines, for each candidate gene sequence, whether it is possible to obtain a flower whose gene sequence is the given one from the three initial flowers by crossing zero or more times.

Input Specification

Read the following data from the standard input:

N

S_A

S_B

S_C

Q

T_0

L_1\ R_1\ C_1

\vdots

L_Q\ R_Q\ C_Q

Output Specification

Write Q+1 lines to the standard output. In the (j+1)-th line (0 \le j \le Q), output Yes if it is possible to obtain a flower whose gene sequence is the candidate gene sequence j from the three initial flowers by crossing zero or more times. Otherwise, output No.

Constraints

  • 1 \le N \le 200\,000.
  • S_A, S_B, S_C are strings of length N. Each character is either J, O, or I.
  • 1 \le Q \le 200\,000.
  • T_0 is a string of length N. Each character is either J, O, or I.
  • 1 \le L_j \le R_j \le N (1 \le j \le Q).
  • C_j is either J, O, or I (1 \le j \le Q).

Subtasks

  1. (3 points) S_A = S_B = S_C, N \le 100.
  2. (23 points) S_A = S_B = S_C.
  3. (23 points) N \le 100.
  4. (51 points) No additional constraints.

Sample Input 1

4
JOJO
JJOI
OJOO
3
IJOJ
1 4 O
2 2 J
2 4 I

Sample Output 1

Yes
No
Yes
Yes

Explanation for Sample Output 1

The gene sequences of the three initial flowers are JOJO, JJOI, and OJOO. In the following, new flowers obtained by crossing are written as their gene sequences.

  1. T_0 is IJOJ. Since it is possible to obtain IJOJ by crossing JJOI with OJOO, output Yes.
  2. T_1 is OOOO. Since it is impossible to obtain OOOO from the three initial flowers by crossing zero or more times, output No.
  3. T_2 is OJOO. Since you have OJOO in the beginning without crossing, output Yes.
  4. T_3 is OIII. You can obtain IJOJ by crossing JJOI with OJOO. Then you can obtain OIII by crossing JOJO with IJOJ. Therefore, output Yes.

This sample input satisfies the constraints of Subtasks 3, 4.

Sample Input 2

3
JOI
JOI
JOI
2
OJI
1 2 O
1 1 J

Sample Output 2

No
No
Yes

Explanation for Sample Output 2

The gene sequences of the three initial flowers are JOI only. You can obtain JOI only by crossing.

  1. T_0 is OJI. Since it is impossible to obtain this flower by crossing, output No.
  2. T_1 is OOI. Since it is impossible to obtain this flower by crossing, output No.
  3. T_2 is JOI. Since it is possible to obtain this flower, output Yes.

This sample input satisfies the constraints of Subtasks 1, 2, 3, 4.


Comments

There are no comments at the moment.