CF1686B.Odd Subarrays

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

Odd Subarrays

For an array [b1,b2,,bm][b_1, b_2, \ldots, b_m] define its number of inversions as the number of pairs (i,j)(i, j) of integers such that 1i<jm1 \le i \lt j \le m and bi>bjb_i \gt b_j. Let's call array bb odd if its number of inversions is odd.

For example, array [4,2,7][4, 2, 7] is odd, as its number of inversions is 11, while array [2,1,4,3][2, 1, 4, 3] isn't, as its number of inversions is 22.

You are given a permutation [p1,p2,,pn][p_1, p_2, \ldots, p_n] of integers from 11 to nn (each of them appears exactly once in the permutation). You want to split it into several consecutive subarrays (maybe just one), so that the number of the odd subarrays among them is as large as possible.

What largest number of these subarrays may be odd?

Input

The first line of the input contains a single integer tt (1t1051 \le t \le 10^5)  — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer nn (1n1051 \le n \le 10^5)  — the size of the permutation.

The second line of each test case contains nn integers p1,p2,,pnp_1, p_2, \ldots, p_n (1pin1 \le p_i \le n, all pip_i are distinct)  — the elements of the permutation.

The sum of nn over all test cases doesn't exceed 21052\cdot 10^5.

Output

For each test case output a single integer  — the largest possible number of odd subarrays that you can get after splitting the permutation into several consecutive subarrays.

Note

In the first and third test cases, no matter how we split our permutation, there won't be any odd subarrays.

In the second test case, we can split our permutation into subarrays [4,3],[2,1][4, 3], [2, 1], both of which are odd since their numbers of inversions are 11.

In the fourth test case, we can split our permutation into a single subarray [2,1][2, 1], which is odd.

In the fifth test case, we can split our permutation into subarrays [4,5],[6,1,2,3][4, 5], [6, 1, 2, 3]. The first subarray has 00 inversions, and the second has 33, so it is odd.

Samples

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

在线编程 IDE

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