CF1833F.Ira and Flamenco
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Ira loves Spanish flamenco dance very much. She decided to start her own dance studio and found n students, ith of whom has level ai.
Ira can choose several of her students and set a dance with them. So she can set a huge number of dances, but she is only interested in magnificent dances. The dance is called magnificent if the following is true:
- exactly m students participate in the dance;
- levels of all dancers are pairwise distinct;
- levels of every two dancers have an absolute difference strictly less than m.
For example, if m=3 and a=[4,2,2,3,6], the following dances are magnificent (students participating in the dance are highlighted in red): [4,2,2,3,6], [4,2,2,3,6]. At the same time dances [4,2,2,3,6], [4,2,2,3,6], [4,2,2,3,6] are not magnificent.
In the dance [4,2,2,3,6] only 2 students participate, although m=3.
The dance [4,2,2,3,6] involves students with levels 2 and 2, although levels of all dancers must be pairwise distinct.
In the dance [4,2,2,3,6] students with levels 3 and 6 participate, but ∣3−6∣=3, although m=3.
Help Ira count the number of magnificent dances that she can set. Since this number can be very large, count it modulo 109+7. Two dances are considered different if the sets of students participating in them are different.
伊菈非常热爱西班牙弗拉门戈舞蹈。她决定创办自己的舞蹈工作室,并找到了 n 名学生,其中第 i 名学生的舞蹈水平为 ai。
伊菈可以选择她的一些学生来编排一支舞蹈。因此,她可以编排出大量不同的舞蹈,但她只对“辉煌舞蹈”(magnificent dance)感兴趣。一支舞蹈被称为“辉煌舞蹈”,当且仅当满足以下全部条件:
- 恰好有 m 名学生参与该舞蹈;
- 所有舞者的水平两两互不相同;
- 任意两名舞者的水平之差的绝对值严格小于 m。
例如,若 m=3,且 a=[4,2,2,3,6],则以下舞蹈是辉煌舞蹈(参与舞蹈的学生以红色高亮显示):[4,2,2,3,6]、[4,2,2,3,6]。而以下舞蹈则不是辉煌舞蹈:[4,2,2,3,6]、[4,2,2,3,6]、[4,2,2,3,6]。
在舞蹈 [4,2,2,3,6] 中,仅有 2 名学生参与,但要求 m=3。
舞蹈 [4,2,2,3,6] 中包含了两名水平均为 2 的学生,但所有舞者水平必须两两互不相同。
舞蹈 [4,2,2,3,6] 中包含了水平为 3 和 6 的学生,但 ∣3−6∣=3,而要求该差值严格小于 m=3。
请帮助伊菈计算她能编排的辉煌舞蹈的数量。由于该数量可能非常大,请对 109+7 取模输出结果。若两支舞蹈所包含的学生集合不同,则视为不同的舞蹈。
输入格式
The first line contains a single integer t (1≤t≤104) — number of testcases.
The first line of each testcase contains integers n and m (1≤m≤n≤2⋅105) — the number of Ira students and the number of dancers in the magnificent dance.
The second line of each testcase contains n integers a1,a2,…,an (1≤ai≤109) — levels of students.
It is guaranteed that the sum of n over all testcases does not exceed 2⋅105.
第一行包含一个整数 t(1≤t≤104)—— 测试用例的数量。
每个测试用例的第一行包含两个整数 n 和 m(1≤m≤n≤2⋅105)—— 分别表示伊菈的学生人数和盛大舞蹈中的舞者人数。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤109)—— 表示各位学生的水平。
保证所有测试用例的 n 值之和不超过 2⋅105。
输出格式
For each testcase, print a single integer — the number of magnificent dances. Since this number can be very large, print it modulo 109+7.
对于每个测试用例,输出一个整数——壮丽舞蹈的数量。由于该数可能非常大,请对 109+7 取模后输出。
输入输出样例
输入#1
9 7 4 8 10 10 9 6 11 7 5 3 4 2 2 3 6 8 2 1 5 2 2 3 1 3 3 3 3 3 3 3 5 1 3 4 3 10 7 12 3 5 2 1 1 4 3 5 5 5 2 7 5 1 1 1 3 2 1 2 3 2 2 1 2
输出#1
5 2 10 0 5 11 1 2 1
说明/提示
In the first testcase, Ira can set such magnificent dances: [8,10,10,9,6,11,7], [8,10,10,9,6,11,7], [8,10,10,9,6,11,7], [8,10,10,9,6,11,7], [8,10,10,9,6,11,7].
The second testcase is explained in the statements.
在第一个测试用例中,Ira 可以设置如下精彩的舞蹈序列:[8,10,10,9,6,11,7]、[8,10,10,9,6,11,7]、[8,10,10,9,6,11,7]、[8,10,10,9,6,11,7]、[8,10,10,9,6,11,7]。
第二个测试用例已在题目描述中说明。
输入解题思路,AI测评打分。不知道怎么写?