#K33537. Palindrome Substring Query
Palindrome Substring Query
Palindrome Substring Query
You are given a string (S) and (Q) queries. Each query consists of two integers (L) and (R). For each query, your task is to determine whether the substring (S[L \ldots R]) (using 1-indexing) is a palindrome. A palindrome is a string that reads the same forwards and backwards. Print "YES" if the substring is a palindrome, otherwise print "NO".
For example, if (S = \texttt{abccba}) and the queries are ((1, 6)), ((2, 4)), and ((3, 5)), then the outputs should be:
- For the substring from 1 to 6 (i.e., "abccba"): (YES) because "abccba" is a palindrome.
- For the substring from 2 to 4 (i.e., "bcc"): (NO) because "bcc" reversed is "ccb".
- For the substring from 3 to 5 (i.e., "ccb"): (NO) because "ccb" reversed is "bcc".
The input is provided via standard input and the output should be printed to standard output.
inputFormat
The first line of input contains the string (S). The second line contains an integer (Q), the number of queries. This is followed by (Q) lines, each containing two space-separated integers (L) and (R) representing the bounds of the substring (1-indexed).
outputFormat
For each query, output a single line containing "YES" if the specified substring is a palindrome, and "NO" otherwise.## sample
abccba
3
1 6
2 4
3 5
YES
NO
NO
</p>