luogu#P4979. 矿洞:坍塌

矿洞:坍塌

Background

  • Made By tomoo

Why is CYJian’s family so rich? Because his family&@%# runs a mine!!

Even if you have a mine, you cannot be reckless. Well, CYJian’s mine collapsed......

change: The setter kindly increased the memory limit.

Problem Description

After CYJian’s mine collapsed, he no longer has any source of income (do not ask me why he has no savings).

So CYJian urgently wants to repair his mine.

CYJian’s mine produces three kinds of ores: A,B,CA,B,C. Therefore, we can only use the three kinds of materials A,B,CA,B,C to repair the mine. We know there are a total of NN tons of materials. Each ton is one of A,B,CA,B,C, and they are connected into a string, for example:

ABCBCABCBACBCBAAABCBCABCBACBCBAA

CYJian has very strict requirements for the materials. Each time, he will choose a continuous interval of materials as the repair materials. Because unqualified materials may cause the mine to collapse again and kill CYJian, this continuous interval must satisfy the following 22 requirements:

  • This continuous interval must consist of only one kind of material.
  • The material immediately before this interval and the material immediately after this interval must be different.

For example, given a segment AACBBABBBCCCBBBAACBBABBBCCCBBB, the interval (45)(4 \sim 5) which is BBBB and the interval (55)(5 \sim 5) which is BB both satisfy the requirements, but the interval (1012)(10 \sim 12) which is CCCCCC does not.

The materials are “alive”, so they can change.

Now there are NN tons of materials and KK queries. Each query is one of the following two types:

  • A x y op means a replacement operation: replace the materials in the interval from xx to y(1xyN)y (1\leq x \leq y \leq N) with opop, where opop is one of the characters A,B,CA,B,C.
  • B x y means a check query: ask whether the materials in the interval from xx to y(1xyN)y(1\leq x \leq y \leq N) are valid. Output Yes if valid, otherwise output No.

Note: When x=1x=1 or y=Ny=N, your program does not need to check the outside neighbors, and only needs to check the interval itself.

Input Format

  • The first line contains a positive integer NN.
  • The next line contains NN characters, representing the materials.
  • Then follow KK queries, each in one of the formats above.

Output Format

For each query B x y, output one line Yes or No.

15
AACBBABBBCCCBBB
3
B 4 5
B 5 5
B 10 12
Yes
Yes
No
5
ABBBB
2
B 1 4
B 2 5
No
Yes

Hint

  • For 30%30\% of the testdata, N1000,K2000N\le1000,K\le2000.
  • For 70%70\% of the testdata, N5000,K5000N\le5000,K\le5000.
  • For 100%100\% of the testdata, $N\le5\cdot10^5,K\le5\cdot10^5, 1\leq x \leq y \leq N$.

Translated by ChatGPT 5