``PKUSC2018'' real ranking (number of simple combinations)

Question: "PKUSC2018" Real Ranking

answer

Classified discussion, for the i-th person:

If a_{i}not doubled, then to meet a_ {j} <a_ {i}, a_ {j}*2 \ geq a_ {i}any of j, j-th individual must not be doubled, otherwise i-ranking individuals must change, because other people do not matter to turn double, it has no effect on the ranking of i. Suppose the number of j that satisfies the condition is m, then the number of schemes is the number of combinations C_{n-m-1}^{k};

If a_{i}doubled, then for a_{i}\leq a_{j}<a_{i}*2,j\neq iany j that is satisfied , the j-th person must double for the same reason. Suppose the number of j that satisfies the condition is p, then the number of schemes is the number of combinations C_{n-p-1}^{k-p-1};

So the total number of plans for the i-th person is C_{n-m_{i}-1}^{k}+C_{n-p_{i}-1}^{k-p_{i}-1}.

Tip: Use fast multiplication with caution in the code! Because I deleted the source code of the test, I got A (QAQ)

Code

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#define ll long long
#define MAXN 100005
#define mod 998244353ll
using namespace std;
inline ll read(){
	ll x=0,f=1;char s=getchar();
	while(s<'0'||s>'9'){if(s=='-')f*=-1;s=getchar();}
	while(s>='0'&&s<='9'){x=(x<<1)+(x<<3)+s-'0';s=getchar();}
	return x*f;
}
int n,k;
struct itn{
	ll x;int y;
	itn(){}
	itn(ll X,int Y){x=X,y=Y;}
}a[MAXN];
ll jc[MAXN],ans[MAXN];
inline bool cmp(itn a,itn b){return a.x<b.x;}
inline ll ksm(ll a,ll b,ll mo){
	ll res=1;
	for(;b;b>>=1){
		if(b&1)res=res*a%mod;
		a=a*a%mod;
	}
	return res;
}
inline ll C(int n,int m){
	if(m>n||m<0)return 0;
	return jc[n]*ksm(jc[m],mod-2,mod)%mod*ksm(jc[n-m],mod-2,mod)%mod;
}
int main()
{
//	freopen("rank.in","r",stdin);
//	freopen("rank.out","w",stdout);
	n=read(),k=read(),jc[0]=1;
	for(int i=1;i<MAXN-4;i++)jc[i]=jc[i-1]*i%mod;
	for(int i=1;i<=n;i++)a[i]=itn(read(),i);
	sort(a+1,a+1+n,cmp);
	for(int i=1;i<=n;i++){
		int id=i,t;
		for(int j=17,o=id-(1<<j);j>=0;j--,o=id-(1<<j))
			if(o>0&&a[o].x==a[id].x)id=o;
		t=id;
		for(int j=17,o=t-(1<<j);j>=0;j--,o=t-(1<<j))
			if(o>0&&(a[o].x<<1)>=a[id].x)t=o;
		ans[a[i].y]=C(n-id+t-1,k)%mod,t=id;
		for(int j=17,o=t+(1<<j);j>=0;j--,o=t+(1<<j))
			if(o<=n&&a[o].x<(a[id].x<<1))t=o;
		(ans[a[i].y]+=C(n-t+id-1,k-t+id-1)%mod)%=mod;
	}
	for(int i=1;i<=n;i++)printf("%lld\n",ans[i]);
	return 0;
}

 

Guess you like

Origin blog.csdn.net/weixin_43960287/article/details/108499164