提交记录 11818


用户 题目 状态 得分 用时 内存 语言 代码长度
Karry5307 1002i. 【模板题】多项式乘法 Accepted 100 29.569 ms 8104 KB C++11 2.67 KB
提交时间 评测时间
2020-02-14 22:38:19 2020-08-01 02:48:15
#include<cstdio>
#include<cstring>
#include<cctype>
#include<cmath>
#include<iostream>
#include<algorithm>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef int ll;
typedef long long int li;
typedef unsigned long long int ull;
const ll MAXN=262151,MOD=998244353,G=3,INVG=332748118;
ll fd,gd,cnt,limit;
ll f[MAXN],g[MAXN],res[MAXN],rev[MAXN],omgs[MAXN];
char buf[400051],*st=buf,*ed=buf;
inline char gc()
{
	return st==ed&&(ed=(st=buf)+fread(buf,1,400051,stdin),ed==st)?0:*st++; 
}
inline ll read()
{
    register ll num=0;
    register char ch=gc();
    while(!isdigit(ch))
    {
        ch=gc();
    }
    while(isdigit(ch))
    {
        num=(num<<3)+(num<<1)+(ch-'0');
        ch=gc();
    }
    return num;
}
inline void write(ll x)
{
	if(x>9)
	{
		write(x/10);
	}
	putchar(x%10+'0');
}
inline ll readSingleDigit()
{
    register char ch=gc();
    while(!isdigit(ch))
    {
        ch=gc();
    }
    if(isdigit(ch))
    {
        return ch-48;
    }
}
inline ll qpow(ll base,ll exponent)
{
    li res=1;
    while(exponent)
    {
        if(exponent&1)
        {
            res=1ll*res*base%MOD;
        }
        base=1ll*base*base%MOD,exponent>>=1;
    }
    return res;
}
inline void setupOmg(ll cnt)
{
	ll limit=log2(cnt)-1,omg;
	omg=qpow(G,(MOD-1)>>(limit+1)),omgs[cnt>>1]=1;
	for(register int i=(cnt>>1|1);i!=cnt;i++)
	{
		omgs[i]=(li)omgs[i-1]*omg%MOD;
	}
	for(register int i=(cnt>>1)-1;i;i--)
	{
		omgs[i]=omgs[i<<1]; 
	}
}
inline void NTT(ll *cp,ll cnt,ll inv)
{
	static ull tcp[MAXN];
    register ll cur=0,x,shift=log2(cnt)-__builtin_ctz(cnt);
    if(inv==-1)
    {
    	reverse(cp+1,cp+cnt);
	}
    for(register int i=0;i<cnt;i++)
	{
		tcp[rev[i]>>shift]=cp[i];
	}
    for(register int i=2;i<=cnt;i<<=1)
    {
        cur=i>>1;
        for(register int j=0;j<cnt;j+=i)
        {
            for(register int k=0;k<cur;k++)
            {
                x=tcp[j|k|cur]*omgs[k|cur]%MOD;
                tcp[j|k|cur]=tcp[j|k]+MOD-x,tcp[j|k]+=x;
            }
        }
    }
    for(register int i=0;i<cnt;i++)
    {
    	cp[i]=tcp[i]%MOD;
	}
	if(inv==1)
	{
		return;
	}
    x=MOD-(MOD-1)/cnt;
    for(register int i=0;i<cnt;i++)
    {
    	cp[i]=(li)cp[i]*x%MOD;
	}
}
int main()
{
	fd=read()+1,gd=read()+1;
	for(register int i=0;i<fd;i++)
	{
		f[i]=readSingleDigit();
	}
	for(register int i=0;i<gd;i++)
	{
		g[i]=readSingleDigit();
	}
	cnt=1,limit=-1;
	while(cnt<=(fd+gd))
	{
		cnt<<=1,limit++;
	}
	setupOmg(cnt);
	for(register int i=0;i<cnt;i++)
	{
		rev[i]=(rev[i>>1]>>1)|((i&1)<<limit);
	}
	NTT(f,cnt,1),NTT(g,cnt,1);
	for(register int i=0;i<cnt;i++)
	{
		f[i]=(li)f[i]*g[i]%MOD;
	}
	NTT(f,cnt,-1);
	for(register int i=0;i<fd+gd-1;i++)
	{
		write(f[i]),putchar(' ');
	}
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #136.41 us60 KBAcceptedScore: 0

Subtask #1 Testcase #228.259 ms7 MB + 856 KBAcceptedScore: 100

Subtask #1 Testcase #39.682 ms3 MB + 532 KBAcceptedScore: 0

Subtask #1 Testcase #49.75 ms3 MB + 520 KBAcceptedScore: 0

Subtask #1 Testcase #536.92 us60 KBAcceptedScore: 0

Subtask #1 Testcase #637.18 us60 KBAcceptedScore: 0

Subtask #1 Testcase #735.56 us60 KBAcceptedScore: 0

Subtask #1 Testcase #826.582 ms7 MB + 528 KBAcceptedScore: 0

Subtask #1 Testcase #926.57 ms7 MB + 528 KBAcceptedScore: 0

Subtask #1 Testcase #1024.86 ms7 MB + 192 KBAcceptedScore: 0

Subtask #1 Testcase #1129.569 ms7 MB + 936 KBAcceptedScore: 0

Subtask #1 Testcase #1221.265 ms6 MB + 816 KBAcceptedScore: 0

Subtask #1 Testcase #1336.06 us60 KBAcceptedScore: 0


Judge Duck Online | 评测鸭在线
Server Time: 2024-12-05 10:34:50 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠