CF1065E.Side Transmutations
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Consider some set of distinct characters A and some string S , consisting of exactly n characters, where each character is present in A .
You are given an array of m integers b ( b1<b2<⋯<bm ).
You are allowed to perform the following move on the string S :
- Choose some valid i and set k=bi ;
- Take the first k characters of S=Prk ;
- Take the last k characters of S=Suk ;
- Substitute the first k characters of S with the reversed Suk ;
- Substitute the last k characters of S with the reversed Prk .
For example, let's take a look at S= "abcdefghi" and k=2 . Pr2= "ab", Su2= "hi". Reversed Pr2= "ba", Su2= "ih". Thus, the resulting S is "ihcdefgba".
The move can be performed arbitrary number of times (possibly zero). Any i can be selected multiple times over these moves.
Let's call some strings S and T equal if and only if there exists such a sequence of moves to transmute string S to string T . For the above example strings "abcdefghi" and "ihcdefgba" are equal. Also note that this implies S=S .
The task is simple. Count the number of distinct strings.
The answer can be huge enough, so calculate it modulo 998244353 .
输入格式
The first line contains three integers n , m and ∣A∣ ( 2≤n≤109 , 1≤m≤min(2n,2⋅105) , 1≤∣A∣≤109 ) — the length of the strings, the size of the array b and the size of the set A , respectively.
The second line contains m integers b1,b2,…,bm ( 1≤bi≤2n , b1<b2<⋯<bm ).
输出格式
Print a single integer — the number of distinct strings of length n with characters from set A modulo 998244353 .
输入输出样例
输入#1
3 1 2 1
输出#1
6
输入#2
9 2 26 2 3
输出#2
150352234
输入#3
12 3 1 2 5 6
输出#3
1
说明/提示
Here are all the distinct strings for the first example. The chosen letters 'a' and 'b' are there just to show that the characters in A are different.
- "aaa"
- "aab" = "baa"
- "aba"
- "abb" = "bba"
- "bab"
- "bbb"