PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#FT0000048. Nghịch thế trong cửa sổ trượt (Sliding Window Inversions)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

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 x1,x2,…,xnx_1,x_2,\ldots,x_n and integer kk, count the pairs of positions (i,j)(i,j) within each contiguous window of length kk satisfying i<ji<j and xi>xjx_i>x_j.

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 n,kn,k, array length and window length.
  • Line 2: nn integers x1,x2,…,xnx_1,x_2,\ldots,x_n.

Output

Print n−k+1n-k+1 integers on one line, one inversion count per window.

Subtasks

Subtask 1 (20 points):

  • 1≤k≤n≤201\le k\le n\le 20; 1≤xi≤1091\le x_i\le 10^9 for every 1≤i≤n1\le i\le n.

Subtask 2 (30 points):

  • 1≤k≤n≤20001\le k\le n\le 2000; 1≤xi≤1091\le x_i\le 10^9 for every 1≤i≤n1\le i\le n.

Subtask 3 (50 points):

  • 1≤k≤n≤2000001\le k\le n\le 200000; 1≤xi≤1091\le x_i\le 10^9 for every 1≤i≤n1\le i\le n.

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 0,1,1,1,2,00,1,1,1,2,0. In [5,2,4][5,2,4], the inversions are 5>25>2 and 5>45>4. In [2,4,4][2,4,4], 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 [8,8][8,8] contains no inversion; [8,7][8,7] contains one; [7,9][7,9] contains none.

An inversion requires the left value to be strictly larger than the right one. The equal values in [8,8][8,8] give zero inversions. The pair (8,7)(8,7) in the second window is an inversion, while 7>97>9 is false in the last window.