QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#423198#2834. NonsenseTianTian2008TL 0ms0kbC++141.4kb2024-05-27 21:30:412024-05-27 21:30:42

Judging History

你现在查看的是最新测评结果

  • [2024-05-27 21:30:42]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-05-27 21:30:41]
  • 提交

answer

#include <iostream>
#include <cstdio>
#define mod 998244353
using namespace std;
typedef long long ll;
ll n,m,x,y,q,fac[5010],inv[5010],px[10010],py[10010];
ll ksm(ll x,ll y) {
	ll res=1;
	while(y) {
		if(y&1) res=res*x%mod;
		x=x*x%mod;
		y>>=1;
	}
	return res;
}
void init() {
	fac[0]=1;
	for(int i=1;i<=m;++i) fac[i]=fac[i-1]*(n-i+2)%mod;
	ll pro=1;
	for(int i=1;i<=m;++i) pro=pro*i%mod;
	inv[m]=ksm(pro,mod-2);
	for(int i=m;i>=1;--i) inv[i-1]=inv[i]*i%mod;
	px[m]=ksm(x,n-m);
	for(int i=m;i>=1;--i) px[i-1]=px[i]*x%mod;
	py[m]=ksm(y,n-m);
	for(int i=m;i>=1;--i) py[i-1]=py[i]*y%mod;
}
inline ll binom(ll x) {return fac[x]*inv[x]%mod;}
namespace sol1 {
	ll f[5010][5010];
	void work() {
		ll div=ksm(x-y,mod-2);
		for(int i=0;i<=m;++i)
			for(int j=0;j<=m;++j) {
				if(i==0) f[i][j]=-binom(j)*py[j-1]%mod;
				else f[i][j]=-f[i-1][j];
				if(j==0) f[i][j]+=binom(i)*px[i-1]%mod;
				else f[i][j]+=f[i][j-1];
				f[i][j]=f[i][j]*div%mod;
			}
		ll a,b;
		while(q--) {
			scanf("%lld%lld",&a,&b);
			printf("%lld\n",(f[a][b]+mod)%mod);
		}
	}
}
namespace sol2 {
	void work() {
		ll a,b;
		while(q--) {
			scanf("%lld%lld",&a,&b);
			printf("%lld\n",px[a+b]*binom(a+b+1)%mod);
		}
	}
}
int main() {
	while(scanf("%lld%lld%lld%lld",&n,&x,&y,&q)!=EOF) {
		m=min(n,5000ll)+1;
		init();
		if(x!=y) sol1::work();
		else sol2::work();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

3 1 2 2
1 1
1 2
100 2 3 1
1 1

output:


result: