QOJ.ac

QOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#383#189753#21673. 【NOIP Round #1】波特分组SixNukestuxuanming2024Failed.2023-09-29 16:44:402023-09-29 16:44:41

Details

Extra Test:

Invalid Input

input:

114

output:


result:

FAIL Unexpected character #10, but ' ' expected (stdin, line 1)

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#189753#21673. 【NOIP Round #1】波特分组tuxuanming2024100 ✓672ms507068kbC++141.2kb2023-09-27 20:48:582023-09-27 20:49:00

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=200005,mod=998244353;
ll fac[N],inv[N],pw[N],inv2[N],sum[N];
int n,q,k,cnt,mp[N],b[N],suf[635][N];
ll C(int n,int m) {return m<0||n<m?0:fac[n]*inv[m]%mod*inv[n-m]%mod;}
ll qpow(ll x,int y)
{
	ll s=1;
	for(;y;x=x*x%mod,y>>=1) if(y&1) s=s*x%mod;
	return s;
}
int main()
{
	scanf("%d %d",&n,&q);
	fac[0]=pw[0]=1;
	for(int i=1;i<=2*n;i++) fac[i]=fac[i-1]*i%mod,pw[i]=pw[i-1]*2%mod;
	inv[2*n]=qpow(fac[2*n],mod-2);
	inv2[2*n]=qpow(pw[2*n],mod-2);
	for(int i=2*n;i>=1;i--) inv[i-1]=inv[i]*i%mod,inv2[i-1]=inv2[i]*2%mod;
	for(int i=1;i<=2*n;i++) sum[i]=(sum[i-1]+C(i,n-1)*pw[2*n-i]%mod)%mod;
	while(q--)
	{
		scanf("%d",&k);
		for(int i=1;i<=k;i++) scanf("%d",b+i);
		ll ans=0;
		b[++k]=2*n;
		for(int i=1;i<=k;i++)
		{
			int l=max(0,b[i-1]-i),r=max(0,b[i]-i-1);
			if(l<=r) ans=(ans+(sum[r]-sum[l])%mod*inv2[i]%mod)%mod;
		}
		k--;
		if(!mp[k])
		{
			mp[k]=++cnt;
			for(int i=2*n-1;i>=1;i--) suf[cnt][i]=(suf[cnt][i+1]+1ll*C(i-k-1,n-k-1)*pw[2*n-i]%mod)%mod;
		}
		ans=(ans+suf[mp[k]][b[k]+1])%mod;
		if(b[k]!=2*n) ans=(ans+C(b[k]-k,n-k)*pw[2*n-b[k]]%mod)%mod;
		if(ans<0) ans+=mod;
		printf("%lld\n",ans*2*inv2[2*n]%mod);
	}
	return 0;
}
/*
3 1
2 2 4
*/