#FT0000048. Nghịch thế trong cửa sổ trượt (Sliding Window Inversions)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Nghịch thế trong cửa sổ trượt (Sliding Window Inversions)
Sliding Window Inversions
Source: CSES
Version: Phuoc Hung OJ Extended
Problem Statement
Given and integer , count the pairs of positions within each contiguous window of length satisfying and .
Such a pair is an inversion. The inequality is strict: equal values do not form an inversion. Positions retain their left-to-right order as the window moves. Output each window's count from left to right.
Input
- Line 1: integers , array length and window length.
- Line 2: integers .
Output
Print integers on one line, one inversion count per window.
Subtasks
Subtask 1 (20 points):
- ; for every .
Subtask 2 (30 points):
- ; for every .
Subtask 3 (50 points):
- ; for every .
Examples
Examples 1
Input
8 3
1 2 3 2 5 2 4 4
Output
0 1 1 1 2 0
Explanation
The six windows have inversion counts . In , the inversions are and . In , the equal fours do not count, leaving zero inversions.
Examples 2
Input
4 2
8 8 7 9
Output
0 1 0
Explanation
The equal pair contains no inversion; contains one; contains none.
An inversion requires the left value to be strictly larger than the right one. The equal values in give zero inversions. The pair in the second window is an inversion, while is false in the last window.