#P5626. 【AFOI-19】数码排序

【AFOI-19】数码排序

Description

While escaping, some “digits” also escaped. They kept making noise and asked Little L to help sort them.

The digits in the virtual world are invisible.

Little L currently only knows selection sort, insertion sort, bubble sort, and merge sort.

So Little L wants to ask: in the worst case, what is the minimum number of comparisons needed to make the sequence sorted?


Template code for sorting

Input Format

There is only one line of input: a positive integer nn, representing the length of the sequence.

Output Format

Output the minimum number of comparisons.

4
5
5
8

Hint

  • Sample 11 Explanation

For a sequence of length 44, merge sort splits it into 22 groups, with 22 elements in each group. The 22 elements in each group are compared once. During merging, the worst case needs 33 comparisons, so the total is 3+1+1=53+1+1=5.

  • Constraints

For 10%10\% of the testdata, n1000n \leq 1000.

For 30%30\% of the testdata, n1000000n \leq 1000000.

For 100%100\% of the testdata, n1016n \leq 10^{16}.

The testdata is guaranteed to be random.

Translated by ChatGPT 5