# 做法

i=1mk=i+1m+1j=ak+1ak1(aij+ki)

=i=1mk=i+1m+1(aiak1+ki)!(aiak11+ki)!

=i=1m(ai+mi)!mk=i+1(aiak+ki)

=i=1m(ai+mi)!i<k1(aii)(akk)

#include<cstdio>
#include<algorithm>
#include<cmath>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
typedef long long ll;
typedef double db;
const int maxlen=3000000+10,mo=1004535809,GG=3;
int rev[maxlen],w[maxlen],tt[maxlen],a[maxlen],b[maxlen],c[maxlen],fac[maxlen];
int i,j,k,l,t,n,m,len,ni,ans,mx;
db ce;
int qsm(int x,int y){
if (!y) return 1;
int t=qsm(x,y/2);
t=(ll)t*t%mo;
if (y%2) t=(ll)t*x%mo;
return t;
}
void prepare(){
ni=qsm(len,mo-2);
fo(i,0,len-1){
int p=0;
for(int j=0,tp=i;j<ce;j++,tp/=2) p=(p<<1)+(tp%2);
rev[i]=p;
}
w[0]=1;
w[1]=qsm(GG,(mo-1)/len);
fo(i,2,len) w[i]=(ll)w[i-1]*w[1]%mo;
}
void DFT(int *a,int sig){
int i;
fo(i,0,len-1) tt[rev[i]]=a[i];
for(int m=2;m<=len;m*=2){
int half=m/2,bei=len/m;
fo(i,0,half-1){
int wi=sig>0?w[i*bei]:w[len-i*bei];
for(int j=i;j<len;j+=m){
int u=tt[j],v=(ll)tt[j+half]*wi%mo;
tt[j]=(u+v)%mo;
tt[j+half]=(u-v)%mo;
}
}
}
if (sig==-1)
fo(i,0,len-1) tt[i]=(ll)tt[i]*ni%mo;
fo(i,0,len-1) a[i]=tt[i];
}
void NTT(){
DFT(b,1);DFT(c,1);
fo(i,0,len-1) b[i]=(ll)b[i]*c[i]%mo;
DFT(b,-1);
}
int main(){
scanf("%d",&m);
fo(i,1,m){
scanf("%d",&a[i]);
n+=a[i];
}
mx=max(a[1],2*m);
mx=max(mx,a[1]+m);
fac[0]=1;
fo(i,1,mx) fac[i]=(ll)fac[i-1]*i%mo;
ans=1;
fo(i,1,m) ans=(ll)ans*fac[a[i]+m-i]%mo;
mx=max(a[1],m);
len=1;
while (len<=4*mx) len*=2;
ce=log(len)/log(2);
prepare();
fo(i,1,m){
t=a[i]-i+mx;
b[t]++;
t=i-a[i]+mx;
c[t]++;
}
NTT();
fo(i,2*mx+1,len-1){
(b[i]+=mo)%=mo;
t=i-2*mx;
t=qsm(t,mo-2);
t=qsm(t,b[i]);
ans=(ll)ans*t%mo;
}
ans=qsm(ans,mo-2);
fo(i,1,m) ans=(ll)ans*fac[a[i]]%mo;
(ans+=mo)%=mo;
printf("%d\n",ans);
}

• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120