CF1526E.Oolimry and Suffix Array
普及/提高-
通过率:0%
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 n and having an alphabet size k , count the number of strings that produce such a suffix array.
Let s be a string of length n . Then the i -th suffix of s is the substring s[i…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] as the array of sorted suffixes is [imry,limry,mry,olimry,oolimry,ry,y] .
A string x is lexicographically smaller than string y , if either x is a prefix of y (and x=y ), or there exists such i that xi<yi , and for any 1≤j<i , xj=yj .
输入格式
The first line contain 2 integers n and k ( 1≤n≤200000,1≤k≤200000 ) — the length of the suffix array and the alphabet size respectively.
The second line contains n integers s0,s1,s2,…,sn−1 ( 0≤si≤n−1 ) where si is the i -th element of the suffix array i.e. the starting position of the i -th lexicographically smallest suffix. It is guaranteed that for all 0≤i<j≤n−1 , si=sj .
输出格式
Print how many strings produce such a suffix array. Since the number can be very large, print the answer modulo 998244353 .
输入输出样例
输入#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 998244353 .