QOJ.ac

QOJ

حد الوقت: 10.0 s حد الذاكرة: 256 MB مجموع النقاط: 100

#11974. 几乎有序的数组

الإحصائيات

我们都很熟悉各种排序算法:快速排序、归并排序、堆排序、插入排序、选择排序、冒泡排序等。但有时对于一个“几乎有序”的数组,使用这些算法有些大材小用。

如果一个数组的元素呈非递减顺序或非递增顺序,我们称该数组是有序的。如果一个数组在恰好移除其中一个元素后,剩余的数组是有序的,我们称该数组是“几乎有序”的。现在给定一个数组 $a_1, a_2, \dots, a_n$,请判断它是否是几乎有序的。

输入格式

第一行包含一个整数 $T$,表示测试用例的总数。每个测试用例的第一行包含一个整数 $n$,随后一行包含 $n$ 个整数 $a_1, a_2, \dots, a_n$。

  • $1 \le T \le 2000$
  • $2 \le n \le 10^5$
  • $1 \le a_i \le 10^5$
  • 其中 $n > 1000$ 的测试用例不超过 20 个。

输出格式

对于每个测试用例,如果数组是几乎有序的,请输出 "YES",否则输出 "NO"(均不含引号)。

样例

输入格式 1

3
3
2 1 7
3
3 2 1
5
3 1 4 1 5

输出格式 1

YES
YES
NO

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.