提交记录 17076


用户 题目 状态 得分 用时 内存 语言 代码长度
cyf 1002i. 【模板题】多项式乘法 Accepted 100 20.271 ms 9268 KB C++11 1.98 KB
提交时间 评测时间
2021-11-30 18:55:44 2021-11-30 18:55:48
#include <bits/stdc++.h>
#define maxn 600005
#define mod 998244353
#define LL long long
using namespace std;
int Wl,Wl2,w[maxn],r[maxn];
inline int Pow(int b, int k) { int r=1; for(;k;k>>=1,b=1ll*b*b%mod) if(k&1) r=1ll*r*b%mod; return r; }
inline void init(int n) {
	for(Wl=1;n>=Wl<<1;Wl<<=1); int pw=Pow(3,(mod-1)/(Wl2=Wl<<1)); w[Wl]=1;
	for(int i=Wl+1;i<=Wl2;i++) w[i]=w[i-1]*1ll*pw%mod; for(int i=Wl-1;i>=1;i--) w[i]=w[i<<1];
}
inline int upd(int x) { return x+=x>>31&mod; }
inline void NTT(int *A, int bit, int tp) {
	static unsigned LL ar[maxn]={};
	int n=1<<bit; if(tp^1) reverse(A+1,A+n);
	for(int i=0;i<n;i++) ar[i]=upd(A[r[i]]);
	for(int L=1;L<n;L<<=1) for(int s=0,L2=L<<1;s<n;s+=L2)
	for(int k=s,x=L,t;x<L2;x++,k++) t=ar[k+L]*w[x]%mod,ar[k+L]=ar[k]-t+mod,ar[k]+=t;
	for(int i=0;i<n;i++) A[i]=ar[i]%mod;
	if(tp^1) for(int i=0,iv=Pow(n,mod-2);i<n;i++) A[i]=1ll*A[i]*iv%mod;
}
inline int Init(int n) { int m; for(m=1;m<n;m<<=1); init(m); return m; }
namespace IO {
const int len=1<<18;
	char buf[len],*p1=buf,*p2=buf;
	#define nc (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<18,stdin),p1==p2)?EOF:*p1++)
	char out[len],*pout=out,*eout=out+len;
	inline void flush() { fwrite(out,1,pout-out,stdout),pout=out; }
	inline void pc(char c) { pout==eout&&(fwrite(out,1,len,stdout),pout=out); (*pout++)=c; }
	inline void put(int x,char suf=' ') {
		static char stk[40];int top=0;
		while(x) stk[top++]=x%10,x/=10;
		!top?pc('0'),0:0; while(top--) pc(stk[top]+'0');
		pc(suf);
	}
	inline int read(){
		char ch=nc; int x=0; for(;ch<'0'||ch>'9';ch=nc);
		for(x=ch-48,ch=nc;ch>='0'&&ch<='9';ch=nc)x=x*10+ch-48;
		return x;
	}
}
#define Rint IO::read()
using IO::put;
int n,m,A[maxn],B[maxn];
int main() {
	n=Rint+1;m=Rint+1; Init(n+m);
	for(int i=0;i<n;i++) A[i]=Rint; for(int i=0;i<m;i++) B[i]=Rint;
	int N=n+m-1,M=1; while((1<<M)<=N) M++;
	for(int i=0;i<(1<<M);i++) r[i]=(r[i>>1]>>1|(i&1)<<M-1);
	NTT(A,M,1); NTT(B,M,1);
	for(int i=0;i<(1<<M);i++) A[i]=1ll*A[i]*B[i]%mod; NTT(A,M,-1);
	for(int i=0;i<N;i++) put(A[i],' '); IO::flush();
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #134.71 us64 KBAcceptedScore: 0

Subtask #1 Testcase #220.082 ms8 MB + 996 KBAcceptedScore: 0

Subtask #1 Testcase #37.902 ms4 MB + 280 KBAcceptedScore: 100

Subtask #1 Testcase #47.909 ms4 MB + 268 KBAcceptedScore: 0

Subtask #1 Testcase #538.16 us64 KBAcceptedScore: 0

Subtask #1 Testcase #635.86 us64 KBAcceptedScore: 0

Subtask #1 Testcase #736.32 us64 KBAcceptedScore: 0

Subtask #1 Testcase #819.373 ms8 MB + 728 KBAcceptedScore: 0

Subtask #1 Testcase #919.408 ms8 MB + 728 KBAcceptedScore: 0

Subtask #1 Testcase #1018.735 ms8 MB + 460 KBAcceptedScore: 0

Subtask #1 Testcase #1120.271 ms9 MB + 52 KBAcceptedScore: 0

Subtask #1 Testcase #1217.437 ms7 MB + 956 KBAcceptedScore: 0

Subtask #1 Testcase #1335.74 us64 KBAcceptedScore: 0


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