CF386C.Diverse Substrings

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

String diversity is the number of symbols that occur in the string at least once. Diversity of s will be denoted by d(s). For example , d("aaa")=1, d("abacaba")=3.

Given a string s, consisting of lowercase Latin letters. Consider all its substrings. Obviously, any substring diversity is a number from 1 to d(s). Find statistics about substrings diversity: for each k from 1 to d(s), find how many substrings of s has a diversity of exactly k.

字符串的多样性是指在该字符串中至少出现一次的不同字符的个数。字符串 ss 的多样性记作 d(s)d(s)。例如,d(“aaa”)=1d(\text{“aaa”}) = 1,d(“abacaba”)=3d(\text{“abacaba”}) = 3。

给定一个由小写拉丁字母组成的字符串 ss。考虑 ss 的所有子串。显然,任意子串的多样性均为 11 到 d(s)d(s) 之间的整数。请统计各子串的多样性:对每个 kk(kk 从 11 到 d(s)d(s)),求出 ss 中恰好具有 kk 种多样性的子串个数。

输入格式

The input consists of a single line containing s. It contains only lowercase Latin letters, the length of s is from 1 to 3·105.

输入仅包含一行,内容为字符串 ss。ss 仅由小写拉丁字母组成,其长度在 11 到 3⋅1053 \cdot 10^5 之间。

输出格式

Print to the first line the value d(s). Print sequence _t_1, _t_2, ..., t__d(s) to the following lines, where t__i is the number of substrings of s having diversity of exactly i.

第一行输出值 d(s)d(s)。接下来的若干行输出序列 t1, t2, …, td(s)t_1,\ t_2,\ \dots,\ t_{d(s)},其中 tit_i 表示字符串 ss 中恰好具有多样性 ii 的子串个数。

输入输出样例

  • 输入#1

    abca

    输出#1

    3
    4
    3
    3
  • 输入#2

    aabacaabbad

    输出#2

    4
    14
    19
    28
    5

说明/提示

Consider the first example.

We denote by s(i, j) a substring of "abca" with the indices in the segment [i, j].

  • s(1, 1) =  "a", d("a") = 1
  • s(2, 2) =  "b", d("b") = 1
  • s(3, 3) =  "c", d("c") = 1
  • s(4, 4) =  "a", d("a") = 1
  • s(1, 2) =  "ab", d("ab") = 2
  • s(2, 3) =  "bc", d("bc") = 2
  • s(3, 4) =  "ca", d("ca") = 2
  • s(1, 3) =  "abc", d("abc") = 3
  • s(2, 4) =  "bca", d("bca") = 3
  • s(1, 4) =  "abca", d("abca") = 3

Total number of substring with diversity 1 is 4, with diversity 2 equals 3, 3 diversity is 3.

考虑第一个例子。

我们用 s(i,j)s(i, j) 表示字符串 "abca" 中下标在区间 [i,j][i, j] 内的子串。

  • s(1,1)="a"s(1, 1) = \text{"a"},d("a")=1d(\text{"a"}) = 1
  • s(2,2)="b"s(2, 2) = \text{"b"},d("b")=1d(\text{"b"}) = 1
  • s(3,3)="c"s(3, 3) = \text{"c"},d("c")=1d(\text{"c"}) = 1
  • s(4,4)="a"s(4, 4) = \text{"a"},d("a")=1d(\text{"a"}) = 1
  • s(1,2)="ab"s(1, 2) = \text{"ab"},d("ab")=2d(\text{"ab"}) = 2
  • s(2,3)="bc"s(2, 3) = \text{"bc"},d("bc")=2d(\text{"bc"}) = 2
  • s(3,4)="ca"s(3, 4) = \text{"ca"},d("ca")=2d(\text{"ca"}) = 2
  • s(1,3)="abc"s(1, 3) = \text{"abc"},d("abc")=3d(\text{"abc"}) = 3
  • s(2,4)="bca"s(2, 4) = \text{"bca"},d("bca")=3d(\text{"bca"}) = 3
  • s(1,4)="abca"s(1, 4) = \text{"abca"},d("abca")=3d(\text{"abca"}) = 3

多样性为 1 的子串总数为 4,多样性为 2 的子串总数为 3,多样性为 3 的子串总数为 3。

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

首页