Problem M
Slide Count
In your programming class, you are given an assignment to
analyze an integer array using a sliding window algorithm.
Specifically, given
-
initially
; -
as long as
:-
if
, then increment ; -
else if
, then increment ; -
else increment
.
-
During the execution of this algorithm, each distinct pair
of indices
Consider the first sample input below. The windows appearing
during the execution of the algorithm are defined by
For each element
Input
The first line of input contains two integers
The next line contains
Output
For each element, in order, display the number of different windows it belongs to during the execution of the algorithm.
Sample Input 1 | Sample Output 1 |
---|---|
5 3 1 1 1 2 2 |
3 3 4 2 1 |
Sample Input 2 | Sample Output 2 |
---|---|
5 10 1 2 3 4 5 |
4 4 4 5 2 |