AT_abc473_f.A/AB Insertion
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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.
给你一个长度为 N 的字符串 S,其字符仅由 A 和 B 组成。
你需要处理总共 Q 个如下类型的查询。
1 i c
类型 1:将字符串 S 的第 i 个字符修改为 c。
2 l r
类型 2:
令字符串 T 为当前字符串 S 中从第 l 个字符到第 r 个字符(含)所构成的子串。
若字符串 T 可通过以下操作得到,则输出 Yes;否则输出 No。
- 从空字符串出发,可任意次数(包括零次)、以任意顺序执行以下两种操作:
- 在字符串的任意位置(可以是开头或结尾)插入字符
A;- 在字符串的任意位置(可以是开头或结尾)插入字符串
AB。
输入格式
The input is given from Standard Input in the following format:
N
S
Q
Query1
Query2
⋮
QueryQ
Here, Queryi represents the i-th query, and the input format for a query follows the format described in the problem statement.
输入从标准输入中按以下格式给出:
N
S
Q
Query1
Query2
⋮
QueryQ
其中,Queryi 表示第 i 个查询,每个查询的输入格式遵循题目描述中所规定的格式。
输出格式
Each time a query of type 2 is given, output the answer on one line.
每次给出类型为 2 的查询时,在一行中输出答案。
输入输出样例
输入#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
说明/提示
Sample 1 Explanation:
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.
Constraints
- N is an integer satisfying 1≤N≤5×105.
- S is a string of length N consisting of
AandB. - Q is an integer satisfying 1≤Q≤2×105.
- Each given query is of type 1 or 2.
- Queries of type 1 satisfy the following constraints:
- i is an integer satisfying 1≤i≤N, and
- c is
AorB.
- Queries of type 2 satisfy the following constraints:
- l and r are integers satisfying 1≤l≤r≤N.
样例 1 解释:
该输入包含六个查询。
- 初始时,S=
AABBAABABB。 - 对于第 1 个查询,T=
AABBAABABB(通过提取 S 的第 1 至第 10 个字符得到),可通过以下步骤构造,因此输出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 个查询,T=
AABBBABABB(通过提取 S 的第 1 至第 10 个字符得到),无法通过题目描述的操作构造,因此输出No。 - 对于第 4 个查询,T=
ABA(通过提取 S 的第 6 至第 8 个字符得到),可由题目描述的操作构造,因此输出Yes。 - 对于第 5 个查询,将 S 的第 3 个字符修改为
A,于是 S=AAABBABABB。 - 对于第 6 个查询,T=
AAABBABABB(通过提取 S 的第 1 至第 10 个字符得到),可由题目描述的操作构造,因此输出Yes。
约束条件
- N 是满足 1≤N≤5×105 的整数。
- S 是一个长度为 N、仅由字符
A和B组成的字符串。 - Q 是满足 1≤Q≤2×105 的整数。
- 每个给定查询的类型为 1 或 2。
- 类型 1 的查询满足以下约束:
- i 是满足 1≤i≤N 的整数;
- c 为
A或B。
- 类型 2 的查询满足以下约束:
- l 和 r 是满足 1≤l≤r≤N 的整数。
输入解题思路,AI测评打分。不知道怎么写?