CF2155C.The Ancient Wizards' Capes

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

There are nn wizards in a row numbered 11 to nn from left to right. Each wizard has an invisibility cape which can be worn either on his left side or on his right side. Harry walks from the position of wizard 11 until the position of wizard nn (1≤n≤1051 \le n \le 10^5), and registers how many wizards he sees from each wizard's position. A wizard in position jj is visible from position ii if:

  • Wizard jj wears his cape on his left side and i≥ji \ge j.
  • Wizard jj wears his cape on his right side and i≤ji \le j.

In particular, note that wizard ii is visible from position ii.

Harry's list is very old but, after much work, you managed to decipher it. The list is an array aa of nn elements, where the ii-th element aia_i (1≤ai≤n1 \le a_i \le n) is the number of wizards that Harry saw from the position of wizard ii.

Your task is to determine how many of all the possible cape arrangements that Harry could have seen are consistent with the data recorded by the list, modulo 676 767 677676\,767\,677.

有 nn 个巫师从左到右排成一列,编号为 11 到 nn。每位巫师拥有一件隐形斗篷,可披在左侧或右侧。哈利从巫师 11 的位置出发,一直走到巫师 nn 的位置(1≤n≤1051 \le n \le 10^5),并记录下从每位巫师位置所能看到的巫师数量。位置为 jj 的巫师在位置 ii 处可见,当且仅当满足以下任一条件:

  • 巫师 jj 将斗篷披在左侧,且 i≥ji \ge j;
  • 巫师 jj 将斗篷披在右侧,且 i≤ji \le j。

特别地,请注意:巫师 ii 在其自身位置 ii 处总是可见的。

哈利的记录清单年代久远,但经过大量努力,你已成功将其破译。该清单是一个长度为 nn 的数组 aa,其中第 ii 个元素 aia_i(1≤ai≤n1 \le a_i \le n)表示哈利从巫师 ii 的位置所看到的巫师总数。

你的任务是:计算所有可能的斗篷穿戴方式中,有多少种与清单 aa 所记录的数据一致,结果对 676 767 677676\,767\,677 取模。

输入格式

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.

The first line of each test case contains a single integer nn (1≤n≤1051 \le n \le 10^5) — the length of aa.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤n1 \le a_i \le n) — the elements of aa.

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5.

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

每个测试用例的第一行包含一个整数 nn(1≤n≤1051 \le n \le 10^5)—— 数组 aa 的长度。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤n1 \le a_i \le n)—— 数组 aa 的元素。

保证所有测试用例的 nn 之和不超过 10510^5。

输出格式

For each test case, print one integer — the number of arrangements for the wizards' capes that satisfy the condition, modulo 676 767 677676\,767\,677.

对于每个测试用例,输出一个整数——满足条件的巫师斗篷排列方案数,对 676 767 677676\,767\,677 取模。

输入输出样例

  • 输入#1

    7
    1
    1
    4
    4 4 3 2
    3
    1 3 2
    2
    2 1
    3
    2 2 2
    3
    3 2 3
    3
    3 2 2

    输出#1

    2
    1
    0
    1
    2
    0
    0

说明/提示

The image below shows an arrangement of capes that matches Harry's list in the second test case.

Wizard 1 has the invisibility cape on his left side, while wizards 22, 33, and 44 wear it on their right side.

  • From position 11, we can see wizards 11, 22, 33, and 44.
  • From position 22, we can see wizards 11, 22, 33, and 44.
  • From position 33, we can see wizards 11, 33, and 44.
  • From position 44, we can see wizards 11 and 44.

Thus, Harry's list ends up being [4,4,3,2][4, 4, 3, 2]. It can be proved that this is the only possible arrangement.

In the third test case, it can be proved that Harry could not have obtained his list from any cape arrangement.

In the fifth case, note that there are two possible cape arrangements from which Harry could have gotten his list:

  • 1∣∣23 ∣1 \mid \quad \mid 2 \quad 3 \, \mid
  • ∣ 12∣∣3\mid \, 1 \quad 2 \mid \quad \mid 3

下图展示了一种斗篷排列方式,该方式与第二个测试用例中哈利的列表相匹配。

巫师 1 将隐形斗篷戴在左侧,而巫师 22、33 和 44 则将其戴在右侧。

  • 从位置 11 出发,我们可以看到巫师 11、22、33 和 44;
  • 从位置 22 出发,我们可以看到巫师 11、22、33 和 44;
  • 从位置 33 出发,我们可以看到巫师 11、33 和 44;
  • 从位置 44 出发,我们可以看到巫师 11 和 44。

因此,哈利的列表最终为 [4,4,3,2][4, 4, 3, 2]。可以证明,这是唯一可能的排列方式。

在第三个测试用例中,可以证明:不存在任何斗篷排列方式,能使哈利得到他所记录的列表。

在第五个测试用例中,请注意存在两种可能的斗篷排列方式,均能产生哈利所记录的列表:

  • 1∣∣23 ∣1 \mid \quad \mid 2 \quad 3 \, \mid
  • ∣ 12∣∣3\mid \, 1 \quad 2 \mid \quad \mid 3

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

首页