QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#423621#2834. Nonsense_qwqUwUWA 148ms101760kbC++201.7kb2024-05-28 13:04:292024-05-28 13:04:29

Judging History

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

  • [2024-05-28 13:04:29]
  • 评测
  • 测评结果:WA
  • 用时:148ms
  • 内存:101760kb
  • [2024-05-28 13:04:29]
  • 提交

answer

#include<bits/stdc++.h>
#define pb push_back
#define P make_pair
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
inline ll read(){
	ll x=0,c=getchar();
	while(c<'0'||c>'9')c=getchar();
	while(c>='0' && c<='9')x=x*10 + c-'0',c=getchar();
	return x;
}
int n,x,y,ma,mb,q;
const int mod=998244353;
inline void Ad(int &x,int y){x=x+y>=mod?x+y-mod:x+y;}
inline int ad(int x,int y){return x+y>=mod?x+y-mod:x+y;}
const int M=2e5+2;
const int N=5003;
int A[M],B[M];
int a[N][N],C[N],iv[N<<1];
inline int fp(int x,int p=mod-2){
	int res=1;
	for(;p;p>>=1){
		if(p&1)res=1ll*res*x%mod;
		x=1ll*x*x%mod;
	}
	return res;
}
inline void solve(){
	ma=mb=0;
	rep(i,1,q)A[i]=read(),B[i]=read(),ma=max(ma,A[i]),mb=max(mb,B[i]);
	if(x==y){
		rep(i,1,q){
			int res=fp(x,n-A[i]-B[i]);
			rep(j,1,A[i]+B[i])res=1ll*res*(n-j+1)%mod*iv[j]%mod;
			printf("%d\n",res);
		}
		return ;
	}
	C[0]=1;
	rep(i,1,max(ma,mb))C[i]=1ll*C[i-1]*(n-i+2)%mod*iv[i]%mod;
	const int ivx=fp(x),ivy=fp(y),iv=fp(ad(x,mod-y));
	int px=fp(x,n+1),py=fp(y,n+1);
	a[0][0]=ad(px,mod-py);
	rep(i,1,ma)px=1ll*px*ivx%mod,a[i][0]=1ll*px*C[i]%mod;
	rep(i,1,mb)py=1ll*py*ivy%mod,a[0][i]=mod-1ll*py*C[i]%mod;
	rep(i,1,ma)rep(j,1,mb)a[i][j]=0;
	rep(i,0,ma)rep(j,0,mb){
		a[i][j]=1ll*a[i][j]*iv%mod;
		Ad(a[i+1][j],mod-a[i][j]);
		Ad(a[i][j+1],a[i][j]);
	}
	rep(i,1,q)printf("%d\n",a[A[i]][B[i]]);
}
int main(){
	//freopen("data.in","r",stdin);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	iv[1]=1;rep(i,2,(N<<1)-1)iv[i]=1ll*iv[mod%i]*(mod-mod/i)%mod;
	while(scanf("%d%d%d%d",&n,&x,&y,&q)!=EOF)solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 5968kb

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: 0
Accepted
time: 7ms
memory: 26412kb

input:

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

output:

381781645
1
1

result:

ok 3 lines

Test #3:

score: 0
Accepted
time: 148ms
memory: 101760kb

input:

1000000000 998244351 998244352 1
5000 5000

output:

663228915

result:

ok single line: '663228915'

Test #4:

score: -100
Wrong Answer
time: 14ms
memory: 3912kb

input:

105886041 9 3 200
4 3
5 1
1 1
4 1
3 3
1 5
2 1
1 5
2 1
1 5
3 3
4 4
2 1
4 4
1 2
5 2
5 2
2 5
4 5
3 3
4 3
1 4
3 1
5 4
5 3
5 2
5 3
3 3
1 3
4 3
2 3
3 5
1 3
3 5
2 3
4 4
3 4
5 5
2 3
1 1
3 3
4 2
1 4
4 5
2 3
1 5
2 2
4 2
5 5
2 1
4 3
3 3
3 1
2 1
2 5
1 1
4 4
1 5
1 5
3 1
3 2
2 2
4 1
5 5
3 4
2 2
2 1
5 3
5 3
2 2
1 ...

output:

721440251
764408668
442427888
914530150
115811774
360614503
666106268
360614503
666106268
360614503
115811774
166867820
666106268
166867820
985976063
717651702
717651702
405340273
435048189
115811774
721440251
719754512
660548079
998056822
165742634
717651702
165742634
115811774
407319461
721440251
...

result:

wrong answer 601st lines differ - expected: '693360471', found: '589969110'