Codeforces Round #167 (Div. 1) B

Source: Internet
Author: User

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;
}


























Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.