QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#450682 | #6349. Is This FFT? | do_while_true | WA | 0ms | 15876kb | C++20 | 4.4kb | 2024-06-22 16:58:44 | 2024-06-22 16:58:44 |
Judging History
answer
#include<cstdio>
#include<vector>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<ctime>
#include<random>
#include<array>
#include<assert.h>
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
#define dbg(x) cerr<<"In Line "<< __LINE__<<" the "<<#x<<" = "<<x<<'\n'
#define dpi(x,y) cerr<<"In Line "<<__LINE__<<" the "<<#x<<" = "<<x<<" ; "<<"the "<<#y<<" = "<<y<<'\n'
#define DE(fmt,...) fprintf(stderr, "Line %d : " fmt "\n",__LINE__,##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 i128;
typedef pair<int,int>pii;
typedef pair<ll,int>pli;
typedef pair<ll,ll>pll;
typedef pair<int,ll>pil;
typedef vector<int>vi;
typedef vector<ll>vll;
typedef vector<pii>vpii;
typedef vector<pll>vpll;
template<typename T>T cmax(T &x, T y){return x=x>y?x:y;}
template<typename T>T cmin(T &x, T y){return x=x<y?x:y;}
template<typename T>
T &read(T &r){
r=0;bool w=0;char ch=getchar();
while(ch<'0'||ch>'9')w=ch=='-'?1:0,ch=getchar();
while(ch>='0'&&ch<='9')r=r*10+(ch^48),ch=getchar();
return r=w?-r:r;
}
template<typename T1,typename... T2>
void read(T1 &x,T2& ...y){read(x);read(y...);}
typedef __uint128_t L;
int mod;
struct FastMod{
ull b,m;
FastMod(ull b):b(b),m(ull((L(1)<<64)/b)){}
friend inline ull operator%(const ull&a,const FastMod&mod){
ull r=a-(L(mod.m)*a>>64)*mod.b;
return r>=mod.b?r-mod.b:r;
}
}Mod(998244353);
inline void cadd(int &x,int y){x=(x+y>=mod)?(x+y-mod):(x+y);}
inline void cdel(int &x,int y){x=(x-y<0)?(x-y+mod):(x-y);}
inline int add(int x,int y){return (x+y>=mod)?(x+y-mod):(x+y);}
inline int del(int x,int y){return (x-y<0)?(x-y+mod):(x-y);}
int qpow(int x,int y){
int s=1;
while(y){
if(y&1)s=1ll*s*x%Mod;
x=1ll*x*x%Mod;
y>>=1;
}
return s;
}
const int N=251;
const int M=3000010;
const int T=33000;
int n;
int fac[N*N],inv[N*N],iv[N*N];
int C(int x,int y){
return 1ll*fac[x]*inv[y]%Mod*inv[x-y]%Mod;
}
int ge,ige;
int check(int w){
int t=mod-1;
for(int i=2;i*i<=t;i++)if(t%i==0){
while(t%i==0)t/=i;
if(qpow(w,(mod-1)/i)==1)return 0;
}
if(t>1){
if(qpow(w,(mod-1)/t)==1)return 0;
}
return 1;
}
void getgen(){
for(int i=2;;i++){
if(check(i)){
ge=i;ige=qpow(i,mod-2);
return ;
}
}
}
int *getw(int n,int type){
static int w[M/2];
w[0]=1;w[1]=qpow(type==1?ge:ige,(mod-1)/n);
for(int i=2;i<n/2;i++)w[i]=1ll*w[i-1]*w[1]%Mod;
return w;
}
int p[M];
void initp(int len){
int ct=0;
while(len!=(1<<ct))ct++;
for(int i=1;i<len;i++){
p[i]=(p[i>>1]>>1)|((i&1)<<(ct-1));
}
}
void NTT(int *f,int n,int op){
for(int i=0;i<n;i++)
if(i<p[i])
swap(f[i],f[p[i]]);
for(int i=1,c=0;i<n;i<<=1,++c){
int *w=getw(i<<1,op);
for(int j=0;j<n;j+=(i<<1)){
for(int k=0;k<i;k++){
int u=f[j+k],v=1ll*f[j+i+k]*w[k]%mod;
f[j+k]=add(u,v);
f[j+i+k]=del(u,v);
}
}
}
if(op==-1){
int iv=qpow(n,mod-2);
for(int i=0;i<n;i++)f[i]=1ll*f[i]*iv%mod;
}
}
int F[N][T],H[N][T],W[N][T];
int P[T];
L tmp[N*N];
signed main(){
read(n,mod);Mod=FastMod(mod);
getgen();
int i2=(mod+1)/2;
fac[0]=1;for(int i=1;i<=n*n;i++)fac[i]=1ll*fac[i-1]*i%Mod;
inv[n*n]=qpow(fac[n*n],mod-2);for(int i=n*n-1;~i;--i)inv[i]=1ll*inv[i+1]*(i+1)%Mod;
for(int i=1;i<=n*n;i++)iv[i]=1ll*inv[i]*fac[i-1]%Mod;
cout<<1<<'\n';
int len=1;
while(len<=n*(n-1)/2)len<<=1;
initp(len);
F[0][0]=1;
NTT(F[0],len,1);
P[0]=1;P[1]=del(0,1);
NTT(P,len,1);
for(int i=0;i<len;i++)H[0][i]=W[0][i]=1;
for(int c=1;c<=n;c++){
for(int i=0;i<len;i++)H[c][i]=1ll*H[c-1][i]*P[i]%Mod;
}
for(int c=1;c<=n;c++){
for(int i=0;i<len;i++)W[c][i]=1ll*W[c-1][i]*H[n][i]%Mod;
}
#ifdef do_while_true
cerr<<'\n'<<"Time:"<<1.0*clock()/CLOCKS_PER_SEC*1000<<" ms"<<'\n';
#endif
for(int m=1;m<n;m++){
for(int i=0;i<m;i++){
int j=m-i-1;
int c=(i+1)*(j+1)-1;
for(int k=0;k<len;k++){
tmp[k]+=(i128)F[i][k]*F[j][k]*W[c/n][k]*H[c%n][k];
}
}
for(int k=0;k<len;k++)F[m][k]=tmp[k]%mod,tmp[k]=0;
NTT(F[m],len,-1);
for(int i=len-1;i;i--)F[m][i]=1ll*F[m][i-1]*iv[i]%Mod;
F[m][0]=0;
int sum=0;
for(int i=0;i<=m*(m+1)/2;i++)cadd(sum,F[m][i]);
NTT(F[m],len,1);
sum=1ll*sum*fac[(m+1)]%Mod*i2%Mod;
cout<<sum<<'\n';
}
#ifdef do_while_true
cerr<<'\n'<<"Time:"<<1.0*clock()/CLOCKS_PER_SEC*1000<<" ms"<<'\n';
#endif
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 15876kb
input:
10 998244353
output:
1 1 1 532396989 328786831 443364983 567813846 34567523 466373946 474334062
result:
wrong answer 3rd numbers differ - expected: '532396989', found: '1'