CF2204B.Right Maximum

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

Right Maximum

You are given an array aa consisting of nn 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.

Input

The first line contains one integer tt (1t1041 \le t \le 10^4) — the number of test cases.

Each test case consists of two lines:

  • the first line contains one integer nn (2n21052 \le n \le 2 \cdot 10^5);
  • the second line contains nn integers a1,a2,,ana_1, a_2, \dots, a_n (1ain1 \le a_i \le n).

Additional constraint on the input: the sum of nn over all test cases does not exceed 21052 \cdot 10^5.

Output

For each test case, print one integer — the number of operations that will be performed.

Note

In the first example, the array is [2,1,2,3,1][2, 1, 2, 3, 1]. The following operations are performed on it:

  • first, the 44-th element is chosen. The last two elements are removed, and the array becomes [2,1,2][2, 1, 2];
  • then, the 33-rd element is chosen. The last element is removed, and the array becomes [2,1][2, 1];
  • then, the 11-st element is chosen. Both elements are removed, so the array becomes empty after 33 operations.

Samples

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

在线编程 IDE

建议全屏模式获得最佳体验