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 SA, SB, SC, respectively.

You can obtain a flower of new species from two flowers of new species by an operation called crossing. The i-th character (1iN) 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 c1 and c2, the i-th character c3 of the gene sequence of the new flower is given by the following table.

c1
c2
J
J
J
O
J
I
O
J
O
O
O
I
I
J
I
O
I
I
c3 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 T0 and, for each j (1jQ), integers Lj, Rj and a character Cj. The candidate gene sequences are given as follows:

  • The candidate gene sequence 0 is T0.
  • The candidate gene sequence j (1jQ) is obtained from the candidate gene sequence j1 by replacing the characters from the Lj-th position to the Rj-th position by the character Cj.

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

SA

SB

SC

Q

T0

L1 R1 C1

LQ RQ CQ

Output Specification

Write Q+1 lines to the standard output. In the (j+1)-th line (0jQ), 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

  • 1N200000.
  • SA, SB, SC are strings of length N. Each character is either J, O, or I.
  • 1Q200000.
  • T0 is a string of length N. Each character is either J, O, or I.
  • 1LjRjN (1jQ).
  • Cj is either J, O, or I (1jQ).

Subtasks

  1. (3 points) SA=SB=SC, N100.
  2. (23 points) SA=SB=SC.
  3. (23 points) N100.
  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. T0 is IJOJ. Since it is possible to obtain IJOJ by crossing JJOI with OJOO, output Yes.
  2. T1 is OOOO. Since it is impossible to obtain OOOO from the three initial flowers by crossing zero or more times, output No.
  3. T2 is OJOO. Since you have OJOO in the beginning without crossing, output Yes.
  4. T3 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. T0 is OJI. Since it is impossible to obtain this flower by crossing, output No.
  2. T1 is OOI. Since it is impossible to obtain this flower by crossing, output No.
  3. T2 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.