提交记录 7892


用户 题目 状态 得分 用时 内存 语言 代码长度
mengbier 1002i. 【模板题】多项式乘法 Accepted 100 25.226 ms 6840 KB C++ 1.82 KB
提交时间 评测时间
2019-01-25 19:31:32 2020-08-01 01:09:54
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#define getchar() (*sS++)
#define add(x,y) ((x)+(y)>=MOD ? (x)+(y)-MOD : (x)+(y))
#define minus(x,y) ((x)-(y)<0 ? (x)-(y)+MOD : (x)-(y))
typedef unsigned int uint;
typedef std::vector<int> vi;
typedef std::vector<int> Poly;
const int G=3;
const int maxn=1<<18|7;
const int MOD=998244353;
char s[1<<20];
char *sS=s;
inline void I(int &x){
	register int ch;
	while(ch=getchar(),ch<'/');x=ch-'0';
	while(ch=getchar(),ch>'/')x=((x+(x<<2))<<1)+ch-'0';
}
inline void O(int x){
	if(x>9)O(x/10),putchar('0'+x%10);
	else putchar('0'+x);
}
inline int Pow(int x,int k){
	int ans=1;
	for(;k;x=x*1ll*x%MOD,k>>=1)
		if(k&1)ans=ans*1ll*x%MOD;
	return ans;
}
inline vi Getrev(int n){
	int len=1,cnt=0;
	while(len<n)len<<=1,++cnt;
	vi rev(len);
	for(int i=1;i<len;++i)
		rev[i]=(rev[i>>1]>>1)|((i&1)<<(cnt-1));
	return rev;
}
inline void NTT(Poly &A,vi &rev,int K){
	register int i,j,k,t,wn;
	int len=rev.size();A.resize(len);
	for(i=0;i<len;++i) if(i<rev[i])
		std::swap(A[i],A[rev[i]]);
	vi w(len);w[0]=1;
	for(i=1,t=2;i<len;i<<=1,t<<=1){
		wn=Pow(G,(K*(MOD-1)/t+MOD-1)%(MOD-1));
		for(k=i-2;k>=0;k-=2)
			w[k+1]=wn*1ll*(w[k]=w[k>>1])%MOD;
		for(j=0;j<len;j+=t) for(k=0;k<i;++k){
			int x=A[j+k],y=A[j+k+i]*1ll*w[k]%MOD;
			A[j+k]=add(x,y),A[j+k+i]=minus(x,y);
		}
	}
	if(K==-1){
		t=Pow(len,MOD-2);
		for(i=0;i<len;++i)
			A[i]=A[i]*1ll*t%MOD;
	}
}
inline void operator *(Poly &A,Poly &B){
	int n=A.size()+B.size()-1;
	vi rev(Getrev(n));
	NTT(A,rev,1),NTT(B,rev,1);
	for(uint i=0;i<A.size();++i)
		A[i]=A[i]*1ll*B[i]%MOD;
	NTT(A,rev,-1);
	for(int i=0;i<n;++i)
		O(A[i]),putchar(' ');
	putchar('\n');
}
int n,m;
Poly A,B;
int main(){
	fread(s,1,1<<20,stdin);
	I(n),I(m);
	A.resize(n+1),B.resize(m+1);
	for(int i=0;i<=n;++i)I(A[i]);
	for(int i=0;i<=m;++i)I(B[i]);
	return A*B,0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #136.23 us40 KBAcceptedScore: 0

Subtask #1 Testcase #225.007 ms6 MB + 616 KBAcceptedScore: 100

Subtask #1 Testcase #311.202 ms2 MB + 912 KBAcceptedScore: 0

Subtask #1 Testcase #411.618 ms2 MB + 900 KBAcceptedScore: 0

Subtask #1 Testcase #538.61 us40 KBAcceptedScore: 0

Subtask #1 Testcase #636.99 us40 KBAcceptedScore: 0

Subtask #1 Testcase #735.88 us40 KBAcceptedScore: 0

Subtask #1 Testcase #824.084 ms6 MB + 148 KBAcceptedScore: 0

Subtask #1 Testcase #924.113 ms6 MB + 148 KBAcceptedScore: 0

Subtask #1 Testcase #1023.238 ms5 MB + 700 KBAcceptedScore: 0

Subtask #1 Testcase #1125.226 ms6 MB + 696 KBAcceptedScore: 0

Subtask #1 Testcase #1221.814 ms5 MB + 576 KBAcceptedScore: 0

Subtask #1 Testcase #1335.46 us40 KBAcceptedScore: 0


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