#x1006. CF963D Frequency of String

CF963D Frequency of String

Frequency of String

题面翻译

给你一个字符串 s(S105)s \pod {|S| \le 10^5} ,有 n(n105)n \pod {n \le 10^5} 个询问,第 ii 个询问包含一个整数 kik_i 和一个字符串 mi(imi105)m_i \pod {\sum_i |m_i| \le 10^5} 。要求找到一个字符串 tt ,使得 ttss 的子串并且 mim_i 至少在 tt 中出现了 kik_i 次。你只需要求出 tt 的最短长度。

保证 mim_i 互不相同。

感谢@OrangeLee 提供的翻译

题目描述

You are given a string s s . You should answer n n queries. The i i -th query consists of integer ki k_i and string mi m_i . The answer for this query is the minimum length of such a string t t that t t is a substring of s s and mi m_i has at least ki k_i occurrences as a substring in t t .

A substring of a string is a continuous segment of characters of the string.

It is guaranteed that for any two queries the strings mi m_i from these queries are different.

输入格式

The first line contains string s s (1s105) (1 \leq \left | s \right | \leq 10^{5}) .

The second line contains an integer n n ( 1n105 1 \leq n \leq 10^5 ).

Each of next n n lines contains an integer ki k_i (1kis) (1 \leq k_i \leq |s|) and a non-empty string mi m_i — parameters of the query with number i i , in this order.

All strings in input consists of lowercase English letters. Sum of length of all strings in input doesn't exceed 105 10^5 . All mi m_i are distinct.

输出格式

For each query output the answer for it in a separate line.

If a string mi m_{i} occurs in s s less that ki k_{i} times, output -1.

样例 #1

样例输入 #1

aaaaa
5
3 a
3 aa
2 aaa
3 aaaa
1 aaaaa

样例输出 #1

3
4
4
-1
5

样例 #2

样例输入 #2

abbb
7
4 b
1 ab
3 bb
1 abb
2 bbb
1 a
2 abbb

样例输出 #2

-1
2
-1
3
-1
1
-1