QOJ.ac

QOJ

时间限制: 1.0 s 内存限制: 256 MB 总分: 100 可 Hack ✓

#9892. 口袋里的序列

统计

DreamGrid 在他的右口袋里发现了一个整数序列 $a_1, a_2, \dots, a_n$。由于感到无聊,DreamGrid 决定玩弄这个序列。他可以执行任意次数(包括零次)以下操作:选择一个元素并将其移动到序列的最前端。

请问,为了使序列变为非递减序列,最少需要进行多少次操作?

输入格式

输入包含多组测试数据。第一行包含一个整数 $T$,表示测试数据的组数。对于每组测试数据:

第一行包含一个整数 $n$ ($1 \le n \le 10^5$),表示序列的长度。 第二行包含 $n$ 个整数 $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$),表示给定的序列。

保证所有测试数据的 $n$ 之和不超过 $10^6$。

输出格式

对于每组测试数据,输出一行,包含一个整数,表示答案。

样例

样例输入 1

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

样例输出 1

2
0

说明

对于第一个样例,将第 3 个元素移动到最前面(序列变为 $\{2, 1, 3, 4\}$),然后将第 2 个元素移动到最前面(序列变为 $\{1, 2, 3, 4\}$)。此时序列变为非递减序列。

对于第二个样例,由于序列已经是有序的,因此不需要进行任何操作。

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.