#C4707. Taco Magical Substrings
Taco Magical Substrings
Taco Magical Substrings
You are given a string S and several queries. For each query, you are asked to determine whether the substring defined by indices i and j is magical. A substring S[i:j] (with i and j being 1-indexed) is magical if for every consecutive character pair in the substring the following condition holds:
\( |S[k] - S[k+1]| \le 1 \)
for all indices \( k \) from i to \( j-1 \). If the condition is satisfied for all adjacent pairs, output Yes
; otherwise, output No
.
Your task is to process multiple test cases. Each test case contains a string and a number of queries. For each query, output the result on a single line with the results of all queries for a test case printed on one line separated by a single space.
inputFormat
The input is read from stdin and has the following format:
T S₁ Q₁ i₁₁ j₁₁ i₁₂ j₁₂ ... S₂ Q₂ i₂₁ j₂₁ i₂₂ j₂₂ ... ...
Here, the first line contains an integer T denoting the number of test cases. For each test case, the first line contains the string S, the second line contains an integer Q (the number of queries), and each of the next Q lines contains two space-separated integers i and j (1-indexed) representing the start and end indices of the substring.
outputFormat
For each test case, output one line. This line should contain the answers for each query separated by a single space. Each answer is either Yes
if the specified substring is magical or No
otherwise. The output is written to stdout.
2
abcdefg
3
1 5
3 7
1 7
zxyab
2
1 3
2 5
Yes Yes Yes
No No
</p>