[Solution] MEX vs MED Codeforces Solution | Solution Codeforces
You are given a permutation of length of numbers . Count the number of subsegments of this permutation such that .
of is the smallest non-negative integer that does not occur in . For example:
of the set is the median of the set, i.e. the element that, after sorting the elements in non-decreasing order, will be at position number (array elements are numbered starting from and here denotes rounding down.). For example:
A sequence of numbers is called a permutation if it contains all the numbers from to exactly once.
The first line of the input contains a single integer ), the number of test cases.
The descriptions of the test cases follow.
The first line of each test case contains a single integer (), the length of the permutation .
The second line of each test case contains exactly integers: (), elements of permutation .
It is guaranteed that the sum of over all test cases does not exceed .
For each test case print the answer in a single line: the number of subsegments of this permutation such that .
The first test case contains exactly one subsegment and on it.
In the third test case, on the following subsegments: , , and , is greater than .
In the fourth test case, on the following subsegments: , , and , greater than .
No comments:
Post a Comment