提交记录 16889


用户 题目 状态 得分 用时 内存 语言 代码长度
Saisyc 1002i. 【模板题】多项式乘法 Accepted 100 21.19 ms 6560 KB C++ 2.50 KB
提交时间 评测时间
2021-10-26 17:07:23 2021-10-26 17:07:27
#include <cstdio>
#include <cctype>
#include <algorithm>

namespace fastIO {
    const int SZ = 1 << 25;
    char ibuf[SZ], *p0 = ibuf, *p1 = ibuf;
    char getchar(void) { return p0 == p1 && (p1 = (p0 = ibuf) + fread(ibuf, 1, SZ, stdin), p0 == p1) ? EOF : *p0++; }
    char char_read; void read(auto &val) {
		val = 0; do char_read = getchar(); while(!isdigit(char_read));
		do val = val * 10 + char_read - '0'; while(isdigit(char_read = getchar()));
    }
    char obuf[SZ], *p = obuf;
    void putchar(char char_write) { *p++ = char_write; }
    void write(auto val) { if(val >= 10) write(val / 10); putchar(val % 10 + '0'); }
    void write(auto a[], int sz) { for(int i = 0; i < sz; ++i) write(a[i].val), putchar(' '); putchar('\n'); }
    void output(void) { fwrite(obuf, p - obuf, 1, stdout);}
};

const int N =     1 << 21;
const int p =    81 << 21 | 1;
const int g =  1167 << 12 | 1;
const int h = 11443 << 12 | 1;

struct RING {
	int val;
	RING operator + (const RING r) const { return (RING){ val + r.val < p ? val + r.val : val + r.val - p }; }
	RING operator - (const RING r) const { return (RING){ val - r.val < 0 ? val - r.val + p : val - r.val }; }
	RING operator * (const RING r) const { return (RING){ (long long)val * r.val % p }; }
	RING operator * (const int  w) const { return (RING){ (long long)val * w     % p }; }
};

int pow_modp(int a, int b) { int x = 1; for(; b; a = (long long)a * a % p, b >>= 1) if(b & 1) x = (long long)x * a % p; return x; }

RING ntt_sup[N];
void ntt(auto a[], int n, int w) {
	auto ntt_a = ntt_sup; for(int i = 1; i < n; i <<= 1, w = (long long)w * w % p, std :: swap(a, ntt_a)) {
		auto _w = 1; for(auto k0 = ntt_a, j0 = a, j1 = a + (n >> 1); k0 != ntt_a + n; k0 += i, _w = (long long)_w * w % p)
			for(auto k1 = k0 + i, _k0 = k1; k0 != _k0; ++j0, ++j1, ++k0, ++k1) *k0 = *j0 + *j1, *k1 = (*j0 - *j1) * _w;
	}
	if(ntt_a != ntt_sup) std :: copy(a, a + n, ntt_a);
}
void poly_mul(auto a[], auto b[], int n) {
	ntt(a, n, pow_modp(g, (p - 1) / n)), ntt(b, n, pow_modp(g, (p - 1) / n));
	for(int i = 0; i < n; ++i) a[i] = a[i] * b[i]; ntt(a, n, pow_modp(h, (p - 1) / n));
	int inv_n = pow_modp(n, p - 2); for(int i = 0; i < n; ++i) a[i] = a[i] * inv_n;
}

int n, n_a, n_b;
RING a[N], b[N];

int main(void) {
	fastIO :: read(n_a), fastIO :: read(n_b); ++n_a, ++n_b; for(n = 1; n < n_a + n_b; n <<= 1);
	for(int i = 0; i < n_a; ++i) fastIO :: read(a[i].val);
	for(int i = 0; i < n_b; ++i) fastIO :: read(b[i].val);
	poly_mul(a, b, n); n = n_a + n_b - 1;
	fastIO :: write(a, n), fastIO :: output();
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Subtask #1 Testcase #17.78 us32 KBAcceptedScore: 0

Subtask #1 Testcase #220.946 ms6 MB + 252 KBAcceptedScore: 0

Subtask #1 Testcase #38.929 ms2 MB + 276 KBAcceptedScore: 100

Subtask #1 Testcase #49.004 ms2 MB + 256 KBAcceptedScore: 0

Subtask #1 Testcase #58.89 us32 KBAcceptedScore: 0

Subtask #1 Testcase #68.3 us32 KBAcceptedScore: 0

Subtask #1 Testcase #77.18 us32 KBAcceptedScore: 0

Subtask #1 Testcase #820.129 ms5 MB + 676 KBAcceptedScore: 0

Subtask #1 Testcase #920.108 ms5 MB + 676 KBAcceptedScore: 0

Subtask #1 Testcase #1019.312 ms5 MB + 72 KBAcceptedScore: 0

Subtask #1 Testcase #1121.19 ms6 MB + 416 KBAcceptedScore: 0

Subtask #1 Testcase #1218.008 ms4 MB + 172 KBAcceptedScore: 0

Subtask #1 Testcase #137.23 us32 KBAcceptedScore: 0


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