102855: [AtCoder]ABC285 F - Substring of Sorted String
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Score : $500$ points
Problem Statement
You are given a string $S$ of length $N$ consisting of lowercase English letters, and $Q$ queries. Process the queries in order.
Each query is of one of the following two kinds:
1 x c
: replace the $x$-th character of $S$ by the character $c$.2 l r
: let $T$ be the string obtained by sorting the characters of $S$ in ascending order. PrintYes
if the string consisting of the $l$-th through $r$-th characters of $S$ is a substring of $T$; printNo
otherwise.
What is a substring?
A substring of $S$ is a string obtained by removing $0$ or more initial characters and $0$ or more final characters of $S$. For example,ab
is a substring of abc
, while ac
is not a substring of abc
.
Constraints
- $1\leq N \leq 10^5$
- $S$ is a string of length $N$ consisting of lowercase English letters.
- $1 \leq Q \leq 10^5$
- For each query of the first kind, $1 \leq x \leq N$.
- For each query of the first kind, $c$ is a lowercase English letter.
- For each query of the second kind, $1 \leq l \leq r \leq N$.
Input
The input is given from Standard Input in the following format, where $\text{query}_i$ denotes the $i$-th query:
$N$ $S$ $Q$ $\text{query}_1$ $\text{query}_2$ $\vdots$ $\text{query}_Q$
Output
Process the queries as instructed in the Problem Statement.
Sample Input 1
6 abcdcf 4 2 1 3 2 2 6 1 5 e 2 2 6
Sample Output 1
Yes No Yes
- In the $1$-st query,
abccdf
is the string $T$ obtained by sorting the characters of $S$ in ascending order. The stringabc
, consisting of the $1$-st through $3$-rd characters of $S$, is a substring of $T$, soYes
should be printed. - In the $2$-nd query,
abccdf
is the string $T$ obtained by sorting the characters of $S$ in ascending order. The stringbcdcf
, consisting of the $2$-nd through $6$-th characters of $S$, is not a substring of $T$, soNo
should be printed. - The $3$-rd query sets the $5$-th character of $S$ to
e
, making $S$abcdef
. - In the $4$-th query,
abcdef
is the string $T$ obtained by sorting the characters of $S$ in ascending order. The stringbcdef
, consisting of the $2$-nd through $6$-th characters of $S$, is a substring of $T$, soYes
should be printed.
Input
题意翻译
给定一个长度为 $N$ 的字符串 $S$,下标从 $1$ 开始,有以下两种操作: - `1 x c`:将字符串 $S$ 中的第 $x$ 个字符替换为 $c$。 - `2 l r`:将 $S$ 中的字符按升序排列,得到新字符串 $T$,询问串 $S_{l,l+1,...,r}$ 是否为 $T$ 的子串。 对于每个操作 $2$,输出 `Yes` 或者 `No` 表示结果。Output
得分:500分
问题描述
你将得到一个长度为$N$的字符串$S$,由小写英文字母组成,以及$Q$个查询。按顺序处理这些查询。
每个查询分为以下两种类型之一:
1 x c
:将字符串$S$中的第$x$个字符替换为字符$c$。2 l r
:设$T$是通过按升序排列字符串$S$中的字符得到的字符串。如果由$S$中的第$l$个到第$r$个字符组成的字符串是$T$的子串,则打印Yes
;否则打印No
。
什么是子串?
一个字符串$S$的子串是指通过从$S$的开头移除$0$个或多个字符,以及从$S$的末尾移除$0$个或多个字符得到的字符串。 例如,ab
是abc
的子串,而ac
不是abc
的子串。
约束
- $1\leq N \leq 10^5$
- $S$是一个长度为$N$的字符串,由小写英文字母组成。
- $1 \leq Q \leq 10^5$
- 对于每个第一种类型的查询,$1 \leq x \leq N$。
- 对于每个第一种类型的查询,$c$是一个小写英文字母。
- 对于每个第二种类型的查询,$1 \leq l \leq r \leq N$。
输入
输入将以以下格式从标准输入给出,其中$\text{query}_i$表示第$i$个查询:
$N$ $S$ $Q$ $\text{query}_1$ $\text{query}_2$ $\vdots$ $\text{query}_Q$
输出
按照问题描述中的说明处理查询。
样例输入1
6 abcdcf 4 2 1 3 2 2 6 1 5 e 2 2 6
样例输出1
Yes No Yes
- 在第$1$个查询中,由按升序排列字符串$S$中的字符得到的字符串$T$是
abccdf
。 由$S$中的第$1$个到第$3$个字符组成的字符串abc
是$T$的子串,因此应该打印Yes
。 - 在第$2$个查询中,由按升序排列字符串$S$中的字符得到的字符串$T$是
abccdf
。 由$S$中的第$2$个到第$6$个字符组成的字符串bcdcf
不是$T$的子串,因此应该打印No
。 - 第$3$个查询将字符串$S$中的第$5$个字符设置为
e
,使$S$变为abcdef
。 - 在第$4$个查询中,由按升序排列字符串$S$中的字符得到的字符串$T$是
abcdef
。 由$S$中的第$2$个到第$6$个字符组成的字符串bcdef
是$T$的子串,因此应该打印Yes
。