CF2242C.Unstable Elements

普及-

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given a sorted array of integers [a1,a2,…,an][a_1, a_2, \dots, a_n]. We can perform any number of operations of the following type on this array:

  • mark the first element of the array, as well as all elements that are not equal to their left neighbors (that is, all elements ii such that ai≠ai−1a_i \ne a_{i-1}).
  • then either delete all marked elements or duplicate them (that is, replace each marked element with two identical elements).

For example, consider the array [1,1,1,2,4,4,5][\mathbf{1}, 1, 1, \mathbf{2}, \mathbf{4}, 4, \mathbf{5}] (marked elements are shown in bold). If we delete all marked elements, we get [1,1,4][1, 1, 4], and if we duplicate them, we get [1,1,1,1,2,2,4,4,4,5,5][1, 1, 1, 1, 2, 2, 4, 4, 4, 5, 5].

The operations cannot be performed if the array becomes empty. After each operation, every element gets unmarked.

We call an array of integers bb reachable if it can be obtained from array aa by some number of the described operations. Your task is to count the number of reachable arrays of length kk.

给你一个已排序的整数数组 [a1,a2,…,an][a_1, a_2, \dots, a_n]。你可以对该数组执行任意多次如下类型的操作:

  • 标记数组的第一个元素,以及所有与其左侧相邻元素不相等的元素(即所有满足 ai≠ai−1a_i \ne a_{i-1} 的下标 ii 对应的元素);
  • 然后,要么删除所有被标记的元素,要么复制所有被标记的元素(即把每个被标记的元素替换为两个完全相同的元素)。

例如,考虑数组 [1,1,1,2,4,4,5][\mathbf{1}, 1, 1, \mathbf{2}, \mathbf{4}, 4, \mathbf{5}](加粗表示被标记的元素)。若删除所有被标记的元素,则得到 [1,1,4][1, 1, 4];若复制所有被标记的元素,则得到 [1,1,1,1,2,2,4,4,4,5,5][1, 1, 1, 1, 2, 2, 4, 4, 4, 5, 5]。

当数组变为空时,无法再执行操作。每次操作结束后,所有元素均取消标记。

若一个整数数组 bb 可通过从数组 aa 出发、执行若干次上述操作而得到,则称 bb 是可达的。你的任务是:计算长度为 kk 的可达数组的个数。

输入格式

The first line contains one integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases.

Each test case consists of two lines:

  • the first line contains two integers nn and kk (1≤n,k≤3⋅1051 \le n, k \le 3 \cdot 10^5);
  • the second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤a1≤a2≤⋯≤an≤n1 \le a_1 \le a_2 \le \dots \le a_n \le n). Note that the array is sorted.

Additional constraint on the input: the sum of nn over all test cases does not exceed 3⋅1053 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 表示测试用例的数量。

每个测试用例由两行组成:

  • 第一行包含两个整数 nn 和 kk(1≤n,k≤3⋅1051 \le n, k \le 3 \cdot 10^5);
  • 第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤a1≤a2≤⋯≤an≤n1 \le a_1 \le a_2 \le \dots \le a_n \le n)。注意:该数组已按非递减顺序排序。

输入的额外约束:所有测试用例的 nn 值之和不超过 3⋅1053 \cdot 10^5。

输出格式

For each test case, output one integer — the number of reachable arrays bb of length kk. It can be shown that, under the constraints of the problem, the answer fits into a standard 3232-bit integer type.

对于每个测试用例,输出一个整数——长度为 kk 的可达数组 bb 的个数。可以证明,在本题的约束条件下,答案可放入标准的 3232 位整数类型中。

输入输出样例

  • 输入#1

    10
    1 5
    1
    4 5
    1 1 2 2
    3 1
    1 1 1
    4 8
    1 2 3 4
    8 6
    1 1 1 2 2 2 2 2
    6 3
    1 1 2 2 3 3
    10 7
    1 1 1 2 2 3 3 3 3 4
    12 5
    1 1 1 1 2 2 2 3 3 4 4 4
    6 5
    1 1 2 2 3 3
    3 1
    1 2 2

    输出#1

    1
    0
    1
    1
    2
    1
    2
    1
    0
    1

说明/提示

In the first example, the following sequence of operations can be performed:

  • [1]→[1,1]→[1,1,1]→[1,1,1,1]→[1,1,1,1,1][\mathbf{1}] \rightarrow [\mathbf{1}, 1] \rightarrow [\mathbf{1}, 1, 1] \rightarrow [\mathbf{1}, 1, 1, 1] \rightarrow [1, 1, 1, 1, 1].

In the second example, it is impossible to obtain an array of length 55.

In the third example, the following sequence of operations can be performed:

  • [1,1,1]→[1,1]→[1][\mathbf{1}, 1, 1] \rightarrow [\mathbf{1}, 1] \rightarrow [1].

In the fifth example, the arrays [1,1,2,2,2,2][1, 1, 2, 2, 2, 2] and [2,2,2,2,2,2][2, 2, 2, 2, 2, 2] can be obtained:

  • [1,1,1,2,2,2,2,2]→[1,1,2,2,2,2][\mathbf{1}, 1, 1, \mathbf{2}, 2, 2, 2, 2] \rightarrow [1, 1, 2, 2, 2, 2];
  • [1,1,1,2,2,2,2,2]→[1,1,2,2,2,2]→[1,2,2,2]→[2,2]→[2,2,2]→[2,2,2,2]→[2,2,2,2,2]→[2,2,2,2,2,2][\mathbf{1}, 1, 1, \mathbf{2}, 2, 2, 2, 2] \rightarrow [\mathbf{1}, 1, \mathbf{2}, 2, 2, 2] \rightarrow [\mathbf{1}, \mathbf{2}, 2, 2] \rightarrow [\mathbf{2}, 2] \rightarrow [\mathbf{2}, 2, 2] \rightarrow [\mathbf{2}, 2, 2, 2] \rightarrow [\mathbf{2}, 2, 2, 2, 2] \rightarrow [2, 2, 2, 2, 2, 2].

In the seventh example, the arrays [1,1,1,3,3,3,3][1, 1, 1, 3, 3, 3, 3] and [3,3,3,3,3,3,3][3, 3, 3, 3, 3, 3, 3] can be obtained.

在第一个例子中,可以执行以下操作序列:

  • [1]→[1,1]→[1,1,1]→[1,1,1,1]→[1,1,1,1,1][\mathbf{1}] \rightarrow [\mathbf{1}, 1] \rightarrow [\mathbf{1}, 1, 1] \rightarrow [\mathbf{1}, 1, 1, 1] \rightarrow [1, 1, 1, 1, 1]。

在第二个例子中,无法得到长度为 55 的数组。

在第三个例子中,可以执行以下操作序列:

  • [1,1,1]→[1,1]→[1][\mathbf{1}, 1, 1] \rightarrow [\mathbf{1}, 1] \rightarrow [1]。

在第五个例子中,可以得到数组 [1,1,2,2,2,2][1, 1, 2, 2, 2, 2] 和 [2,2,2,2,2,2][2, 2, 2, 2, 2, 2]:

  • [1,1,1,2,2,2,2,2]→[1,1,2,2,2,2][\mathbf{1}, 1, 1, \mathbf{2}, 2, 2, 2, 2] \rightarrow [1, 1, 2, 2, 2, 2];
  • [1,1,1,2,2,2,2,2]→[1,1,2,2,2,2]→[1,2,2,2]→[2,2]→[2,2,2]→[2,2,2,2]→[2,2,2,2,2]→[2,2,2,2,2,2][\mathbf{1}, 1, 1, \mathbf{2}, 2, 2, 2, 2] \rightarrow [\mathbf{1}, 1, \mathbf{2}, 2, 2, 2] \rightarrow [\mathbf{1}, \mathbf{2}, 2, 2] \rightarrow [\mathbf{2}, 2] \rightarrow [\mathbf{2}, 2, 2] \rightarrow [\mathbf{2}, 2, 2, 2] \rightarrow [\mathbf{2}, 2, 2, 2, 2] \rightarrow [2, 2, 2, 2, 2, 2]。

在第七个例子中,可以得到数组 [1,1,1,3,3,3,3][1, 1, 1, 3, 3, 3, 3] 和 [3,3,3,3,3,3,3][3, 3, 3, 3, 3, 3, 3]。

输入解题思路,AI测评打分。不知道怎么写?

首页