DMOPC '21 Contest 10 P6 - Median Replace

View as PDF

Submit solution


Points: 25 (partial)
Time limit: 2.0s
Memory limit: 512M

Author:
Problem types

You are given an array of N positive integers a1,a2,,aN, initially all distinct. You can repeatedly perform the following operation:

  • Choose a subarray [l,r] with 1l<rN where the size rl+1 is odd and al,al+1,,ar are all distinct. Replace all of al,al+1,,ar with their median.

Determine

  1. The minimum number of distinct numbers in a1,a2,,aN after performing a finite number of operations.
  2. The maximum number of operations performed among all sequences of operations that achieve the minimum in (1). It can be proven that this answer is finite.
  3. The number of sequences of operations that achieve both the minimum in (1) and the maximum in (2), modulo 998244353.

Constraints

1N3×106

1aiN

All ai are pairwise distinct.

Subtask 1 [40%]

1N5×103

Subtask 2 [30%]

1N2×105

Subtask 3 [30%]

No additional constraints.

Input Specification

The first line contains the integer N.

The second line contains N space-separated integers a1,a2,,aN.

Output Specification

Output 3 space-separated integers, the answers to (1), (2), and (3) in order.

Sample Input

Copy
6
3 1 4 2 5 6

Sample Output

Copy
2 2 3

Explanation

The 3 sequences of operations are:

  • [[1,3],[3,5]]: The array a becomes [3,1,4,2,5,6][3,3,3,2,5,6][3,3,3,3,3,6].
  • [[1,3],[4,6]]: The array a becomes [3,1,4,2,5,6][3,3,3,2,5,6][3,3,3,5,5,5].
  • [[4,6],[1,3]]: The array a becomes [3,1,4,2,5,6][3,1,4,5,5,5][3,3,3,5,5,5].

Comments

There are no comments at the moment.