CF272D.Dima and Two Sequences

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Little Dima has two sequences of points with integer coordinates: sequence (_a_1, 1), (_a_2, 2), ..., (a__n, n) and sequence (_b_1, 1), (_b_2, 2), ..., (b__n, n).

Now Dima wants to count the number of distinct sequences of points of length 2·n that can be assembled from these sequences, such that the x-coordinates of points in the assembled sequence will not decrease. Help him with that. Note that each element of the initial sequences should be used exactly once in the assembled sequence.

Dima considers two assembled sequences (_p_1, _q_1), (_p_2, _q_2), ..., (_p_2·n, _q_2·n) and (_x_1, _y_1), (_x_2, _y_2), ..., (_x_2·n, _y_2·n) distinct, if there is such i (1 ≤ i ≤ 2·n), that (p__i, q__i) ≠ (x__i, y__i).

As the answer can be rather large, print the remainder from dividing the answer by number m.

小迪马有两组具有整数坐标的点序列:第一组为 (a1,1), (a2,2), …, (an,n)(a_1, 1),\ (a_2, 2),\ \dots,\ (a_n, n),第二组为 (b1,1), (b2,2), …, (bn,n)(b_1, 1),\ (b_2, 2),\ \dots,\ (b_n, n)。

现在迪马希望计算:从这两组序列中各取全部 nn 个点(即共 2n2n 个点),拼接成一个长度为 2n2n 的点序列,使得该序列中各点的 xx 坐标不递减(即非严格单调递增)的方案总数。请你帮他解决这个问题。注意:初始两组序列中的每个点都必须且仅能使用一次。

迪马认为两个拼接得到的序列 (p1,q1), (p2,q2), …, (p2n,q2n)(p_1, q_1),\ (p_2, q_2),\ \dots,\ (p_{2n}, q_{2n}) 与 (x1,y1), (x2,y2), …, (x2n,y2n)(x_1, y_1),\ (x_2, y_2),\ \dots,\ (x_{2n}, y_{2n}) 是不同的,当且仅当存在某个下标 ii(1≤i≤2n1 \le i \le 2n),使得 (pi,qi)≠(xi,yi)(p_i, q_i) \ne (x_i, y_i)。

由于答案可能非常大,请输出答案对给定正整数 mm 取模的结果。

输入格式

The first line contains integer n (1 ≤ n ≤ 105). The second line contains n integers _a_1, _a_2, ..., a__n (1 ≤ a__i ≤ 109). The third line contains n integers _b_1, _b_2, ..., b__n (1 ≤ b__i ≤ 109). The numbers in the lines are separated by spaces.

The last line contains integer m (2 ≤ m ≤ 109 + 7).

第一行包含一个整数 nn(1 ≤ n ≤ 1051 \leq n \leq 10^5)。
第二行包含 nn 个整数 a1, a2, ..., ana_1,\,a_2,\,...,\,a_n(1 ≤ ai ≤ 1091 \leq a_i \leq 10^9)。
第三行包含 nn 个整数 b1, b2, ..., bnb_1,\,b_2,\,...,\,b_n(1 ≤ bi ≤ 1091 \leq b_i \leq 10^9)。
每行中的数字以空格分隔。

最后一行包含一个整数 mm(2 ≤ m ≤ 109 + 72 \leq m \leq 10^9 + 7)。

输出格式

In the single line print the remainder after dividing the answer to the problem by number m.

在单行中输出该问题答案对数 mm 取模后的余数。

输入输出样例

  • 输入#1

    1
    1
    2
    7

    输出#1

    1
  • 输入#2

    2
    1 2
    2 3
    11

    输出#2

    2

说明/提示

In the first sample you can get only one sequence: (1, 1), (2, 1).

In the second sample you can get such sequences : (1, 1), (2, 2), (2, 1), (3, 2); (1, 1), (2, 1), (2, 2), (3, 2). Thus, the answer is 2.

在第一个样例中,你只能得到一个序列:(1, 1), (2, 1)(1,\,1),\,(2,\,1)。

在第二个样例中,你可以得到如下序列:(1, 1), (2, 2), (2, 1), (3, 2)(1,\,1),\,(2,\,2),\,(2,\,1),\,(3,\,2);(1, 1), (2, 1), (2, 2), (3, 2)(1,\,1),\,(2,\,1),\,(2,\,2),\,(3,\,2)。因此,答案是 22。

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

首页