提交记录 21474


用户 题目 状态 得分 用时 内存 语言 代码长度
ETO_leader 1002i. 【模板题】多项式乘法 Accepted 100 51.641 ms 8284 KB C++17 1.58 KB
提交时间 评测时间
2024-04-07 22:35:40 2024-04-07 22:35:45
#include<bits/stdc++.h>
#define cir(i,a,b) for(int i=a;i<b;++i)
using namespace std;
using complf=complex<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<int> ans(n);
        cir(i,0,n) ans[i]=round(fx[i].imag()/2);
        return ans;
    }
}
int main(){
    ios::sync_with_stdio(false),cin.tie(0);
    int n,m;cin>>n>>m;++n;++m;
    vector<int> a(n),b(m);
    for(auto&i:a) cin>>i;
    for(auto&i:b) cin>>i;
    const auto ans=poly::mul(a,b);
    cir(i,0,n+m-1) cout<<ans[i]<<' ';
    cout<<'\n';
    return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #151.8 us60 KBAcceptedScore: 100

Subtask #1 Testcase #251.056 ms8 MB + 12 KBAcceptedScore: 0

Subtask #1 Testcase #323.289 ms3 MB + 620 KBAcceptedScore: 0

Subtask #1 Testcase #423.272 ms3 MB + 608 KBAcceptedScore: 0

Subtask #1 Testcase #544.04 us60 KBAcceptedScore: 0

Subtask #1 Testcase #644.33 us60 KBAcceptedScore: 0

Subtask #1 Testcase #743.84 us60 KBAcceptedScore: 0

Subtask #1 Testcase #846.627 ms7 MB + 500 KBAcceptedScore: 0

Subtask #1 Testcase #946.597 ms7 MB + 500 KBAcceptedScore: 0

Subtask #1 Testcase #1042.225 ms6 MB + 984 KBAcceptedScore: 0

Subtask #1 Testcase #1151.641 ms8 MB + 92 KBAcceptedScore: 0

Subtask #1 Testcase #1247.998 ms6 MB + 996 KBAcceptedScore: 0

Subtask #1 Testcase #1343.33 us60 KBAcceptedScore: 0


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