Palindrome Strings
시간 제한2초메모리 제한2048 MB
고정된 문자열 S와 q개의 질의 문자열 t가 주어질 때, t 뒤에 S[l..r]을 이어 붙인 문자열이 회문이 되는 (l, r) 쌍의 개수를 각 질의마다 구한다.
문제
You are given a string and queries. In each query, a string is given, and you should determine the number of pairs such that and the combined string is a palindrome, which means that
입력
The first line contains two integers and (, ) denoting the length of string and the number of queries, respectively.
The second line contains a single string .
Each of the following lines contains a single string denoting a query.
It is guaranteed that all the strings only contain lowercase English letters and that .
출력
For each query, output a single line containing one integer: the required number of pairs.
힌트
- For the first query, the 4 pairs are , , , and , and the combined strings are "
pcp", "pp", "pmp", "pp", respectively. - For the second query, the 7 pairs are , , , , , , and .
- For the third query, the 4 pairs are , , , and .