MTT求助。。。WA50,快调自闭了

P4245 【模板】任意模数多项式乘法

Serenata_Immortale @ 2019-10-02 15:53:37

小点都对了,大点就挂...

#include<bits/stdc++.h>
#define N 800010
#define pi acos(-1)
#define int long long
#define ld long double
using namespace std;
struct fs
{
    ld x,y;
    friend fs operator+(const fs&a,const fs&b){return (fs){a.x+b.x,a.y+b.y};}
    friend fs operator-(const fs&a,const fs&b){return (fs){a.x-b.x,a.y-b.y};}
    friend fs operator*(const fs&a,const fs&b){return (fs){a.x*b.x-a.y*b.y,a.x*b.y+a.y*b.x};}
}a[N],b[N],c[N],d[N],e[N],f[N],g[N],h[N];
int n,m,p,r[N];
void FFT(fs*A,int lim,int fl)
{
    for(int i = 0;i<lim;i++)if(i<r[i])swap(A[i],A[r[i]]);
    for(int i = 2;i<=lim;i<<=1)
    {
        fs wn = (fs){cos(2*pi/i),fl*sin(2*pi/i)};
        for(int j = 0;j<lim;j+=i)
        {
            fs w = (fs){1,0};
            for(int k = 0;k<i>>1;k++)
            {
                fs x = A[j+k],y = w*A[j+k+(i>>1)];
                A[j+k] = x+y,A[j+k+(i>>1)] = x-y;
                w = w*wn;
            }
        }
    }if(fl==-1)for(int i = 0;i<lim;i++)A[i].x/=lim;
}
signed main()
{
    scanf("%lld%lld%lld",&n,&m,&p);
    for(int i = 0;i<=n;i++)
    {
        int num;scanf("%lld",&num);
        num%=p;
        a[i].x = (ld)(num>>15);
        b[i].x = (ld)(num&0x7fff);
    }
    for(int i = 0;i<=m;i++)
    {
        int num;scanf("%lld",&num);
        num%=p;
        c[i].x = (ld)(num>>15);
        d[i].x = (ld)(num&0x7fff);
    }
    int lim = 1,bit = 0;
    while(lim<=n+m)lim<<=1,bit++;
    for(int i = 0;i<lim;i++)r[i] = (r[i>>1]>>1)|((i&1)<<bit-1);
    FFT(a,lim,1),FFT(b,lim,1),FFT(c,lim,1),FFT(d,lim,1);
    for(int i = 0;i<lim;i++)
    {
        e[i] = a[i]*c[i];
        f[i] = a[i]*d[i];
        g[i] = b[i]*d[i];
        h[i] = b[i]*c[i];
    }
    FFT(e,lim,-1),FFT(f,lim,-1),FFT(g,lim,-1),FFT(h,lim,-1);
    for(int i = 0;i<=n+m;i++)
    {
        int E = (int)round(e[i].x)%p,F = (int)round(f[i].x)%p,G = (int)round(g[i].x)%p,H = (int)round(h[i].x)%p;
        printf("%lld ",(((E<<30)%p+((F+H)%p<<15)%p+G)%p+p)%p);
    }
    return 0;
}

by guodong @ 2019-10-02 15:56:02

orz MTT


by Serenata_Immortale @ 2019-10-02 16:10:16

我靠终于调出来了。。。

我pi没开long double然后就挂了...


|