CF1686B.Odd Subarrays

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 < j \le m and bi>bjb_i>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?

输入格式

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 .

输出格式

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.

输入输出样例

  • 输入#1

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

    输出#1

    0
    2
    0
    1
    1

说明/提示

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.

首页