提交记录 11510


用户 题目 状态 得分 用时 内存 语言 代码长度
Fister 1002. 测测你的多项式乘法 Accepted 100 612.611 ms 164868 KB C++11 1.52 KB
提交时间 评测时间
2020-01-18 15:21:55 2020-08-01 02:44:46
#include<bits/stdc++.h>
#define maxn 3000005
#define Pi 3.1415926535897932384626433832795
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define db double
#define Ct const 
using namespace std;

char cb[1<<16],*cs=cb,*ct=cb;
#define getc() (cs==ct&&(ct=(cs=cb)+fread(cb,1,1<<16,stdin),cs==ct)?0:*cs++)
template<class T>void read(T &res){char ch;
	for(;!isdigit(ch=getc()););
	for(res=ch-'0';isdigit(ch=getc());res=res*10+ch-'0');
}

struct cp{
	db r,i;cp(db r=0,db i=0):r(r),i(i){}
	cp operator +(Ct cp &B)Ct{ return cp(r+B.r,i+B.i); }
	cp operator -(Ct cp &B)Ct{ return cp(r-B.r,i-B.i); }
	cp operator *(Ct cp &B)Ct{ return cp(r*B.r-i*B.i,r*B.i+i*B.r);  }   
	cp conj()Ct{ return cp(r,-i); }
};

int Wl,lg[maxn],r[maxn];
cp W[maxn];
void init(int n){
	for(Wl=1;n>=2*Wl;Wl<<=1);
	rep(i,0,Wl) W[i]=cp(cos(i*Pi/Wl),sin(i*Pi/Wl));
	rep(i,2,Wl<<1) lg[i]=lg[i>>1]+1;
}
void FFT(cp *A,int n,int tp){
	rep(i,1,n-1) (i<(r[i]=(r[i>>1]>>1)|((i&1)<<(lg[n]-1))))&&(swap(A[i],A[r[i]]),0);cp t;
	for(int L=1,B=Wl;L<n;L<<=1,B>>=1) for(int s=0;s<n;s+=L<<1) for(int k=s,x=0;k<s+L;k++,x+=B) 
		t=(tp==1?W[x]:W[x].conj())*A[k+L],A[k+L]=A[k]-t,A[k]=A[k]+t;
	if(tp^1) rep(i,0,n-1) A[i].r/=n;
}
cp A[maxn],B[maxn];
void poly_multiply(unsigned *a, int n, unsigned *b, int m, unsigned *c){
	double x;
	rep(i,0,n) A[i].r=a[i];
	rep(i,0,m) A[i].i=b[i];
	init(n+m);
	FFT(A,Wl<<1,1);
	rep(i,0,(Wl<<1)-1) B[i]=(A[i]+A[i?(Wl<<1)-i:0].conj())*(A[i]-A[i?(Wl<<1)-i:0].conj())*cp(0,-0.25);
	FFT(B,Wl<<1,-1);
	rep(i,0,n+m) c[i]=round(B[i].r);
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #1612.611 ms161 MB + 4 KBAcceptedScore: 100


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