Codeforces Round #167 (Div. 2) D. Dima and Two Sequences(组合数学)(*)

题目链接
在这里插入图片描述
题意:给出两个长度为nn的点对(a1,1),(a2,2),…,(an,n)和(b1,1),(b2,2),…,(bn,n),要求用这两个序列构成一个长度为2n的点对序列,使得x坐标非减,问方案数
思路:答案为IIcntx/pow(2,num),其实cnt是每个数的个数,num为a【i】==b【i】的对数

#include<bits/stdc++.h>
using namespace std;
typedef long long ll; 
const int maxn=1e5+1;
ll m,ans=1,cnt,a[maxn],b[maxn];
map<ll,ll>p;
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;++i) scanf("%lld",&a[i]),p[a[i]]++;
	for(int i=1;i<=n;++i){
		scanf("%lld",&b[i]);
		if(a[i]==b[i]) cnt++;
		p[b[i]]++;
	}
	scanf("%lld",&m);
	for(auto i:p)
	{
		for(int j=1;j<=i.second;++j)
		{
			ll t=j;
			while(cnt>0&&t%2==0) t/=2,cnt--;
			ans=ans*t%m;
		}
	}
	printf("%lld\n",ans%m);
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值