QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#422753#2834. NonsenseqwqwfWA 17ms25912kbC++142.1kb2024-05-27 19:08:122024-05-27 19:08:13

Judging History

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

  • [2024-05-27 19:08:13]
  • 评测
  • 测评结果:WA
  • 用时:17ms
  • 内存:25912kb
  • [2024-05-27 19:08:12]
  • 提交

answer

//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2")
//#pragma GCC optimize("Ofast","unroll-loops","inline")
#include<bits/stdc++.h>
#define ll long long
//#define int ll
#define pb push_back
using namespace std;
const int N=2e5+10,M=5e3+10,mod=998244353;
int fac[N],ifac[N];
inline int C(int n,int m){
	if(n<0||m<0||n<m) return 0;
	int res=1;
	for(int i=1;i<=m;i++) res=1ll*res*(n-i+1)%mod; 
	return 1ll*res*ifac[m]%mod;
}
inline void Add(int &x,int y){x+=y;if(x>=mod) x-=mod;}
inline void Del(int &x,int y){x-=y;if(x<0) x+=mod;}
inline int del(int x,int y){x-=y;return x<0?x+mod:x;}
inline int add(int x,int y){x+=y;return x>=mod?x-mod:x;}
int qpow(int a,int b){
	int res=1;
	while(b){
		if(b&1) res=1ll*res*a%mod;
		a=1ll*a*a%mod;b>>=1;
	}return res;
}
int f[M][M],mx;
void div(int a,int b,int c){
	int invc=qpow(c,mod-2);
	for(int i=0;i<=mx;i++) for(int j=0;j<=mx;j++){
		int v=f[i][j];
		if(i) Del(v,1ll*a*f[i-1][j]%mod);
		if(j) Del(v,1ll*b*f[i][j-1]%mod);
		f[i][j]=1ll*v*invc%mod; 
	}
}
int a[N],b[N],n,q,x,y;
void solve(){
	mx=0;
	for(int i=1;i<=q;i++) scanf("%d%d",&a[i],&b[i]),mx=max(mx,max(a[i],b[i]));
	for(int i=0;i<=mx;i++) for(int j=0;j<=mx;j++) f[i][j]=0;
	if(x==y){
		for(int i=1;i<=min(2*mx,n+1);i++) for(int j=0;j<i;j++){
			int c=qpow(x,n+1-i);
			int ret=C(n+1,i);
			if(j<=mx&&i-j-1<=mx) Add(f[j][i-j-1],1ll*c*ret%mod);
		}
		for(int i=1;i<=q;i++){
			printf("%d\n",f[a[i]][b[i]]);
		}
		return ;
	}
	for(int i=0;i<=min(mx,n+1);i++){
		int c1=qpow(x,n+1-i),c2=qpow(y,n+1-i);
		f[i][0]=1ll*c1*C(n+1,i)%mod; 
		if(i) f[0][i]=del(0,1ll*c2*C(n+1,i)%mod);
		else Del(f[0][i],1ll*c2*C(n+1,i)%mod); 
	}
	int A=1,B=mod-1,C=del(x,y);
	div(A,B,C);
	for(int i=1;i<=q;i++){
		printf("%d\n",f[a[i]][b[i]]);
	}
}
signed main(){
//	freopen("a.in","r",stdin);
//	freopen("a.out","w",stdout);
	fac[0]=ifac[0]=ifac[1]=1;for(int i=1;i<N;i++) fac[i]=1ll*fac[i-1]*i%mod;
	ifac[N-1]=qpow(fac[N-1],mod-2);for(int i=N-1;i;i--) ifac[i-1]=1ll*ifac[i]*i%mod;
	while(~scanf("%d%d%d%d",&n,&x,&y,&q)) solve();
//	int T;cin>>T;
//	while(T--) solve();
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 8436kb

input:

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

output:

6
1
866021789

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 17ms
memory: 25912kb

input:

1000000000 0 1 1
1000 1000
2 0 0 1
1 1
2 998244352 998244352 1
1 1

output:

381781645
0
0

result:

wrong answer 2nd lines differ - expected: '1', found: '0'