#C. 排序

    Type: Default File IO: sort 2000ms 512MiB

排序

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

排序(sort\texttt{sort}

【题目描述】

小 D 有一个数列 a1ana_1\sim a_n,他可以对这个数列进行若干次操作,每次操作可以选择一个 1n11\sim n-1 中的 ii,然后交换 ai,ai+1a_i,a_{i+1}

小 D 还可以在操作前使用一次超能力,他可以任选两个下标 i,ji,j 满足 1i<jn1\le i<j\le n,然后交换 ai,aja_i,a_j

小 D 想知道使用一次超能力后(不能不使用),至少要多少次操作才能把 a1ana_1\sim a_n 变成不降的。

【输入格式】

sort.in\texttt{sort.in} 中读入数据。

第一行一个整数 nn

接下来 nn 行,每行一个整数,第 ii 个整数表示 aia_i

【输出格式】

输出到 sort.out\texttt{sort.out} 中。

一行一个整数表示最小操作次数。

【样例 1 输入】

5
3
1
7
9
5

【样例 1 输出】

2

【样例 1 解释】

先用超能力交换 a3,a5a_3,a_5,得到序列 a=[3,1,5,9,7]a=[3,1,5,9,7],交换 a1,a2a_1,a_2,交换 a4,a5a_4,a_5

【样例 2 输入】

3
1
2
3

【样例 2 输出】

1

【样例 2 解释】

不能不使用超能力。

【样例 3】

见下发文件中的 sort3.in\texttt{sort3.in}sort3.ans\texttt{sort3.ans}

该样例满足子任务 22 的限制。

【样例 4】

见下发文件中的 sort4.in\texttt{sort4.in}sort4.ans\texttt{sort4.ans}

该样例满足子任务 44 的限制。

【数据范围】

对于所有的测试数据有:2n105,1ai1092\le n\le 10^5,1\le a_i\le 10^9

子任务编号 分值 特殊限制
11 2020 n1000n\le 1000aia_i 两两不同
22 3030 n5000n\le 5000aia_i 两两不同
33 aia_i 两两不同
44 2020 无特殊限制

NOIP2024 模拟赛(四)hard

Not Attended
Status
Done
Rule
OI
Problem
4
Start at
2024-8-10 7:50
End at
2024-8-10 12:05
Duration
4.3 hour(s)
Host
Partic.
32