#K66772. Palindrome Queries
Palindrome Queries
Palindrome Queries
You are given a string s
of length n and q queries. Each query consists of two integers l and r (1-indexed). For each query, you need to determine if the substring \(s[l:r]\) is a palindrome.
A string is a palindrome if it reads the same backward as forward. Formally, a substring \(s[l:r]\) is a palindrome if \(s[l:r] = \text{reverse}(s[l:r])\).
Example:
Input: 6 3 abccba 1 6 1 3 2 5</p>Output: Yes No Yes
In the above example, the full string "abccba" is a palindrome, the substring from index 1 to 3 ("abc") is not a palindrome, and the substring from index 2 to 5 ("bccb") is a palindrome.
inputFormat
The first line contains two integers n and q — the length of the string and the number of queries, respectively.
The second line contains the string s
.
The next q lines each contain two integers l and r representing the start and end positions (1-indexed) of the substring to be checked.
outputFormat
For each query, output a single line containing Yes
if the specified substring is a palindrome; otherwise, output No
.
6 3
abccba
1 6
1 3
2 5
Yes
No
Yes
</p>