GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Wednesday 25 May 2022

[Solution] Odd Subarrays Codeforces Solution | Codeforces Problem Solution 2022

B. Odd Subarrays
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

For an array [b1,b2,,bm] define its number of inversions as the number of pairs (i,j) of integers such that 1i<jm and bi>bj. Let's call array b odd if its number of inversions is odd.

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

You are given a permutation [p1,p2,,pn] of integers from 1 to n (each of them appears exactly 

Solution Click Below:-  CLICK HERE

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 t (1t105)  — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer n (1n105)  — the size of the permutation.

The second line of each test case contains n integers p1,p2,,pn (1pin, all pi are distinct)  — the elements of the permutation.

The sum of n over all test cases doesn't exceed 2105.

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.

No comments:

Post a Comment