#B3667. Suffix Maximum Positions Counting

    ID: 11326 Type: Default 1000ms 256MiB

Suffix Maximum Positions Counting

Suffix Maximum Positions Counting

You are given an array \(a\) of length \(n\). For every contiguous subarray of length \(k\), you need to determine the number of positions that are suffix maximums in that subarray.

A position \(i\) (1-indexed) in a sequence \(b = [b_1, b_2, \ldots, b_{|b|}]\) is called a suffix maximum if for every \(j\) such that \(i b_j\). Note that the last element is always a suffix maximum since there are no elements to its right.

Task: For each subarray of length \(k\) extracted from \(a\) (taking consecutive elements), output the count of suffix maximum positions in that subarray.

inputFormat

The first line contains two integers \(n\) and \(k\) (where \(1 \leq k \leq n\)).

The second line contains \(n\) space-separated integers, representing the elements of the array \(a\).

It is guaranteed that the input is valid.

outputFormat

Output \(n-k+1\) integers separated by spaces, where each integer is the count of suffix maximum positions for the corresponding subarray of length \(k\).

sample

5 3
1 2 3 2 1
1 2 3