Palindrome
Time limit2sMemory limit512 MB
Given a string s, each query concatenates the length-l substrings starting at the listed positions and asks for the number of palindromic substrings of the result.
- Level
Hard9 of 10
- Topics
- String, String matching, Math
- Solved
- No attempts yet
Problem
A palindromic string is a string that reads the same forward and backward.
Yuuka has a string and wants to ask some questions about it. In each question, Yuuka gives a list of integers (where is 1-indexed) and an integer . Let denote the substring of of length that starts at position . Let be the concatenation of . Yuuka wants to know the total number of palindromic substrings of .
Input
The input contains zero or more test cases and ends at end-of-file. Each test case is as follows.
The first line contains the length of the string ().
The second line contains integers that denote the string (). Yuuka's alphabet may be large, so each character is written as an integer from 1 to .
The third line contains the number of questions ().
Each of the next lines contains two integers and , followed by integers (, , , ).
The sum of all and the sum of all do not exceed .
Output
For each question, output the number of palindromic substrings of as an integer.