提交记录 16355


用户 题目 状态 得分 用时 内存 语言 代码长度
000226 1002i. 【模板题】多项式乘法 Accepted 100 67.638 ms 6996 KB C++ 2.76 KB
提交时间 评测时间
2021-07-15 21:34:07 2021-07-15 21:34:12
#include <bits/stdc++.h>

using namespace std;

#define LL long long

inline int read() {
	int x = 0, f = 1; char a = getchar();
	for(; ! isdigit(a); a = getchar()) if(a == '-') f = -1;
	for(; isdigit(a); a = getchar()) x = x * 10 + a - '0';
	return x * f;
}

namespace Mathematicas {
	const int P = 998244353;
	
	inline int Mod(int x) { return x + ((x >> 31) & P); }
	
	int power(int x, int k) {
		int res = 1;
		while(k) {
			if(k & 1) res = (LL) res * x % P;
			x = (LL) x * x % P; k >>= 1;
		}
		return res;
	}
	
	const int G = 3;
	const int Gi = power(G, P - 2);
	
	int lim, bit;
	vector<int> rev;
	void init(int n) {
		lim = 1, bit = 0;
		while(lim < n) lim <<= 1, bit ++;
		rev.resize(lim);
		for(int i = 0; i < lim; i ++) 
			rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (bit - 1));
	}
	
	class Poly {
		public :
		vector<int> A;
		int lenth;
		Poly(int len) {
			lenth = len; A.resize(lenth);
		}
		void resize(int len);
		void clear();
		void print();
		int& operator [](int id) { return A[id]; }		
	} ;
	
	void Poly :: resize(int len) { 
			while(A.size() < len) A.push_back(0);
			while(A.size() > len) A.pop_back();
			for(int i = lenth; i < len; i ++) A[i] = 0;
			lenth = len;
		}
	
	void Poly :: clear() { A.clear(); A.resize(lenth); }
	
	void Poly :: print() {
		for(int i = 0; i < lenth; i ++) printf("%d ", A[i]);
		putchar('\n');
	}
	
	Poly operator +(Poly x, Poly y) {
		int len = max(x.lenth, y.lenth);
		x.resize(len); y.resize(len);
		for(int i = 0; i < len; i ++) x[i] = Mod(x[i] + y[i] - P);
		return x;	
	}
	
	Poly operator -(Poly x, Poly y) {
		int len = max(x.lenth, y.lenth);
		x.resize(len); y.resize(len);
		for(int i = 0; i < len; i ++) x[i] = Mod(x[i] - y[i]);
		return x;	
	}
	
	void NTT(Poly &A, int type) {
		A.resize(lim);
		for(int i = 0; i < lim; i ++) 
			if(i < rev[i]) swap(A[i], A[rev[i]]);
		for(int dep = 1; dep < lim; dep <<= 1) {
			int Wn = power(type == 1 ? G : Gi, (P - 1) / (dep << 1));
			for(int len = dep << 1, j = 0; j < lim; j += len) {
				int w = 1;
				for(int k = 0; k < dep; k ++, w = (LL) w * Wn % P) {
					int x = A[j + k], y = (LL) A[j + k + dep] * w % P;
					A[j + k] = Mod(x + y - P);
					A[j + k + dep] = Mod(x - y);
				}
			}
		}
		if(type == -1) {
			int inv = power(lim, P - 2);
			for(int i = 0; i < lim; i ++) A[i] = (LL) A[i] * inv % P;
		}
	}
	
	void DFT(Poly &A) { NTT(A, 1); }
	void IDFT(Poly &A) { NTT(A, -1); }
	
	Poly operator *(Poly A, Poly B) {
		int len = A.lenth + B.lenth - 1;
		init(len);
		DFT(A); DFT(B);
		for(int i = 0; i < lim; i ++) A[i] = (LL) A[i] * B[i] % P;
		IDFT(A); A.resize(len); 
		return A;
	}
}

using Mathematicas :: Poly; 

int main() {
	int n = read(), m = read();
	Poly a(n + 1), b(m + 1);
	for(int i = 0; i <= n; i ++) a[i] = read();
	for(int i = 0; i <= m; i ++) b[i] = read();
	a = a * b;
	a.print();
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #136.2 us36 KBAcceptedScore: 0

Subtask #1 Testcase #266.602 ms6 MB + 772 KBAcceptedScore: 0

Subtask #1 Testcase #330.576 ms3 MB + 80 KBAcceptedScore: 100

Subtask #1 Testcase #430.624 ms2 MB + 836 KBAcceptedScore: 0

Subtask #1 Testcase #540.94 us36 KBAcceptedScore: 0

Subtask #1 Testcase #638.01 us36 KBAcceptedScore: 0

Subtask #1 Testcase #737.34 us36 KBAcceptedScore: 0

Subtask #1 Testcase #861.549 ms6 MB + 740 KBAcceptedScore: 0

Subtask #1 Testcase #961.483 ms6 MB + 228 KBAcceptedScore: 0

Subtask #1 Testcase #1056.325 ms5 MB + 440 KBAcceptedScore: 0

Subtask #1 Testcase #1166.93 ms6 MB + 852 KBAcceptedScore: 0

Subtask #1 Testcase #1267.638 ms5 MB + 732 KBAcceptedScore: 0

Subtask #1 Testcase #1335.09 us36 KBAcceptedScore: 0


Judge Duck Online | 评测鸭在线
Server Time: 2026-03-19 08:20:06 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠