CF2204B.Right Maximum
入门
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array a consisting of n integers.
While the array is not empty, an operation is performed consisting of two steps:
- first, the maximum element in the array is chosen (if there are multiple maximum elements, the rightmost maximum is chosen);
- then, all elements after the chosen element, including it, are removed from the array.
Your task is to calculate the number operations that will be performed before the array becomes empty.
给你一个由 n 个整数组成的数组 a。
当数组非空时,重复执行如下两步操作:
- 首先,选择数组中的最大元素(若存在多个最大元素,则选择最右侧的那个);
- 然后,将所选元素及其之后的所有元素从数组中删除。
你的任务是计算在数组变为空之前总共执行的操作次数。
输入格式
The first line contains one integer t (1≤t≤104) — the number of test cases.
Each test case consists of two lines:
- the first line contains one integer n (2≤n≤2⋅105);
- the second line contains n integers a1,a2,…,an (1≤ai≤n).
Additional constraint on the input: the sum of n over all test cases does not exceed 2⋅105.
第一行包含一个整数 t(1≤t≤104)—— 测试用例的数量。
每个测试用例由两行组成:
- 第一行包含一个整数 n(2≤n≤2⋅105);
- 第二行包含 n 个整数 a1,a2,…,an(1≤ai≤n)。
输入的额外约束:所有测试用例的 n 值之和不超过 2⋅105。
输出格式
For each test case, print one integer — the number of operations that will be performed.
对于每个测试用例,输出一个整数——将要执行的操作次数。
输入输出样例
输入#1
4 5 2 1 2 3 1 6 1 2 3 4 5 6 3 3 2 1 4 1 3 3 1
输出#1
3 6 1 3
说明/提示
In the first example, the array is [2,1,2,3,1]. The following operations are performed on it:
- first, the 4-th element is chosen. The last two elements are removed, and the array becomes [2,1,2];
- then, the 3-rd element is chosen. The last element is removed, and the array becomes [2,1];
- then, the 1-st element is chosen. Both elements are removed, so the array becomes empty after 3 operations.
在第一个例子中,数组为 [2,1,2,3,1]。对其执行以下操作:
- 首先,选择第 4 个元素。移除最后两个元素,数组变为 [2,1,2];
- 接着,选择第 3 个元素。移除最后一个元素,数组变为 [2,1];
- 然后,选择第 1 个元素。移除两个元素,因此经过 3 次操作后数组变为空。
输入解题思路,AI测评打分。不知道怎么写?