Repovive
  • Dashboard
  • Ranking
  • Submissions
  • Discussion
  1. Contests
  2. Premier Round 4
  3. 9F

My submissions

/
/
/
/

Announcements

My submissions

/
/
/
/

Announcements

Solve
Author

9F. Expected Beauty

3250 pts·2s·256 MB

Constraints

Input

Output

Samples

Input
t
5
Case 1
1 100
7
Case 2
2 0
5 2
Case 3
2 1
5 2
Case 4
3 1
3 1 2
Case 5
10 3
10 1 9 2 8 3 7 4 6 5
Explanation
Case 1
Case 2
Case 3
Case 4
Case 5
Output
Case 1
0
Case 2
3
Case 3
2
Case 4
499122179
Case 5
969444607

You are given an array a1,a2,…,ana_1, a_2, \ldots, a_na1​,a2​,…,an​.

You perform the following operation exactly kkk times.

Choose two integers lll and rrr uniformly at random among all pairs satisfying 1≤l≤r≤n1 \le l \le r \le n1≤l≤r≤n, then reverse the subarray al,al+1,…,ara_l, a_{l+1}, \ldots, a_ral​,al+1​,…,ar​.

The operations are independent.

The beauty of an array bbb is defined as

∑1≤x<y≤nmax⁡(0,bx−by).\sum_{1 \le x < y \le n} \max(0, b_x - b_y).1≤x<y≤n∑​max(0,bx​−by​).

Compute the expected value of the beauty of the final array modulo 998244353998244353998244353.

Formally, if the expected value can be written as an irreducible fraction pq\frac{p}{q}qp​, output p×q−1p \times q^{-1}p×q−1 modulo 998244353998244353998244353.

  • 1≤t≤1041 \le t \le 10^41≤t≤104
  • 1≤n≤1061 \le n \le 10^61≤n≤106
  • The sum of nnn over all test cases is at most 10610^6106
  • 0≤k≤1090 \le k \le 10^90≤k≤109
  • 1≤ai≤1091 \le a_i \le 10^91≤ai​≤109
ttt nka1a2⋯an}×t\left. \begin{array}{l} n \quad k \\ a_1 \quad a_2 \quad \cdots \quad a_n \end{array} \right\} \times tnka1​a2​⋯an​​}×t
ans}×t\left. \begin{array}{l} ans \end{array} \right\} \times tans​}×t

The array has only one element, so the beauty is always 000.

No operation is performed, so the beauty remains 333.

There are 333 possible segments, and the expected beauty is 222.

After one operation, the expected beauty is 52\frac{5}{2}25​.

This is a larger sample with n=10n=10n=10 and k=3k=3k=3.