/
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 525 点
問題文
長さ N の A, B からなる文字列 S が与えられます。
以下のクエリを合計 Q 個処理してください。
1 i c
タイプ 1 : S の i 文字目を c に変更する。
2 l r
タイプ 2 :
文字列 T を、現在の文字列 S の l 文字目から r 文字目までを抜き出した文字列とする。
文字列 T が以下の操作で得られる文字列であれば Yes 、そうでなければ No と出力する。
- 空文字列から始め、以下の 2 つの操作を好きな順序で 0 回以上何回でも行う。
- 文字列の(先頭・末尾を含めた)任意の箇所を選択し、そこに
Aを挿入する。- 文字列の(先頭・末尾を含めた)任意の箇所を選択し、そこに
ABを挿入する。
制約
- N は 1 \le N \le 5 \times 10^5 を満たす整数
- S は
A,Bからなる長さ N の文字列 - Q は 1 \le Q \le 2 \times 10^5 を満たす整数
- 与えられるクエリはタイプ 1,2 のいずれかである
- タイプ 1 のクエリは以下の制約を満たす
- i は 1 \le i \le N を満たす整数
- c は
A,Bのいずれか
- タイプ 2 のクエリは以下の制約を満たす
- l,r は 1 \le l \le r \le N を満たす整数
入力
入力は以下の形式で標準入力から与えられる。
N
S
Q
{\rm Query}_1
{\rm Query}_2
\vdots
{\rm Query}_Q
但し、 {\rm Query}_i は i 個目のクエリを表し、クエリの入力は問題文中の形式に従う。
出力
タイプ 2 のクエリが入力されるごとに、答えを 1 行に出力せよ。
入力例 1
10 AABBAABABB 6 2 1 10 1 5 B 2 1 10 2 6 8 1 3 A 2 1 10
出力例 1
Yes No Yes Yes
この入力には 6 個のクエリが含まれます。
- 最初、 S=
AABBAABABBです。 - 1 つ目のクエリについて、 S の 1 文字目から 10 文字目までを抜き出した T=
AABBAABABBは以下の手順を踏むことで得ることができるため、Yesと出力します。- 空文字列から始める。
- 空文字列の先頭に
ABを挿入し、文字列がABとなる。 ABの 1 文字目の直後にABを挿入し、文字列がAABBとなる。AABBの末尾にABを挿入し、文字列がAABBABとなる。AABBABの 5 文字目の直後にABを挿入し、文字列がAABBAABBとなる。AABBAABBの 7 文字目の直後にABを挿入し、文字列がAABBAABABBとなる。
- 2 つ目のクエリについて、 S の 5 文字目を
Bに変更します。その結果、 S=AABBBABABBとなります。 - 3 つ目のクエリについて、 S の 1 文字目から 10 文字目までを抜き出した T=
AABBBABABBは問題文中の操作では得られないため、Noと出力します。 - 4 つ目のクエリについて、 S の 6 文字目から 8 文字目までを抜き出した T=
ABAは問題文中の操作で得ることができるため、Yesと出力します。 - 5 つ目のクエリについて、 S の 3 文字目を
Aに変更します。その結果、 S=AAABBABABBとなります。 - 6 つ目のクエリについて、 S の 1 文字目から 10 文字目までを抜き出した T=
AAABBABABBは問題文中の操作で得ることができるため、Yesと出力します。
Score : 525 points
Problem Statement
You are given a string S of length N consisting of A and B.
Process a total of Q queries of the following types.
1 i c
Type 1: Change the i-th character of S to c.
2 l r
Type 2:
Let string T be the string obtained by extracting the l-th through r-th characters of the current string S.
If it is possible to obtain string T by the following operation, output Yes; otherwise, output No.
- Starting from the empty string, perform the following two operations any number of times, possibly zero, in any order.
- Choose any position in the string (possibly the beginning or the end) and insert
Athere.- Choose any position in the string (possibly the beginning or the end) and insert
ABthere.
Constraints
- N is an integer satisfying 1 \le N \le 5 \times 10^5.
- S is a string of length N consisting of
AandB. - Q is an integer satisfying 1 \le Q \le 2 \times 10^5.
- Each given query is of type 1 or 2.
- Queries of type 1 satisfy the following constraints:
- i is an integer satisfying 1 \le i \le N, and
- c is
AorB.
- Queries of type 2 satisfy the following constraints:
- l and r are integers satisfying 1 \le l \le r \le N.
Input
The input is given from Standard Input in the following format:
N
S
Q
{\rm Query}_1
{\rm Query}_2
\vdots
{\rm Query}_Q
Here, {\rm Query}_i represents the i-th query, and the input format for a query follows the format described in the problem statement.
Output
Each time a query of type 2 is given, output the answer on one line.
Sample Input 1
10 AABBAABABB 6 2 1 10 1 5 B 2 1 10 2 6 8 1 3 A 2 1 10
Sample Output 1
Yes No Yes Yes
This input contains six queries.
- Initially, S=
AABBAABABB. - For the 1-st query, T=
AABBAABABB, obtained by extracting the 1-st through 10-th characters of S, can be obtained by the following steps, so outputYes.- Start from the empty string.
- Insert
ABat the beginning of the empty string, making the stringAB. - Insert
ABright after the 1-st character ofAB, making the stringAABB. - Insert
ABat the end ofAABB, making the stringAABBAB. - Insert
ABright after the 5-th character ofAABBAB, making the stringAABBAABB. - Insert
ABright after the 7-th character ofAABBAABB, making the stringAABBAABABB.
- For the 2-nd query, change the 5-th character of S to
B. As a result, S=AABBBABABB. - For the 3-rd query, T=
AABBBABABB, obtained by extracting the 1-st through 10-th characters of S, cannot be obtained by the operation described in the problem statement, so outputNo. - For the 4-th query, T=
ABA, obtained by extracting the 6-th through 8-th characters of S, can be obtained by the operation described in the problem statement, so outputYes. - For the 5-th query, change the 3-rd character of S to
A. As a result, S=AAABBABABB. - For the 6-th query, T=
AAABBABABB, obtained by extracting the 1-st through 10-th characters of S, can be obtained by the operation described in the problem statement, so outputYes.