#P13969. [VKOSHP 2024] Exchange and Deletion

[VKOSHP 2024] Exchange and Deletion

题目描述

There is a classic way to remove an element from an array: swap the values of the element to be removed and the last element of the array, and then delete the last element. Unfortunately, it turned out that this method does not always preserve the order of the elements in the array. Your task is to count the number of sequences of kk deletions after which the initially sorted array in ascending order will remain sorted.

You are given an array aa of length nn, initially filled with numbers from 11 to nn in ascending order, that is, ai=ia_i=i, and an array bb of length kk, whose elements are pairwise distinct numbers from 11 to nn.

There are kk steps performed, at the jj-th step the following occurs: an index ii is chosen from 11 to nj+1n-j+1 such that ai=bja_i=b_j, after which aia_i and anj+1a_{n-j+1} are swapped (if i=nj+1i=n-j+1, nothing happens). Then the last element of the array at this step, which has the index nj+1n - j + 1, is removed from the array.

The array [b1,b2,,bk][b_1,b_2,\ldots,b_k] is called good\textit{good} if after performing kk steps the array [a1,a2,,ank][a_1,a_2,\ldots,a_{n-k}] is strictly increasing.

You are given the numbers nn and kk, count the number of good arrays [b1,b2,,bk][b_1,b_2,\ldots,b_k]. The answer may be too large, so output the remainder of the answer when divided by 109+710^9+7.

输入格式

The first line contains an integer tt (1t1041 \le t \le 10^4) --- the number of test cases. In the following tt lines, the test cases are provided.

In the first line of each test case, the integers nn and kk are given (1n51051 \le n \le 5\cdot 10^5, 0kn0 \le k \le n).

It is guaranteed that the sum of nn across all test cases does not exceed 51055\cdot 10^5.

输出格式

For each test case, output a single integer --- the number of good arrays bb, taken modulo 109+710^9+7.

5
1 0
1 1
2 2
3 1
4 2
1
1
2
2
7

提示

Let's analyze the fourth test from the example. In it, n=3n=3 and k=1k=1. Initially, a=[1,2,3]a=[1,2,3]. Let's see how aa changes after the first step for all possible arrays bb.

  • b=[1]b=[1]. Then aa changes as follows: [1,2,3][3,2,1][3,2][1, 2, 3]\to[3,2,1]\to[3,2]. The array [3,2][3,2] is not increasing.
  • b=[2]b=[2]. Then aa changes as follows: [1,2,3][1,3,2][1,3][1, 2, 3]\to[1,3,2]\to[1,3]. The array [1,3][1,3] is increasing.
  • b=[3]b=[3]. Then aa changes as follows: [1,2,3][1,2,3][1,2][1, 2, 3]\to[1,2,3]\to[1,2]. The array [1,2][1,2] is increasing.

We find that there are two good arrays b=[2]b=[2] and b=[3]b=[3], so the answer to the fourth test from the example is 22.