#CF2218G. The 67th Iteration of "Counting is Fun"

    ID: 7048 传统题 1000ms 256MiB 尝试: 1 已通过: 1 难度: 10 上传者: 标签>实现数学CodeforcesCodeforces Round 1090(Div4)Div4GCF2218G1800

The 67th Iteration of "Counting is Fun"

题目描述

nn 个人站成一排。未知数组 aa 满足 0ai<n0\le a_i<n,若 ai=0a_i=0 则第 ii 人在时间 00 坐下;否则在某时刻开始时,若此前已坐下人数至少为 aia_i,且至少一个相邻的人已坐下,则该人坐下。给定每个人坐下时间 bib_i,求有多少个数组 aa 能产生该 bb,答案模 676767677676767677

输入格式

第一行整数 tt。每组第一行 n,mn,m,第二行 nn 个整数 bib_i,且 00m1m-1 都出现。

输出格式

每组输出合法数组数量。

样例

7
4 3
0 1 2 0
8 4
0 1 2 3 1 2 0 1
9 5
1 0 1 3 4 3 2 1 0
15 14
3 0 1 2 3 4 5 6 7 8 9 10 11 12 13
5 5
4 3 0 1 2
5 2
0 1 1 1 0
3 2
0 1 1
2
0
1920
138007136
8
0
0

数据范围

1mn21051\le m\le n\le2\cdot10^5,所有测试 nn 之和不超过 21052\cdot10^5

来源

Codeforces Round 1090 (Div. 4), Problem G - The 67th Iteration of "Counting is Fun"