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] of array x=[x1,x2,…,xn] is the smallest integer i such that l≤i≤r and xi=max(xl,xl+1,…,xr).
You are given an array a=[a1,a2,…,an] of length n. Find the number of integer arrays b=[b1,b2,…,bn] of length n that satisfy the following conditions:
- 1≤bi≤m for all 1≤i≤n;
- for all pairs of integers 1≤l≤r≤n, the position of the leftmost maximum on the segment [l;r] of the array b is equal to the position of the leftmost maximum on the segment [l;r] of the array a.
Since the answer might be very large, print its remainder modulo 109+7.
数组 x=[x1,x2,…,xn] 在区间 [l;r] 上的最左最大值位置,是指满足 l≤i≤r 且 xi=max(xl,xl+1,…,xr) 的最小整数 i。
给定一个长度为 n 的数组 a=[a1,a2,…,an]。请计算满足以下条件的长度为 n 的整数数组 b=[b1,b2,…,bn] 的个数:
- 对所有 1≤i≤n,有 1≤bi≤m;
- 对所有整数对 1≤l≤r≤n,数组 b 在区间 [l;r] 上的最左最大值位置等于数组 a 在区间 [l;r] 上的最左最大值位置。
由于答案可能非常大,请输出其对 109+7 取模的结果。
输入格式
Each test contains multiple test cases. The first line contains a single integer t (1≤t≤103) — the number of test cases.
The first line of each test case contains two integers n and m (2≤n,m≤2⋅105, n⋅m≤106).
The second line of each test case contains n integers a1,a2,…,an (1≤ai≤m) — the array a.
It is guaranteed that the sum of n⋅m over all test cases doesn't exceed 106.
每个测试包含多个测试用例。第一行包含一个整数 t(1≤t≤103),表示测试用例的数量。
每个测试用例的第一行包含两个整数 n 和 m(2≤n,m≤2⋅105,且 n⋅m≤106)。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤m),表示数组 a。
保证所有测试用例的 n⋅m 之和不超过 106。
输出格式
For each test case print one integer — the number of arrays b that satisfy the conditions from the statement, modulo 109+7.
对于每个测试用例,输出一个整数——满足题目条件的数组 b 的个数,对 109+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 8 arrays satisfy the conditions from the statement:
- [1,2,1];
- [1,2,2];
- [1,3,1];
- [1,3,2];
- [1,3,3];
- [2,3,1];
- [2,3,2];
- [2,3,3].
In the second test case, the following 5 arrays satisfy the conditions from the statement:
- [1,1,1,1];
- [2,1,1,1];
- [2,2,1,1];
- [2,2,2,1];
- [2,2,2,2].
在第一个测试用例中,以下 8 个数组满足题目所述的条件:
- [1,2,1];
- [1,2,2];
- [1,3,1];
- [1,3,2];
- [1,3,3];
- [2,3,1];
- [2,3,2];
- [2,3,3]。
在第二个测试用例中,以下 5 个数组满足题目所述的条件:
- [1,1,1,1];
- [2,1,1,1];
- [2,2,1,1];
- [2,2,2,1];
- [2,2,2,2]。
输入解题思路,AI测评打分。不知道怎么写?