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

建议使用的浏览器:

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

5532:Almost Sorted Array

题目描述
We are all familiar with sorting algorithms: quick sort, merge sort, heap sort, insertion sort, selection sort, bubble sort, etc. But sometimes it is an overkill to use these algorithms for an almost sorted array.

We say an array is sorted if its elements are in non-decreasing order or non-increasing order. We say an array is almost sorted if we can remove exactly one element from it, and the remaining array is sorted. Now you are given an array $a_1, a_2, \ldots, a_n$, is it almost sorted?
输入解释
The first line contains an integer $T$ indicating the total number of test cases. Each test case starts with an integer $n$ in one line, then one line with $n$ integers $a_1, a_2, \ldots, a_n$.

$1 \le T \le 2000$
$2 \le n \le 10^5$
$1 \le a_i \le 10^5$
There are at most 20 test cases with $n > 1000$.
输出解释
For each test case, please output "`YES`" if it is almost sorted. Otherwise, output "`NO`" (both without quotes).
输入样例
3
3
2 1 7
3
3 2 1
5
3 1 4 1 5
输出样例
YES
YES
NO
来自杭电HDUOJ的附加信息
Recommend hujie

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

源链接: HDU-5532

最后修改于 2020-10-25T23:23:31+00:00 由爬虫自动更新

共提交 0

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