Codeforces Round #167 (Div. 1) B
// Sort x in ascending order
// Open an array equal and store the same x value
// Then ans = equal [1]! * Equal [2]! ....
// Then divide by the factorial of the same number of y in the same x.
// As you can see from the question, open (xi = xj) and (yi = yj) only have two
// You can record the logarithm of (xi = xj) and (yi = yj,
// During calculation, you can divide the even number by 2.
# Include
# Include
# Include
# Include
Using namespace std;
Const int maxn = 200010;
Typedef _ int64 ll;
Struct node
{
Int x, y;
} A [maxn];
Bool cmp (struct node a, struct node B)
{
If (a. x = B. x)
Return a. y <B. y;
Return a. x <B. x;
}
Int limit _x [maxn];
Int main ()
{
Int n, m;
While (~ Scanf ("% d", & n ))
{
For (int I = 1; I <= 2 * n; I ++)
{
Scanf ("% d", & a [I]. x );
A [I]. y = I % n;
}
Scanf ("% d", & m );
Sort (a + 1, a + 1 + 2 * n, cmp );
Int len_x = 0, len_y = 0;
For (int I = 1; I <= 2 * n; I ++)
{
If (a [I]. x = a [I-1]. x)
{
If (a [I]. y = a [I-1]. y)
Len_y ++;
Optional _x [len_x] ++;
If (I = 2 * n) len_x ++;
}
Else len_x ++;
}
Ll ans = 1;
For (int I = 0; I <len_x; I ++)
{
For (int j = 1; j <= random _x [I]; j ++)
{
If (len_y & (j + 1) % 2 = 0)
{
Ans = (ans * (ll) (j + 1)/2) % m;
Len_y --;
}
Else ans = (ans * (ll) (j + 1) % m;
}
}
Printf ("% I64d \ n", ans );
}
Return 0;
}