#P10668. BZOJ2720 [Violet 5] 列队春游

BZOJ2720 [Violet 5] 列队春游

Problem Description

Given a sequence of positive integers h1,h2,⋯ ,hnh_1,h_2,\cdots,h_n. Let pp be a random permutation of 1∼n1\sim n.

Define hi′=hpih'_i=h_{p_i}. Define prei\mathrm{pre}_i as the largest j<ij\lt i such that hj′≥hi′h'_j\ge h'_i (if it does not exist, let it be 00).

Find the expected value of ∑i=1n(i−prei)\displaystyle \sum_{i=1}^n (i-\mathrm{pre}_i), and output it rounded to two decimal places.

Input Format

The first line contains a positive integer nn, which is the length of the sequence.

The second line contains nn positive integers hih_i.

Output Format

Output one real number in one line, which is the answer rounded to two decimal places.

3
3 2 1
4.33

Hint

For 20%20\% of the testdata, 1≤n≤101\leq n\leq 10.

For 50%50\% of the testdata, 1≤n≤701\leq n\leq 70, and all hih_i are distinct.

For 100%100\% of the testdata, it is guaranteed that 1≤n≤3001\leq n\leq 300 and 1≤hi≤10001\leq h_i\leq 1000.

Translated by ChatGPT 5