CF1748E.Yet Another Array Counting Problem
普及/提高-
通过率:0%
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 .
输入格式
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 .
输出格式
For each test case print one integer — the number of arrays b that satisfy the conditions from the statement, modulo 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] .