Vlad、Misha 和两个数组AI (CI翻译)
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 \leq l \leq r \leq n$ and the minimum number among $p_l, p_{l+1}, \ldots, p_r$ is equal to $p_i$, and wrote this number into $a_i$.
Vlad 想出了一个长度为 $n$ 的排列 $p$。随后,对于每个从 $1$ 到 $n$ 的 $i$,他统计满足 $1 \leq l \leq r \leq n$ 且 $p_l, p_{l+1}, \ldots, p_r$ 中的最小值等于 $p_i$ 的数对 $l, r$ 的数量,并将这个数量写入 $a_i$。AI (CI翻译)
Now he gave Misha the numbers $a_1, a_2, \ldots, a_n$ 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 $10^9+7$. Help him with this. Note that Vlad could have made a mistake, and there may be no such permutations.
现在,他把数字 $a_1, a_2, \ldots, a_n$ 交给 Misha,并让他猜出排列 $p$。然而,Misha 很快意识到,排列 $p$ 并不总能被唯一还原。因此,他决定给 Vlad 一个惊喜,告诉他满足条件的排列 $p$ 的数量对 $10^9+7$ 取模后的结果。请帮助他完成这个任务。注意,Vlad 可能犯了错误,因此可能不存在这样的排列。AI (CI翻译)
Input
输入格式
AI (CI翻译)Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.
每个测试包含多个测试用例。第一行包含测试用例的数量 $t$($1 \leq t \leq 10^4$)。接下来是各测试用例的描述。AI (CI翻译)
In the first line of each test case, a natural number $n$ ($1 \leq n \leq 5 \cdot 10^5$) is given — the size of the permutation.
每个测试用例的第一行包含一个正整数 $n$($1 \leq n \leq 5 \cdot 10^5$),表示排列的长度。AI (CI翻译)
In the second line of each test case, $n$ numbers $a_1, a_2, \ldots a_n$ ($1 \leq a_i \leq 10^{12}$) are given — the array $a$ that Vlad gave to Misha.
每个测试用例的第二行包含 $n$ 个数字 $a_1, a_2, \ldots a_n$($1 \leq a_i \leq 10^{12}$),表示 Vlad 交给 Misha 的数组 $a$。AI (CI翻译)
It is guaranteed that the sum of $n$ over all test cases does not exceed $5 \cdot 10^5$.
保证所有测试用例的 $n$ 之和不超过 $5 \cdot 10^5$。AI (CI翻译)
Output
输出格式
AI (CI翻译)For each test case, output the number of suitable permutations modulo $10^9+7$.
对于每个测试用例,输出满足条件的排列数量对 $10^9+7$ 取模后的结果。AI (CI翻译)
Note
说明
AI (CI翻译)In the first test case, there exist exactly two suitable permutations: $p = [2, 1, 3]$ and $p = [3, 1, 2]$.
在第一个测试用例中,恰好存在两个满足条件的排列:$p = [2, 1, 3]$ 和 $p = [3, 1, 2]$。AI (CI翻译)
In the second test case, the only suitable permutation is $p = [4, 3, 2, 1]$.
在第二个测试用例中,只有一个满足条件的排列,即 $p = [4, 3, 2, 1]$。AI (CI翻译)
In the fourth test case, it can be shown that no permutation $p$ corresponds to the array $a$.
在第四个测试用例中,可以证明不存在排列 $p$ 与数组 $a$ 对应。AI (CI翻译)
样例
4
3
1 4 1
4
1 2 3 4
4
1 6 1 2
3
3 3 3
2
1
3
0
题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。