[Solution] Odd Subarrays Codeforces Solution | Codeforces Problem Solution 2022
For an array define its number of inversions as the number of pairs of integers such that and . Let's call array odd if its number of inversions is odd.
For example, array is odd, as its number of inversions is , while array isn't, as its number of inversions is .
You are given a permutation of integers from to (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 () — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer () — the size of the permutation.
The second line of each test case contains integers (, all are distinct) — the elements of the permutation.
The sum of over all test cases doesn't exceed .
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.
No comments:
Post a Comment