CF1748E.Yet Another Array Counting Problem

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

The position of the leftmost maximum on the segment [l;r][l; r] of array x=[x1,x2,…,xn]x = [x_1, x_2, \ldots, x_n] is the smallest integer ii such that l≤i≤rl \le i \le r and xi=max⁡(xl,xl+1,…,xr)x_i = \max(x_l, x_{l+1}, \ldots, x_r).

You are given an array a=[a1,a2,…,an]a = [a_1, a_2, \ldots, a_n] of length nn. Find the number of integer arrays b=[b1,b2,…,bn]b = [b_1, b_2, \ldots, b_n] of length nn that satisfy the following conditions:

  • 1≤bi≤m1 \le b_i \le m for all 1≤i≤n1 \le i \le n;
  • for all pairs of integers 1≤l≤r≤n1 \le l \le r \le n, the position of the leftmost maximum on the segment [l;r][l; r] of the array bb is equal to the position of the leftmost maximum on the segment [l;r][l; r] of the array aa.

Since the answer might be very large, print its remainder modulo 109+710^9+7.

数组 x=[x1,x2,…,xn]x = [x_1, x_2, \ldots, x_n] 在区间 [l;r][l; r] 上的最左最大值位置,是指满足 l≤i≤rl \le i \le r 且 xi=max⁡(xl,xl+1,…,xr)x_i = \max(x_l, x_{l+1}, \ldots, x_r) 的最小整数 ii。

给定一个长度为 nn 的数组 a=[a1,a2,…,an]a = [a_1, a_2, \ldots, a_n]。请计算满足以下条件的长度为 nn 的整数数组 b=[b1,b2,…,bn]b = [b_1, b_2, \ldots, b_n] 的个数:

  • 对所有 1≤i≤n1 \le i \le n,有 1≤bi≤m1 \le b_i \le m;
  • 对所有整数对 1≤l≤r≤n1 \le l \le r \le n,数组 bb 在区间 [l;r][l; r] 上的最左最大值位置等于数组 aa 在区间 [l;r][l; r] 上的最左最大值位置。

由于答案可能非常大,请输出其对 109+710^9+7 取模的结果。

输入格式

Each test contains multiple test cases. The first line contains a single integer tt (1≤t≤1031 \le t \le 10^3) — the number of test cases.

The first line of each test case contains two integers nn and mm (2≤n,m≤2⋅1052 \le n,m \le 2 \cdot 10^5, n⋅m≤106n \cdot m \le 10^6).

The second line of each test case contains nn integers a1,a2,…,ana_1,a_2,\ldots,a_n (1≤ai≤m1 \le a_i \le m) — the array aa.

It is guaranteed that the sum of n⋅mn \cdot m over all test cases doesn't exceed 10610^6.

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤1031 \le t \le 10^3),表示测试用例的数量。

每个测试用例的第一行包含两个整数 nn 和 mm(2≤n,m≤2⋅1052 \le n,m \le 2 \cdot 10^5,且 n⋅m≤106n \cdot m \le 10^6)。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1,a_2,\ldots,a_n(1≤ai≤m1 \le a_i \le m),表示数组 aa。

保证所有测试用例的 n⋅mn \cdot m 之和不超过 10610^6。

输出格式

For each test case print one integer — the number of arrays bb that satisfy the conditions from the statement, modulo 109+710^9+7.

对于每个测试用例,输出一个整数——满足题目条件的数组 bb 的个数,对 109+710^9+7 取模。

输入输出样例

  • 输入#1

    4
    3 3
    1 3 2
    4 2
    2 2 2 2
    6 9
    6 9 6 9 6 9
    9 100
    10 40 20 20 100 60 80 60 60

    输出#1

    8
    5
    11880
    351025663

说明/提示

In the first test case, the following 88 arrays satisfy the conditions from the statement:

  • [1,2,1][1,2,1];
  • [1,2,2][1,2,2];
  • [1,3,1][1,3,1];
  • [1,3,2][1,3,2];
  • [1,3,3][1,3,3];
  • [2,3,1][2,3,1];
  • [2,3,2][2,3,2];
  • [2,3,3][2,3,3].

In the second test case, the following 55 arrays satisfy the conditions from the statement:

  • [1,1,1,1][1,1,1,1];
  • [2,1,1,1][2,1,1,1];
  • [2,2,1,1][2,2,1,1];
  • [2,2,2,1][2,2,2,1];
  • [2,2,2,2][2,2,2,2].

在第一个测试用例中,以下 88 个数组满足题目所述的条件:

  • [1,2,1][1,2,1];
  • [1,2,2][1,2,2];
  • [1,3,1][1,3,1];
  • [1,3,2][1,3,2];
  • [1,3,3][1,3,3];
  • [2,3,1][2,3,1];
  • [2,3,2][2,3,2];
  • [2,3,3][2,3,3]。

在第二个测试用例中,以下 55 个数组满足题目所述的条件:

  • [1,1,1,1][1,1,1,1];
  • [2,1,1,1][2,1,1,1];
  • [2,2,1,1][2,2,1,1];
  • [2,2,2,1][2,2,2,1];
  • [2,2,2,2][2,2,2,2]。

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

首页