#P15757. [JAG 2025 Summer Camp #1] Inversion of Suffix Array

[JAG 2025 Summer Camp #1] Inversion of Suffix Array

题目描述

You are given positive integers NN, KK and a string SS of length NN consisting of lowercase English letters.

Let TT be the string obtained by concatenating KK copies of SS.

Find the inversion number of the Suffix Array of TT, modulo 998244353998244353.

For a string ss of length nn, the suffix array of ss is a permutation of integers from 11 to nn that represents the starting positions of all non-empty suffixes of ss, sorted in lexicographical order.

输入格式

The input is given in the following format:

N KS\begin{aligned} &N \ K \\ &S \end{aligned}
  • 1N2000001 \leq N \leq 200\,000
  • 1K10121 \leq K \leq 10^{12}
  • SS is a string of length NN consisting of lowercase English letters.
  • NN and KK are integers.

输出格式

Output the answer in a single line.

4 2
icpc
18
13 92025
jagsummercamp
996562345