提交记录 21476


用户 题目 状态 得分 用时 内存 语言 代码长度
ETO_leader 1002i. 【模板题】多项式乘法 Accepted 100 63.036 ms 13768 KB C++17 3.80 KB
提交时间 评测时间
2024-04-07 22:43:58 2024-04-07 22:44:03
#include<bits/stdc++.h>
#define cir(i,a,b) for(int i=a;i<b;++i)
using namespace std;
namespace fcomplex{
    template<typename _Ty>
    class fcomplex{
    private:
        _Ty a,b;
    public:
        auto&operator+=(const fcomplex x){
            a+=x.a;b+=x.b;
            return*this;
        }
        auto operator+(const fcomplex x) const{
            return fcomplex(a+x.a,b+x.b);
        }
        auto&operator-=(const fcomplex x){
            a-=x.a;b-=x.b;
            return*this;
        }
        auto operator-(const fcomplex x) const{
            return fcomplex(a-x.a,b-x.b);
        }
        auto&operator*=(const fcomplex x){
            const auto cpx=*this;
            a=cpx.a*x.a-cpx.b*x.b;b=cpx.a*x.b+cpx.b*x.a;
            return*this;
        }
        auto operator*(const fcomplex x) const{
            return fcomplex(*this)*=x;
        }
        auto&operator/=(const _Ty x){
            a/=x;b/=x;
            return*this;
        }
        auto operator/(const _Ty x) const{
            return fcomplex(a/x,b/x);
        }
        auto&operator~(){b=-b;return*this;}
        auto&operator-(){a=-a;b=-b;return*this;}
        auto real() const{return a;}
        auto imag() const{return b;}
        fcomplex()=default;
        fcomplex(const _Ty _a,const _Ty _b):a(_a),b(_b){}
    };
}
using complf=fcomplex::fcomplex<long double>;
namespace poly{
    static constexpr auto pi=acos(-1);
    auto change(vector<complf>&a,const int n){
        vector<int> rev(n);
        cir(i,0,n){
            rev[i]=(rev[i>>1]>>1)|((n>>1)*(i&1));
        }
        cir(i,0,n) if(i<rev[i]) swap(a[i],a[rev[i]]);
    }
    template<const int type>
    auto fft(vector<complf>&a,const int n){
        change(a,n);
        for(auto h=2;h<n+1;h<<=1){
            const auto wx=complf(cos(pi*2/h),sin(pi*2*type/h));
            const auto midh=h/2;
            for(auto i=0;i<n;i+=h){
                auto u=complf(1,0);
                cir(k,i,i+midh){
                    const auto wy=u*a[k+midh];
                    a[k+midh]=a[k]-wy;a[k]+=wy;
                    u*=wx;
                }
            }
        }
        if(type==-1) for(auto&i:a) i/=n;
    }
    auto mul(vector<int> a,vector<int> b){
        const auto n=1<<((int)(log2(a.size()+b.size()))+1);
        vector<complf> fx(n);
        cir(i,0,(int)(a.size())) fx[i]+=complf(a[i],0);
        cir(i,0,(int)(b.size())) fx[i]+=complf(0,b[i]);
        fft<1>(fx,n);
        for(auto&i:fx) i*=i;
        fft<-1>(fx,n);
        vector<long long> ans(n);
        cir(i,0,n) ans[i]=roundl(fx[i].imag()/2);
        return ans;
    }
}
namespace flash_man{
    static array<char,5000000> buf;
    auto p1 = buf.begin(), p2 = buf.begin();
    #define getchar() p1 == p2 && (p2 = (p1 = buf.begin()) + fread(buf.begin(), 1, 1000000, stdin), p1 == p2) ? EOF : *p1++
    template <typename type>
    inline auto read(type &x) {
        x = 0;
        char c = getchar();
        while (!isdigit(c)) {
            c = getchar();
        }
        while (isdigit(c)) {
            x = (x << 1) + (x << 3) + (c ^ 48);
            c = getchar();
        }
    }
    inline auto read(){
        int x;read(x);
        return x;
    }
    array<char,100> stc;
    inline auto write(int x,char c){
        if(x<0) putchar('-'),x=-x;
        auto tp=0;
        if(!x) stc[tp++]=0;
        while(x) stc[tp++]=x%10,x/=10;
        while((--tp)>-1) putchar(stc[tp]+'0');
        putchar(c);
    }
    #undef getchar
}
int main(){
    //ios::sync_with_stdio(false),cin.tie(0);
    int n,m;
    flash_man::read(n);flash_man::read(m);++n;++m;
    //cin>>n>>m;
    vector<int> a(n),b(m);
    for(auto&i:a) flash_man::read(i);//cin>>i;
    for(auto&i:b) flash_man::read(i);//cin>>i;
    const auto ans=poly::mul(a,b);
    cir(i,0,n+m-1) flash_man::write(ans[i],' ');//cout<<ans[i]<<' ';
    putchar('\n');
    //cout<<'\n';
    return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #145.19 us40 KBAcceptedScore: 100

Subtask #1 Testcase #262.806 ms13 MB + 376 KBAcceptedScore: 0

Subtask #1 Testcase #325.206 ms6 MB + 276 KBAcceptedScore: 0

Subtask #1 Testcase #425.412 ms6 MB + 264 KBAcceptedScore: 0

Subtask #1 Testcase #538.55 us40 KBAcceptedScore: 0

Subtask #1 Testcase #636.99 us40 KBAcceptedScore: 0

Subtask #1 Testcase #736.22 us40 KBAcceptedScore: 0

Subtask #1 Testcase #862.264 ms12 MB + 796 KBAcceptedScore: 0

Subtask #1 Testcase #962.333 ms12 MB + 796 KBAcceptedScore: 0

Subtask #1 Testcase #1061.046 ms12 MB + 188 KBAcceptedScore: 0

Subtask #1 Testcase #1163.036 ms13 MB + 456 KBAcceptedScore: 0

Subtask #1 Testcase #1260.536 ms12 MB + 336 KBAcceptedScore: 0

Subtask #1 Testcase #1337.51 us40 KBAcceptedScore: 0


Judge Duck Online | 评测鸭在线
Server Time: 2025-07-19 04:13:06 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠