#P204E. Little Elephant and Strings

    ID: 229 远端评测题 3000ms 256MiB 尝试: 1 已通过: 1 难度: 10 上传者: 标签>data structuresimplementationstring suffix structurestwo pointers*2800

Little Elephant and Strings

Little Elephant and Strings

题面翻译

给定一个字符串序列 a1,a2,,ana_1,a_2,\dots,a_n,对于每个 aia_i,求出多少对 (l,r)(l,r) ,满足 S[l,r]S[l,r]aa 中至少 kk 个串的子串。

n,k105n,k\le 10^5ai105\sum |a_i|\le 10^5

题目描述

The Little Elephant loves strings very much.

He has an array a a from n n strings, consisting of lowercase English letters. Let's number the elements of the array from 1 to n n , then let's denote the element number i i as ai a_{i} . For each string ai a_{i} (1<=i<=n) (1<=i<=n) the Little Elephant wants to find the number of pairs of integers l l and r r (1<=l<=r<=ai) (1<=l<=r<=|a_{i}|) such that substring ai[l... r] a_{i}[l...\ r] is a substring to at least k k strings from array a a (including the i i -th string).

Help the Little Elephant solve this problem.

If you are not familiar with the basic notation in string problems, you can find the corresponding definitions in the notes.

输入格式

The first line contains two space-separated integers — n n and k k (1<=n,k<=105) (1<=n,k<=10^{5}) . Next n n lines contain array a a . The i i -th line contains a non-empty string ai a_{i} , consisting of lowercase English letter. The total length of all strings ai a_{i} does not exceed 105 10^{5} .

输出格式

On a single line print n n space-separated integers — the i i -th number is the answer for string ai a_{i} .

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

样例 #1

样例输入 #1

3 1
abc
a
ab

样例输出 #1

6 1 3

样例 #2

样例输入 #2

7 4
rubik
furik
abab
baba
aaabbbababa
abababababa
zero

样例输出 #2

1 0 9 9 21 30 0

提示

Let's assume that you are given string a=a1a2... aa a=a_{1}a_{2}...\ a_{|a|} , then let's denote the string's length as a |a| and the string's i i -th character as ai a_{i} .

A substring a[l... r] a[l...\ r] (1<=l<=r<=a) (1<=l<=r<=|a|) of string a a is string alal+1... ar a_{l}a_{l+1}...\ a_{r} .

String a a is a substring of string b b , if there exists such pair of integers l l and r r (1<=l<=r<=b) (1<=l<=r<=|b|) , that b[l... r]=a b[l...\ r]=a .