CF2176A.Operations with Inversions
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Given an array a1,a2,…,an. In one operation, you can choose a pair of indices i,j such that 1≤i<j≤n, ai>aj, and remove the element at index j from the array. After that, the size of the array will decrease by 1, and the relative order of the elements will not change.
Determine the maximum number of operations that can be performed on the array if they are applied optimally.
给定一个数组 a1,a2,…,an。在一次操作中,你可以选择一对下标 i,j,满足 1≤i<j≤n 且 ai>aj,然后将位于下标 j 处的元素从数组中删除。执行该操作后,数组长度减少 1,其余元素的相对顺序保持不变。
求在最优操作策略下,最多可以执行多少次这样的操作。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤50). The description of the test cases follows.
The first line of each test case contains an integer n (1≤n≤100) — the size of the initial array.
The second line of each test case contains n natural numbers a1,a2,…,an (1≤ai≤n).
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤50)。随后是测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤100)—— 初始数组的大小。
每个测试用例的第二行包含 n 个自然数 a1,a2,…,an(1≤ai≤n)。
输出格式
For each test case, output the maximum number of operations that you can perform on the given array.
对于每个测试用例,输出可以在给定数组上执行的最大操作次数。
输入输出样例
输入#1
5 3 3 2 1 3 1 2 3 3 3 3 3 5 3 1 4 5 2 1 1
输出#1
2 0 0 2 0
说明/提示
In the first example, we can first choose the pair i=2, j=3 with values a2=2, a3=1 and remove a3. The resulting array will be a=[3,2]. After that, we can remove the second element by choosing the pair i=1, j=2. The total number of operations is 2.
In the second, third, and fifth examples, no operations can be performed since there are no suitable pairs.
In the fourth example, we can remove the second and fifth elements. It can be shown that this is the optimal answer and there is no solution that removes more elements.
在第一个例子中,我们可以首先选择下标对 i=2、j=3,对应值为 a2=2、a3=1,并移除 a3。此时数组变为 a=[3,2]。随后,我们可通过选择下标对 i=1、j=2 来移除第二个元素。总操作次数为 2。
在第二个、第三个和第五个例子中,由于不存在满足条件的下标对,因此无法执行任何操作。
在第四个例子中,我们可以移除第二个和第五个元素。可以证明这是最优解,且不存在能移除更多元素的方案。
输入解题思路,AI测评打分。不知道怎么写?