아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Master Zhu and Palindromes

시간 제한2초메모리 제한512 MB

요약
각 질의 구간 S[L..R]에서 꼬리가 주어진 문자열 T로 시작하는 회문 부분 문자열의 개수를 센다.
난이도

보통10점 중 6점

유형
문자열, 해시맵, 누적 합, 구현
정답자
아직 제출이 없습니다

문제

Master Zhu has a string S\[1,…,n]S \[1, \ldots, n]. This string can contain only the first five lowercase English letters. Another peculiar property of SS is that the length of each palindrome substring in SS is less than 2020.

For a palindrome string P\[1,…,k]P \[1, \ldots, k], its tail is the string P\[⌊k/2⌋+1,…,k]P \[\lfloor k / 2 \rfloor + 1, \ldots, k]. For example, the tail of the string "aba" is "ba", and the tail of the string "caac" is "ac".

Given LL, RR, and a string TT, Master Zhu wants you to find the number of different palindrome substrings in S\[L,…,R]S \[L, \ldots, R] such that TT is a prefix of their tails. Here, two substrings are considered different if their starting or ending positions in SS differ.

입력

The first line of input contains one integer CC, the number of test cases (1≤C≤501 \le C \le 50).

The first line of each test case contains a string SS consisting only of the first five lowercase English letters (1≤∣S∣≤1051 \le |S| \le 10^5, the length of each palindrome substring in SS is less than 2020).

The second line contains one integer qq, the number of queries (1≤q≤1051 \le q \le 10^5). Each of the next qq lines contains two integers LL and RR and a string TT consisting only of the first five lowercase English letters (1≤L≤R≤∣S∣1 \le L \le R \le |S|, 1≤∣T∣≤101 \le |T| \le 10).

출력

For each query, print a single line with a single integer: the number of different palindrome substrings in S\[L,…,R]S \[L, \ldots, R] such that TT is a prefix of their tails.

예제1

  1. 예제 1

    입력
    1
    bceaeeddee
    5
    5 8 e
    3 5 e
    1 2 a
    5 9 d
    5 9 de
    
    예상 출력
    3
    2
    0
    4
    1