提交记录 21443


用户 题目 状态 得分 用时 内存 语言 代码长度
ETO_leader 1002i. 【模板题】多项式乘法 Accepted 100 67.027 ms 6720 KB C++17 1.77 KB
提交时间 评测时间
2024-03-24 16:11:05 2024-03-24 16:11:09
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define cir(i,a,b) for(int i=a;i<b;++i)
using namespace std;
using lint=long long;
static constexpr auto MOD=998244353,omega=3;
namespace poly{
    constexpr auto qpow(lint a,lint b){
        auto res=1ll;
        while(b){
            if(b&1) (res*=a)%=MOD;
            (a*=a)%=MOD;b>>=1;
        }
        return res;
    }
    constexpr auto inv(lint x){
        return qpow(x,MOD-2);
    }
    template<typename _Ty>
    auto change(vector<_Ty>&a,const int n){
        vector<int> rev(n);
        cir(i,0,n){
            rev[i]=rev[i>>1]>>1;
            if(i&1) rev[i]|=(n>>1);
        }
        cir(i,0,n) if(i<rev[i]) swap(a[i],a[rev[i]]);
    }
    template<const int type>
    auto ntt(vector<lint>&a,const int n){
        change(a,n);
        for(auto h=2;h<n+1;h<<=1){
            const auto midi=h>>1;
            const auto wx=qpow(omega,(MOD-1)/h);
            for(int i=0;i<n;i+=h){
                auto u=1ll;
                for(auto k=i;k<i+midi;++k){
                    const auto wk=u*a[k+midi]%MOD;
                    a[k+midi]=(a[k]+MOD-wk)%MOD;
                    (a[k]+=wk)%=MOD;
                    (u*=wx)%=MOD;
                }
            }
        }
        if(type==-1){
            const auto invx=inv(n);
            reverse(a.begin()+1,a.end());
            for(auto&i:a) (i*=invx)%=MOD;
        }
    }
}
int main(){
    ios::sync_with_stdio(false),cin.tie(0);
    int n,m;cin>>n>>m;++n;++m;
    const auto lgn=(int)(log2(n+m)+1);
    const auto len=1<<lgn;
    vector<lint> a(len),b(len);
    cir(i,0,n) cin>>a[i];
    cir(i,0,m) cin>>b[i];
    poly::ntt<1>(a,len);
    poly::ntt<1>(b,len);
    cir(i,0,len) (a[i]*=b[i])%=MOD;
    poly::ntt<-1>(a,len);
    cir(i,0,n+m-1) cout<<a[i]<<' ';
    cout<<'\n';
    return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #154.48 us60 KBAcceptedScore: 100

Subtask #1 Testcase #266.562 ms6 MB + 496 KBAcceptedScore: 0

Subtask #1 Testcase #330.428 ms2 MB + 860 KBAcceptedScore: 0

Subtask #1 Testcase #430.419 ms2 MB + 848 KBAcceptedScore: 0

Subtask #1 Testcase #544.16 us60 KBAcceptedScore: 0

Subtask #1 Testcase #644.12 us60 KBAcceptedScore: 0

Subtask #1 Testcase #743.39 us60 KBAcceptedScore: 0

Subtask #1 Testcase #862.17 ms6 MB + 228 KBAcceptedScore: 0

Subtask #1 Testcase #962.187 ms6 MB + 228 KBAcceptedScore: 0

Subtask #1 Testcase #1057.861 ms5 MB + 984 KBAcceptedScore: 0

Subtask #1 Testcase #1167.027 ms6 MB + 576 KBAcceptedScore: 0

Subtask #1 Testcase #1263.456 ms5 MB + 456 KBAcceptedScore: 0

Subtask #1 Testcase #1343.71 us60 KBAcceptedScore: 0


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