CF204E.Little Elephant and Strings

省选/NOI-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

The Little Elephant loves strings very much.

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

小象非常喜欢字符串。

他有一个由 nn 个字符串组成的数组 aa,每个字符串仅包含小写英文字母。我们将数组元素编号为 11 到 nn,并用 aia_i 表示第 ii 个元素。对于每个字符串 aia_i(其中 1≤i≤n1 \le i \le n),小象希望找出满足如下条件的整数对 (l,r)(l, r) 的数量:
1≤l≤r≤∣ai∣1 \le l \le r \le |a_i|,且子串 ai[l…r]a_i[l\ldots r] 至少是数组 aa 中 kk 个字符串(包括第 ii 个字符串本身)的子串。

请帮助小象解决这个问题。

如果你不熟悉字符串问题中的基本记号,可参见题末的注释部分。

输入格式

The first line contains two space-separated integers — n and k (1 ≤ n, k ≤ 105). Next n lines contain array a. The i-th line contains a non-empty string a__i, consisting of lowercase English letter. The total length of all strings a__i does not exceed 105.

第一行包含两个以空格分隔的整数 — nn 和 kk(1 ≤ n, k ≤ 1051 ≤ n, k ≤ 10^5)。接下来的 nn 行包含数组 aa。第 ii 行包含一个非空字符串 aia_i,由小写英文字母组成。所有字符串 aia_i 的总长度不超过 10510^5。

输出格式

On a single line print n space-separated integers — the i-th number is the answer for string 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.

在一行中输出 n 个空格分隔的整数——第 i 个数是字符串 a__i 对应的答案。

请注意,在 C++ 中读写 64 位整数时,请勿使用 %lld 说明符。推荐使用 cin、cout 流或 %I64d 说明符。

输入输出样例

  • 输入#1

    3 1
    abc
    a
    ab

    输出#1

    6 1 3
  • 输入#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 = _a_1_a_2... a|a|, then let's denote the string's length as |a| and the string's i-th character as a__i.

A substring a[l... r] (1 ≤ l ≤ r ≤ |a|) of string a is string a__l__a__l + 1... a__r.

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

假设给定字符串 a=a1a2…a∣a∣a = a_1a_2\ldots a_{|a|},我们记该字符串的长度为 ∣a∣|a|,其第 ii 个字符为 aia_i。

字符串 aa 的子串 a[l…r]a[l\ldots r](其中 1≤l≤r≤∣a∣1 \le l \le r \le |a|)定义为字符串 alal+1…ara_la_{l+1}\ldots a_r。

若存在一对整数 ll 和 rr(满足 1≤l≤r≤∣b∣1 \le l \le r \le |b|),使得 b[l…r]=ab[l\ldots r] = a,则称字符串 aa 是字符串 bb 的子串。

输入解题思路,AI测评打分。不知道怎么写?

首页