CF2234E.Vlad, Misha and Two Arrays
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Vlad thought of a permutation p of length n. After that, for each i from 1 to n, he counted the number of pairs l,r such that 1≤l≤r≤n and the minimum number among pl,pl+1,…,pr is equal to pi, and wrote this number into ai.
Now he gave Misha the numbers a1,a2,…,an and asked him to guess the permutation p. However, Misha quickly realized that it is not always possible to uniquely restore the permutation p. Therefore, he decided to surprise Vlad and tell him the number of suitable permutations p modulo 109+7. Help him with this. Note that Vlad could have made a mistake, and there may be no such permutations.
弗拉德构思了一个长度为 n 的排列 p。之后,对于每个从 1 到 n 的 i,他统计了满足 1≤l≤r≤n 且子数组 pl,pl+1,…,pr 中最小值恰好等于 pi 的区间对 (l,r) 的数量,并将该数量记为 ai。
现在他将数组 a1,a2,…,an 告诉了米沙,让他据此猜出原排列 p。然而,米沙很快意识到,原排列 p 并不总是能被唯一确定。因此,他决定给弗拉德一个惊喜,告诉他自己算出的满足条件的排列 p 的个数(对 109+7 取模)。请你帮他完成这项任务。注意:弗拉德可能出错,使得根本不存在满足条件的排列。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
In the first line of each test case, a natural number n (1≤n≤5⋅105) is given — the size of the permutation.
In the second line of each test case, n numbers a1,a2,…an (1≤ai≤1012) are given — the array a that Vlad gave to Misha.
It is guaranteed that the sum of n over all test cases does not exceed 5⋅105.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
在每个测试用例的第一行中,给出一个自然数 n(1≤n≤5⋅105)—— 即排列的大小。
在每个测试用例的第二行中,给出 n 个数 a1,a2,…an(1≤ai≤1012)—— 即 Vlad 给 Misha 的数组 a。
保证所有测试用例的 n 之和不超过 5⋅105。
输出格式
For each test case, output the number of suitable permutations modulo 109+7.
对于每个测试用例,输出满足条件的排列数量对 109+7 取模的结果。
输入输出样例
输入#1
4 3 1 4 1 4 1 2 3 4 4 1 6 1 2 3 3 3 3
输出#1
2 1 3 0
说明/提示
In the first test case, there exist exactly two suitable permutations: p=[2,1,3] and p=[3,1,2].
In the second test case, the only suitable permutation is p=[4,3,2,1].
In the fourth test case, it can be shown that no permutation p corresponds to the array a.
在第一个测试用例中,恰好存在两个合适的排列:p=[2,1,3] 和 p=[3,1,2]。
在第二个测试用例中,唯一的合适排列是 p=[4,3,2,1]。
在第四个测试用例中,可以证明不存在任何排列 p 与数组 a 对应。
输入解题思路,AI测评打分。不知道怎么写?