각 질의 (L, R)에서 가능한 모든 접두사와 접미사 분할에 대해 T가 나타나는 횟수를 세고, 기댓값에 L과 (n-R+1)을 곱해 출력한다.
어려움8문자열 매칭누적 합해시맵아직 제출이 없습니다시간 제한1초메모리 제한512 MBWhen chatting online, we can save what somebody said to form his classic quotation. Little Q does this, too. And what's more, he can even change the original words. Formally, assume somebody said a string S of length n. Little Q will choose a continuous substring of S (possibly empty) and remove it, then concatenate the two remaining parts, obtaining a new string S′. For example, he might remove "not " from the string "I am not SB", so that the new string S′ will be "I am SB".
After doing lots of such things, Little Q finds out that string T occurs as a continuous substring of S′ very often.
Now given strings S and T, Little Q has k queries. Each query has the following format: given L and R, Little Q will remove a substring so that the two remaining parts are S\[1..i] and S\[j..n] where the pair of integers (i,j) is chosen equiprobably among all pairs where 1≤i≤L and R≤j≤n. Your goal is to find E, the expected number of occurrences of T in the resulting string, and print the value E⋅L⋅(n−R+1).
All occurrences of T must taken into account even if they overlap. The queries are independent: the string S actually does not transform into S′ and is the same for all queries.
The first line of the input contains three integers n, m and k denoting the length of S, the length of T and the number of queries (1≤n≤5⋅104, 1≤m≤100, 1≤k≤5⋅104).
The next line contains a string S consisting of n lowercase English letters. The following line contains a string T consisting of m lowercase English letters. Each of the remaining k lines contains a query consisting of two integers L and R (1≤L<R≤n).
For each query, print a single line containing a single integer: the answer to the query.