提交记录 20513


用户 题目 状态 得分 用时 内存 语言 代码长度
lotus_f 1002i. 【模板题】多项式乘法 Accepted 100 27.606 ms 7608 KB C++14 5.20 KB
提交时间 评测时间
2023-11-02 08:02:11 2023-11-02 08:02:17
#include<bits/stdc++.h>
using namespace std;
namespace io
{
	const int size = (1 << 20) + 1;
	char buf[size], *p1 = buf, *p2 = buf;
	char buffer[size];
	int op1 = -1;
	const int op2 = size - 1;
	struct FastIO
	{
		inline char readchar()
		{
			return p1 != p2 ? *p1++ : p1 == (p2 = (p1 = buf) + fread(buf, 1, size - 1, stdin)) ? EOF
																							   : *p1++;
		}	
// #ifndef ONLINE_JUDGE
// #define readchar getchar
// #endif
		inline char rc()
		{
			char c=readchar();
			while(c<32 || c==127) c=readchar();
			return c;
		}
		inline void flush()
		{
			fwrite(buffer, 1, op1 + 1, stdout), op1 = -1;
		}
		inline void writechar(const char &x)
		{
			if (op1 == op2)
				flush();
			buffer[++op1] = x;
		}
		inline int readint()
		{
			int s = 1, x = 0;
			char c = readchar();
			while (c <= 32)
			{
				c = readchar();
			}
			if (c == '-')
			{
				s = -1, c = readchar();
			}
			while ('0' <= c && c <= '9')
			{
				x = x * 10 + c - '0';
				c = readchar();
			}
			return x * s;
		}
		inline int readuint()
		{
			int x = 0;
			char c = readchar();
			while (c <= 32)
			{
				c = readchar();
			}
			while ('0' <= c && c <= '9')
			{
				x = x * 10 + c - '0';
				c = readchar();
			}
			return x;
		}
		inline void writeint(int x)
		{
			if (x < 0)
			{
				writechar('-'), x = -x;
			}
			char s[24];
			int n = 0;
			while (x || !n)
			{
				s[n++] = '0' + x % 10, x /= 10;
			}
			while (n--)
			{
				writechar(s[n]);
			}
		}
		inline void writeuint(unsigned x)
		{
			char s[24];
			int n = 0;
			while (x || !n)
			{
				s[n++] = '0' + x % 10, x /= 10;
			}
			while (n--)
			{
				writechar(s[n]);
			}
		}
		inline long long readlonglong()
		{
			long long x = 0, s = 1;
			char c = readchar();
			while (c <= 32)
			{
				c = readchar();
			}
			if (c == '-')
			{
				s = -1, c = readchar();
			}
			while ('0' <= c && c <= '9')
			{
				x = x * 10 + c - '0';
				c = readchar();
			}
			return x * s;
		}
		inline unsigned long long readulonglong()
		{
			unsigned long long x = 0;
			char c = readchar();
			while (c <= 32)
			{
				c = readchar();
			}
			while ('0' <= c && c <= '9')
			{
				x = x * 10 + c - '0';
				c = readchar();
			}
			return x;
		}
		inline void writelonglong(long long x)
		{
			if (x < 0)
			{
				writechar('-'), x = -x;
			}
			char s[25];
			int n = 0;
			while (x || !n)
			{
				s[n++] = '0' + x % 10, x /= 10;
			}
			while (n--)
			{
				writechar(s[n]);
			}
		}
		inline void writeulonglong(unsigned long long x)
		{
			char s[25];
			int n = 0;
			while (x || !n)
			{
				s[n++] = '0' + x % 10, x /= 10;
			}
			while (n--)
			{
				writechar(s[n]);
			}
		}
		inline int readstring(char *s)
		{
			int cnt = 0;
			char c = readchar();
			while (c <= 32)
			{
				c = readchar();
			}
			while (c > 32)
			{
				*s++ = c, ++cnt;
				c = readchar();
			}
			return *s = 0, cnt;
		}
		inline void writestring(const char *s)
		{
			while (*s)
			{
				writechar(*s++);
			}
		}
		inline double readdouble()
		{
			int zheng = 0, fuhao = 1;
			double xiao = 0, chushu = 10;
			char c;
			while ((c = readchar()) < '0' || c > '9')
			{
				if (c == '-')
				{
					fuhao = -1;
				}
			}
			while (c >= '0' && c <= '9')
			{
				zheng = zheng * 10 + c - '0';
				c = readchar();
			}
			if (c != '.')
			{
				return fuhao * zheng;
			}
			while ((c = readchar()) >= '0' && c <= '9')
			{
				xiao += (c - '0') / chushu;
				chushu *= 10;
			}
			return fuhao * (zheng + xiao);
		}
	} io;
#define readc io::io.rc
#define writec io::io.writechar
#define read io::io.readint
#define readu io::io.readuint
#define write io::io.writeint
#define writeu io::io.writeuint 
#define readl io::io.readlonglong
#define readlu io::io.readulonglong
#define writel io::io.writelonglong
#define writelu io::io.writeulonglong
#define reads io::io.readstring
#define writes io::io.writestring
#define readd io::io.readdouble
#define flush io::io.flush
} using namespace io;
const int mod=998244353,g=3,gi=(mod+1)/g;
inline int add(const int &a,const int &b) { return a+b<mod?a+b:a+b-mod; }
int qpow(int a,int b)
{
	int ans=1;
	while(b!=0)
	{
		if(b%2==1) ans=1ll*ans*a%mod;
		a=1ll*a*a%mod,b/=2;
	}
	return ans;
}
const double pi=acos(-1);
int n,m;
int a[1<<21],b[1<<21];
int id[1<<21];
vector<int> ppow[21];
void ntt(int n,int *a)
{
	for(int i=0; i<n; ++i)
	{
		if(id[i]>i) swap(a[i],a[id[i]]);
	}
	for(int lg=0; lg<__lg(n); ++lg)
	{
		int len=(1<<lg);
		for(int l=0; l<n; l+=2*len)
		{
			for(int i=l; i<l+len; ++i)
			{
				int tmp=1ll*ppow[lg][i-l]*a[i+len]%mod,x=add(a[i],tmp),y=add(a[i],mod-tmp);
				a[i]=x,a[i+len]=y;
			}
		}
	}
}
void intt(int n,int *a)
{
	ntt(n,a),reverse(a+1,a+n);
	int invn=qpow(n,mod-2);
	for(int i=0; i<=n-1; ++i) a[i]=1ll*a[i]*invn%mod;
}
signed main()
{
	n=read(),m=read(); int lstlen=n+m;
	for(int i=0; i<=n; ++i) a[i]=read();
	for(int i=0; i<=m; ++i) b[i]=read();
	int lg=__lg(max(n,m))+2,n=(1<<lg);
	id[0]=0;
	for(int i=1; i<=lg; ++i)
	{
		for(int j=(1<<i-1); j<(1<<i); ++j) id[j]=id[j-(1<<i-1)]+(1<<lg-i);
	}
	for(int i=0; i<=lg-1; ++i)
	{
		int len=(1<<i);
		int w=qpow(g,(mod-1)/(len*2)),noww=1;
		for(int j=0; j<len; ++j) ppow[i].push_back(noww),noww=1ll*noww*w%mod;
	}
	ntt(n,a),ntt(n,b);
	for(int i=0; i<=n-1; ++i) a[i]=1ll*a[i]*b[i]%mod;
	intt(n,a);
	for(int i=0; i<=lstlen; ++i) write(a[i]),writec(' ');
	return flush(),0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #139.86 us56 KBAcceptedScore: 100

Subtask #1 Testcase #227.606 ms7 MB + 360 KBAcceptedScore: 0

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

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

Subtask #1 Testcase #537.53 us56 KBAcceptedScore: 0

Subtask #1 Testcase #636.91 us56 KBAcceptedScore: 0

Subtask #1 Testcase #736.34 us56 KBAcceptedScore: 0

Subtask #1 Testcase #826.836 ms7 MB + 24 KBAcceptedScore: 0

Subtask #1 Testcase #926.487 ms7 MB + 24 KBAcceptedScore: 0

Subtask #1 Testcase #1026.567 ms6 MB + 608 KBAcceptedScore: 0

Subtask #1 Testcase #1127.142 ms7 MB + 440 KBAcceptedScore: 0

Subtask #1 Testcase #1225.323 ms5 MB + 716 KBAcceptedScore: 0

Subtask #1 Testcase #1336.29 us56 KBAcceptedScore: 0


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