CF1526E.Oolimry and Suffix Array

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Once upon a time, Oolimry saw a suffix array. He wondered how many strings can produce this suffix array.

More formally, given a suffix array of length nn and having an alphabet size kk, count the number of strings that produce such a suffix array.

Let ss be a string of length nn. Then the ii-th suffix of ss is the substring s[i…n−1]s[i \ldots n-1]. A suffix array is the array of integers that represent the starting indexes of all the suffixes of a given string, after the suffixes are sorted in the lexicographic order. For example, the suffix array of oolimry is [3,2,4,1,0,5,6][3,2,4,1,0,5,6] as the array of sorted suffixes is [imry,limry,mry,olimry,oolimry,ry,y][\texttt{imry},\texttt{limry},\texttt{mry},\texttt{olimry},\texttt{oolimry},\texttt{ry},\texttt{y}].

A string xx is lexicographically smaller than string yy, if either xx is a prefix of yy (and x≠yx\neq y), or there exists such ii that xi<yix_i \lt y_i, and for any 1≤j<i1\leq j \lt i , xj=yjx_j = y_j.

很久以前,Oolimry 看到了一个后缀数组。他好奇:有多少个字符串能生成该后缀数组?

更形式化地,给定一个长度为 nn 的后缀数组以及字母表大小 kk,请计算能生成该后缀数组的字符串个数。

设 ss 是一个长度为 nn 的字符串,则 ss 的第 ii 个后缀是子串 s[i…n−1]s[i \ldots n-1]。后缀数组是一个整数数组,其元素表示原字符串所有后缀在按字典序排序后的起始下标。例如,字符串 oolimry\texttt{oolimry} 的后缀数组为 [3,2,4,1,0,5,6][3,2,4,1,0,5,6],因为其按字典序排序后的后缀序列为 [imry,limry,mry,olimry,oolimry,ry,y][\texttt{imry},\texttt{limry},\texttt{mry},\texttt{olimry},\texttt{oolimry},\texttt{ry},\texttt{y}]。

字符串 xx 在字典序上小于字符串 yy,当且仅当以下任一条件成立:
(1)xx 是 yy 的真前缀(即 x≠yx \neq y 且 xx 是 yy 的前缀);
(2)存在某个下标 ii,使得 xi<yix_i \lt y_i,且对任意 1≤j<i1 \leq j \lt i,均有 xj=yjx_j = y_j。

输入格式

The first line contain 2 integers nn and kk (1≤n≤200000,1≤k≤2000001 \leq n \leq 200000,1 \leq k \leq 200000) — the length of the suffix array and the alphabet size respectively.

The second line contains nn integers s0,s1,s2,…,sn−1s_0, s_1, s_2, \ldots, s_{n-1} (0≤si≤n−10 \leq s_i \leq n-1) where sis_i is the ii-th element of the suffix array i.e. the starting position of the ii-th lexicographically smallest suffix. It is guaranteed that for all 0≤i<j≤n−10 \leq i \lt j \leq n-1, si≠sjs_i \neq s_j.

第一行包含两个整数 nn 和 kk(1≤n≤200000, 1≤k≤2000001 \leq n \leq 200000,\,1 \leq k \leq 200000),分别表示后缀数组的长度和字母表大小。

第二行包含 nn 个整数 s0,s1,s2,…,sn−1s_0, s_1, s_2, \ldots, s_{n-1}(0≤si≤n−10 \leq s_i \leq n-1),其中 sis_i 是后缀数组的第 ii 个元素,即字典序第 ii 小的后缀的起始位置。保证对所有 0≤i<j≤n−10 \leq i \lt j \leq n-1,均有 si≠sjs_i \neq s_j。

输出格式

Print how many strings produce such a suffix array. Since the number can be very large, print the answer modulo 998244353998244353.

输出能生成该后缀数组的字符串个数。由于答案可能非常大,请对 998244353998244353 取模后输出。

输入输出样例

  • 输入#1

    3 2
    0 2 1

    输出#1

    1
  • 输入#2

    5 1
    0 1 2 3 4

    输出#2

    0
  • 输入#3

    6 200000
    0 1 2 3 4 5

    输出#3

    822243495
  • 输入#4

    7 6
    3 2 4 1 0 5 6

    输出#4

    36

说明/提示

In the first test case, "abb" is the only possible solution.

In the second test case, it can be easily shown no possible strings exist as all the letters have to be equal.

In the fourth test case, one possible string is "ddbacef".

Please remember to print your answers modulo 998244353998244353.

在第一个测试用例中,“abb”是唯一的可能解。

在第二个测试用例中,可以很容易地证明不存在可能的字符串,因为所有字母都必须相等。

在第四个测试用例中,一个可能的字符串是“ddbacef”。

请注意,您的答案需对 998244353998244353 取模后输出。

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

首页