#P4979. CYJian's Mine Restoration

    ID: 18218 Type: Default 1000ms 256MiB

CYJian's Mine Restoration

CYJian's Mine Restoration

After CYJian's mine collapsed, he lost his only source of income (and don’t ask me why he never saved any money). In order to rebuild his mine, he needs to choose a continuous segment of materials to repair it. His mine produces three types of ore, namely \(A, B, C\), so he can only use these three materials.

You are given \(N\) tons of material, where each ton is one of the characters \(A\), \(B\) or \(C\). These materials are arranged in a string, for example:

[ ABCBCABCBACBCBAA ]

CYJian has very strict requirements. Every time he selects a continuous segment of the material for repair, the segment must satisfy the following two conditions:

  1. The materials in the chosen segment must all be the same.
  2. If the segment is not at the boundary (i.e. if it has a previous or next material), then the material immediately before the segment and the material immediately after the segment must be different from the material in the chosen segment.

Note: When \(x=1\) or \(y=N\) (i.e. the segment touches one of the boundaries), you only need to check the materials within the segment and the one adjacent on the inside (if applicable).

In addition, the materials are "alive" and can change. You will be given \(K\) queries on these \(N\) tons of material. Each query is one of the following two types:

  • A x y op: Replace all materials in the interval from index \(x\) to \(y\) (\(1 \le x \le y \le N\)) with the character \(op\) (which is one of \(A, B, C\)).
  • B x y: Check if the segment from index \(x\) to \(y\) (\(1 \le x \le y \le N\)) is valid according to the rules above. Print Yes if it is valid; otherwise, print No.

For queries of type B, if \(x=1\) or \(y=N\), you do not need to check the neighboring materials outside the segment; just ensure that all materials in the segment are the same.

inputFormat

The first line contains two integers \(N\) and \(K\) separated by a space.

The second line contains a string of length \(N\) consisting of characters \(A\), \(B\), and \(C\) representing the initial materials.

The next \(K\) lines each contain a query in one of the following formats:

  • A x y op: Replace the material in the interval \([x, y]\) with character \(op\).
  • B x y: Check if the segment \([x, y]\) is valid according to the problem conditions.

It is guaranteed that \(1 \le x \le y \le N\). For queries of type B, when \(x=1\) or \(y=N\), you only need to check the segment itself.

outputFormat

For each query of type B, output a single line containing either Yes or No depending on whether the selected segment is valid.

sample

10 5
AABBBCCAAA
B 1 2
B 3 5
A 1 3 C
B 1 3
B 8 10
Yes

No Yes Yes

</p>