menu ZJOJ
account_circle 请登录
home
首页
book
题目
apps
分类
play_circle_outline
状态
assessment
竞赛
assignment
作业
equalizer
排名
assignment_ind
登录
person_add
注册
1561: 青原樱
时间限制:1.000s
内存限制:128MB

题目描述

小紫是一个非常喜欢边听古风鸽边写数学题的人,因此这道题其实是个五三原题。

小紫希望重现青原上樱花盛开的景色,于是他准备了很多互不相同樱花树幼苗,准备种成一行。

这一行中,一共有 n 个位置可以种下樱花,而小紫准备了 m 支幼苗。由于樱花盛放时对左右空间需求非常大,所以樱花不能紧挨着种植,也就是任意两支幼苗之间必须至少存在一个不种花的空位置。

按照这种方式种花并不难,但是令小紫感到好奇的是一共有多少合法的方案让他把这 m支幼苗都种下去。一个方案是合法的当且仅当他满足上一段中叙述的要求。如果我们将花按照 1,2,3,…,m 编号,两种方案不同当且仅当被选择种花的位置不同或从左向右数花的编号序列不同。

为了避免输出过大,答案对一个参数 p 取模。

输入格式

每个输入中有且仅有一组测试数据。

测试数据只有一行四个整数,依次代表 lns="http://www.w3.org/1998/Math/MathML">type,~n,~m,~p,其中 lns="http://www.w3.org/1998/Math/MathML">type 是一个帮助你判断测试点类型的参数,会在数据范围中说明。


输出格式

输出一行一个整数,代表答案对 lns="http://www.w3.org/1998/Math/MathML">p 取模的结果

样例输入 content_copy

1 3 2 19260718

样例输出 content_copy

2

提示/说明

样例输入输出 1 解释

一共有 lns="http://www.w3.org/1998/Math/MathML">2 个樱花幼苗, lns="http://www.w3.org/1998/Math/MathML">3 个种花的位置,如果给幼苗编号为 lns="http://www.w3.org/1998/Math/MathML">1,~2,位置编号为 lns="http://www.w3.org/1998/Math/MathML">1,~2,~3,那么两种方案分别如下:

位置 lns="http://www.w3.org/1998/Math/MathML">1 lns="http://www.w3.org/1998/Math/MathML">2 lns="http://www.w3.org/1998/Math/MathML">3
方案 1 幼苗 lns="http://www.w3.org/1998/Math/MathML">1 幼苗 lns="http://www.w3.org/1998/Math/MathML">2
方案 2 幼苗 lns="http://www.w3.org/1998/Math/MathML">2 幼苗 lns="http://www.w3.org/1998/Math/MathML">1


数据规模与约定



本题采用多测试点捆绑测试,共有 6 个子任务

子任务编号 lns="http://www.w3.org/1998/Math/MathML">n \leq lns="http://www.w3.org/1998/Math/MathML">m \leq lns="http://www.w3.org/1998/Math/MathML">type= 特殊性质 子任务分值
1 lns="http://www.w3.org/1998/Math/MathML">1 lns="http://www.w3.org/1998/Math/MathML">1 lns="http://www.w3.org/1998/Math/MathML">0 特殊性质 1 lns="http://www.w3.org/1998/Math/MathML">5
2 lns="http://www.w3.org/1998/Math/MathML">20 lns="http://www.w3.org/1998/Math/MathML">20 lns="http://www.w3.org/1998/Math/MathML">1 特殊性质 1 lns="http://www.w3.org/1998/Math/MathML">15
3 lns="http://www.w3.org/1998/Math/MathML">400 lns="http://www.w3.org/1998/Math/MathML">200 lns="http://www.w3.org/1998/Math/MathML">2 lns="http://www.w3.org/1998/Math/MathML">20
4 lns="http://www.w3.org/1998/Math/MathML">2000 lns="http://www.w3.org/1998/Math/MathML">2000 lns="http://www.w3.org/1998/Math/MathML">3 lns="http://www.w3.org/1998/Math/MathML">20
5 lns="http://www.w3.org/1998/Math/MathML">2000000 lns="http://www.w3.org/1998/Math/MathML">1000000 lns="http://www.w3.org/1998/Math/MathML">4 特殊性质 2 lns="http://www.w3.org/1998/Math/MathML">20
6 lns="http://www.w3.org/1998/Math/MathML">2000000 lns="http://www.w3.org/1998/Math/MathML">1000000 lns="http://www.w3.org/1998/Math/MathML">5 lns="http://www.w3.org/1998/Math/MathML">20

特殊性质 1:保证对应测试点的实际方案数(在取模前)不超过 lns="http://www.w3.org/1998/Math/MathML">10^6

特殊性质 2:保证 lns="http://www.w3.org/1998/Math/MathML">p 是一个质数。

对于 lns="http://www.w3.org/1998/Math/MathML">100\% 的数据,保证:

  • lns="http://www.w3.org/1998/Math/MathML">1 \leq n \leq 2 \times 10^6
  • lns="http://www.w3.org/1998/Math/MathML">1 \leq m \leq 10^6
  • lns="http://www.w3.org/1998/Math/MathML">1 \leq p \leq 10^9
  • lns="http://www.w3.org/1998/Math/MathML">1 \leq m \leq \lceil\frac{n}{2} \rceil

提示

  • 请使用合适的数据类型来进行运算,避免溢出。
  • 参数 lns="http://www.w3.org/1998/Math/MathML">type 可以帮助你快速的判断子任务编号。