CF2234E.Vlad, Misha and Two Arrays

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Vlad thought of a permutation pp of length nn. After that, for each ii from 11 to nn, he counted the number of pairs l,rl, r such that 1≤l≤r≤n1 \leq l \leq r \leq n and the minimum number among pl,pl+1,…,prp_l, p_{l+1}, \ldots, p_r is equal to pip_i, and wrote this number into aia_i.

Now he gave Misha the numbers a1,a2,…,ana_1, a_2, \ldots, a_n and asked him to guess the permutation pp. However, Misha quickly realized that it is not always possible to uniquely restore the permutation pp. Therefore, he decided to surprise Vlad and tell him the number of suitable permutations pp modulo 109+710^9+7. Help him with this. Note that Vlad could have made a mistake, and there may be no such permutations.

弗拉德构思了一个长度为 nn 的排列 pp。之后,对于每个从 11 到 nn 的 ii,他统计了满足 1≤l≤r≤n1 \leq l \leq r \leq n 且子数组 pl,pl+1,…,prp_l, p_{l+1}, \ldots, p_r 中最小值恰好等于 pip_i 的区间对 (l,r)(l, r) 的数量,并将该数量记为 aia_i。

现在他将数组 a1,a2,…,ana_1, a_2, \ldots, a_n 告诉了米沙,让他据此猜出原排列 pp。然而,米沙很快意识到,原排列 pp 并不总是能被唯一确定。因此,他决定给弗拉德一个惊喜,告诉他自己算出的满足条件的排列 pp 的个数(对 109+710^9+7 取模)。请你帮他完成这项任务。注意:弗拉德可能出错,使得根本不存在满足条件的排列。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

In the first line of each test case, a natural number nn (1≤n≤5⋅1051 \leq n \leq 5 \cdot 10^5) is given — the size of the permutation.

In the second line of each test case, nn numbers a1,a2,…ana_1, a_2, \ldots a_n (1≤ai≤10121 \leq a_i \leq 10^{12}) are given — the array aa that Vlad gave to Misha.

It is guaranteed that the sum of nn over all test cases does not exceed 5⋅1055 \cdot 10^5.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1041 \le t \le 10^4)。随后是各测试用例的描述。

在每个测试用例的第一行中,给出一个自然数 nn(1≤n≤5⋅1051 \leq n \leq 5 \cdot 10^5)—— 即排列的大小。

在每个测试用例的第二行中,给出 nn 个数 a1,a2,…ana_1, a_2, \ldots a_n(1≤ai≤10121 \leq a_i \leq 10^{12})—— 即 Vlad 给 Misha 的数组 aa。

保证所有测试用例的 nn 之和不超过 5⋅1055 \cdot 10^5。

输出格式

For each test case, output the number of suitable permutations modulo 109+710^9+7.

对于每个测试用例,输出满足条件的排列数量对 109+710^9+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]p = [2, 1, 3] and p=[3,1,2]p = [3, 1, 2].

In the second test case, the only suitable permutation is p=[4,3,2,1]p = [4, 3, 2, 1].

In the fourth test case, it can be shown that no permutation pp corresponds to the array aa.

在第一个测试用例中,恰好存在两个合适的排列:p=[2,1,3]p = [2, 1, 3] 和 p=[3,1,2]p = [3, 1, 2]。

在第二个测试用例中,唯一的合适排列是 p=[4,3,2,1]p = [4, 3, 2, 1]。

在第四个测试用例中,可以证明不存在任何排列 pp 与数组 aa 对应。

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

首页