#B3703. Substring Predecessor Queries
Substring Predecessor Queries
Substring Predecessor Queries
Fusu receives a string \(s\) consisting only of lowercase letters. For any string \(t\) of length \(x\) consisting of lowercase letters, we define the previous string of \(t\) as the string that immediately precedes \(t\) in the lexicographical order of all strings of length \(x\) composed only of lowercase letters. For example, the previous string of bcd
is bcc
, while aaa
does not have a previous string.
Fusu has \(q\) queries. Each query provides an interval \([l, r]\) and asks: Does the previous string of the substring formed by the \(l\)th to the \(r\)th characters of \(s\) occur anywhere in \(s\) as a contiguous substring? If the substring does not have a previous string, answer it as if the previous string does not appear in \(s\).
inputFormat
The first line contains the string \(s\). The second line contains an integer \(q\), the number of queries. Each of the following \(q\) lines contains two integers \(l\) and \(r\) (1-indexed) representing a query. The substring from the \(l\)th to the \(r\)th character of \(s\) forms the string \(t\).
outputFormat
For each query, print Yes
if the previous string of \(t\) appears in \(s\) as a contiguous substring, otherwise print No
. If \(t\) does not have a previous string, output No
.
sample
abc
2
1 2
2 3
No
No
</p>