当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

6949:Swap

题目描述
You are given a sequence of length $N$, and there is also a number $H$ in your hands.

In each step, you can swap the number in your hands with one of the numbers in the sequence.

Now you need to find the minimum steps to make the sequence in non-decreasing order.
输入解释
There are multiple test cases.

For each test case, the first line contains two integers $N$ and $H$, denoting the length of the sequence and the number in your hands initially.

The second line contains $N$ integers $A_1,A_2,\ldots,A_N$, denoting the initial sequence.

$1\leq H,A_i \leq 10^9$. And the sum of $N$ of all test cases is not larger than $300000$.

输出解释
For each test case, print an integer in one line, denoting your answer.
输入样例
4 3
1 4 2 5
4 3
1 2 5 4
6 2
2 3 4 2 3 4
6 2
3 4 5 3 4 5
输出样例
2
1
3
4

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-6949

最后修改于 2021-10-23T19:10:47+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
4000/2000MS(Java/Others) 65536/262144K(Java/Others)