提交记录 17024


用户 题目 状态 得分 用时 内存 语言 代码长度
kpeaker 1002. 测测你的多项式乘法 Accepted 100 311.62 ms 24240 KB C++ 1.51 KB
提交时间 评测时间
2021-11-29 11:07:27 2021-11-29 11:07:31
#pragma GCC optimize("Ofast","-funroll-loops")
//#pragma GCC target("sse4.1","sse4.2","ssse3","sse3","sse2","sse","avx2","avx","popcnt","tune=native")
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const unsigned MOD=998244353,G=3;
unsigned qpow(unsigned a,unsigned b,unsigned ans=1){
	for(unsigned base=a%MOD;b;b/=2){
		if(b&1)ans=(ull)ans*base%MOD;
		base=(ull)base*base%MOD;
	}
	return ans;
}
inline unsigned inv(unsigned T){return qpow(T,MOD-2);}
inline unsigned add(unsigned a,unsigned b){return a+b>=MOD?(a+b-MOD):a+b;}
inline void D(unsigned *a,unsigned len,int op=1){
	for(unsigned i=1,k,j=len>>1;i+1<len;++i){
		if(i<j)a[i]^=a[j],a[j]^=a[i],a[i]^=a[j];
		k=len>>1;
		while(j>=k)j=j-k,k=k>>1;
		j+=k;
	}
	for(unsigned L=1;L<len;L*=2){
        unsigned step=qpow(G,(MOD-1)/2/L);
        if(op!=1) step=inv(step);
        for(unsigned i=0;i<len;i+=L*2){
            ull cur=1;for(unsigned k=i;k<i+L;++k){
                unsigned g=a[k],h=a[k+L]*cur%MOD;
                a[k]=add(g,h);
				a[k+L]=add(g,MOD-h);
                (cur*=step)%=MOD;
            }
        }
    }
}
unsigned av[3000000];
unsigned bv[3000000];
void poly_multiply(unsigned *a, int n, unsigned *b, int m, unsigned *c)
{
	int len=1,mt=max(n,m)*2;
	while(len<mt)len*=2;
	memcpy(av,a,sizeof(unsigned)*(n+1));
	memcpy(bv,b,sizeof(unsigned)*(m+1));
	D(av,len),D(bv,len);
	for(int i=0;i<len;++i)av[i]=1ull*av[i]*bv[i]%MOD;
	D(av,len,0);
    for(unsigned i=0,invN=inv(len);i<=(unsigned)n+m;++i)c[i]=1ull*av[i]*invN%MOD;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #1311.62 ms23 MB + 688 KBAcceptedScore: 100


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