提交记录 13212


用户 题目 状态 得分 用时 内存 语言 代码长度
panyf 1002i. 【模板题】多项式乘法 Accepted 100 23.556 ms 12336 KB C++11 1.28 KB
提交时间 评测时间
2020-07-31 16:19:53 2020-08-01 03:06:41
#include<bits/stdc++.h>
using namespace std; 
const int N=21e5+3;
const double P=acos(-1);
struct C{
	double x,y;
	C operator+(C a)const{return{x+a.x,y+a.y};}
	C operator-(C a)const{return{x-a.x,y-a.y};}
	C operator*(C a)const{return{x*a.x-y*a.y,x*a.y+y*a.x};}
}a[N],g[N];
int n,r[N];
void fft(C*a){
	int i,j,k;
	C *w,*u,*v,x;
	for(i=0;i<n;++i)if(i<r[i])swap(a[i],a[r[i]]);
	for(i=1;i<n;i<<=1)for(j=0;j<n;j+=i<<1)for(k=0,w=g+i,u=a+j,v=u+i;k<i;++k)
	x=w[k]*v[k],v[k]=u[k]-x,u[k]=u[k]+x;
}
char buf[999999],*p1,*p2;
#define G (p1==p2?(p2=(p1=buf)+fread(buf,1,999991,stdin),*p1++):*p1++)
void in(int&x){char c=G;for(x=0;c<'0'||c>'9';c=G);for(;c>='0'&&c<='9';c=G)x=x*10+c-48;}
char c2[999999],st[13],*k3=c2,*k4;
void out(int x){
	if(!x){
		*k3++=48,*k3++=' ';
		return;
	}
	for(k4=st+1,*k4=' ';x;*++k4=x%10+48,x/=10);
	for(;k4!=st;*k3++=*k4--);
}
int main(){
	int m,i,j;
	double o;
	scanf("%d%d",&n,&m);
	for(i=0;i<=n;++i)in(j),a[i].x=j;
	for(i=0;i<=m;++i)in(j),a[i].y=j;
	for(m+=n,n=1;n<=m;n<<=1);
	for(i=0,g[j=n>>1]={1,0};i<n;++i)r[i]=(r[i>>1]>>1)|((i&1)?j:0);
	C w={cos(2*P/n),sin(2*P/n)};
	for(i=j+1;i<n;++i)g[i]=g[i-1]*w;
	for(i=j-1;i>0;--i)g[i]=g[i<<1];
	fft(a);
	for(i=0;i<n;++i)a[i]=a[i]*a[i];
	fft(a),a[n]=a[0],o=1.0/n/2;
	for(i=0;i<=m;++i)out(a[n-i].y*o+0.5);
	fwrite(c2,1,k3-c2,stdout);
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #136.92 us56 KBAcceptedScore: 0

Subtask #1 Testcase #223.264 ms11 MB + 912 KBAcceptedScore: 100

Subtask #1 Testcase #38.87 ms5 MB + 300 KBAcceptedScore: 0

Subtask #1 Testcase #48.965 ms5 MB + 280 KBAcceptedScore: 0

Subtask #1 Testcase #538.11 us56 KBAcceptedScore: 0

Subtask #1 Testcase #636.59 us56 KBAcceptedScore: 0

Subtask #1 Testcase #736.04 us56 KBAcceptedScore: 0

Subtask #1 Testcase #822.28 ms11 MB + 488 KBAcceptedScore: 0

Subtask #1 Testcase #922.27 ms11 MB + 488 KBAcceptedScore: 0

Subtask #1 Testcase #1021.249 ms11 MB + 96 KBAcceptedScore: 0

Subtask #1 Testcase #1123.556 ms12 MB + 48 KBAcceptedScore: 0

Subtask #1 Testcase #1219.129 ms10 MB + 200 KBAcceptedScore: 0

Subtask #1 Testcase #1336.12 us56 KBAcceptedScore: 0


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