CF212B.Polycarpus is Looking for Good Substrings

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

We'll call string s[a,b]=sasa+1... sbs[a,b]=s_{a}s_{a+1}...\ s_{b} (1<=a<=b<=s)(1<=a<=b<=|s|) a substring of string s=s1s2... sss=s_{1}s_{2}...\ s_{|s|} , where s|s| is the length of string ss .

The trace of a non-empty string tt is a set of characters that the string consists of. For example, the trace of string "aab" equals {'a', 'b'}.

Let's consider an arbitrary string ss and the set of its substrings with trace equal to CC . We will denote the number of substrings from this set that are maximal by inclusion by r(C,s)r(C,s) . Substring s[a,b]s[a,b] of length n=ba+1n=b-a+1 belonging to some set is called maximal by inclusion, if there is no substring s[x,y]s[x,y] in this set with length greater than nn , such that 1<=x<=a<=b<=y<=s1<=x<=a<=b<=y<=|s| . Two substrings of string ss are considered different even if they are equal but they are located at different positions of ss .

Polycarpus got a challenging practical task on a stringology exam. He must do the following: given string ss and non-empty sets of characters C1C_{1} , C2C_{2} , ...... , CmC_{m} , find r(Ci,s)r(C_{i},s) for each set CiC_{i} . Help Polycarpus to solve the problem as he really doesn't want to be expelled from the university and go to the army!

输入格式

The first line contains a non-empty string ss (1<=s<=106)(1<=|s|<=10^{6}) .

The second line contains a single integer mm (1<=m<=104)(1<=m<=10^{4}) . Next mm lines contain descriptions of sets CiC_{i} . The ii -th line contains string cic_{i} such that its trace equals CiC_{i} . It is guaranteed that all characters of each string cic_{i} are different.

Note that CiC_{i} are not necessarily different. All given strings consist of lowercase English letters.

输出格式

Print mm integers — the ii -th integer must equal r(Ci,s)r(C_{i},s) .

输入输出样例

  • 输入#1

    aaaaa
    2
    a
    a
    

    输出#1

    1
    1
    
  • 输入#2

    abacaba
    3
    ac
    ba
    a
    

    输出#2

    1
    2
    4
    
首页