萌新求助 爆零了
查看原帖
萌新求助 爆零了
443592
黑化肥会挥发楼主2021/12/4 19:22
using namespace std;
#define int long long 
const int N = 1000010, p = 1004535809, G = 3, Gi = 334845270;
const double PI = acos(-1);
typedef long long ll;
ll a[N], b[N];
int ans[N], RR[N], limit = 1;
int L;
ll n, m, k, t;
inline int read()
{
    register int x = 0, f = 1;
    register char ch = getchar();
    while(ch < '0' || ch > '9') {if(ch == '-')f = -1;ch = getchar();}
    while(ch >= '0' && ch <= '9') {x = x * 10 + ch - '0';ch = getchar();}
    return x * f;
}
ll qpow(ll a, ll b)
{
	ll res = 1;
	while(b)
	{
		if(b & 1) res = res * a % p;
		a = a * a % p;
		b >>= 1;
	}
	return res ;
}
ll inv(ll x)
{
	return qpow(x, p-2);
}
void NTT(ll *A, int type)
{
    for (int i = 0; i < limit; ++i)
        if(i < RR[i])
            swap(A[i], A[RR[i]]);
    for(int mid = 1; mid < limit; mid <<= 1)
    {
        ll wn = qpow(G, (p-1)/(mid * 2));
        if(type == -1) wn = qpow(Gi, (p-1)/(mid * 2));
        for(int len = mid << 1, pos = 0; pos < limit; pos += len)
        {
            ll w = 1;
            for(int k = 0; k < mid; ++k, w = 1ll * (w * wn) % p)
            {
                int x = A[pos + k] % p, y = 1ll* w * A[pos + mid + k] % p;
                A[pos + k] = (x + y) % p;
                A[pos + k + mid] = (x - y + p) % p;
            }
        }
    }
    if(type == -1)
    {
        ll limit_inv = inv(limit);
        for(int i = 0; i < limit; ++i)
            A[i] = (1ll * A[i] * limit_inv) % p;
    }
}

void poly_mul(ll a[], ll b[], int deg)
{
    for(limit = 1, L = 0; limit <= deg; limit <<= 1)
        L++;
    for(int i = 0; i < limit; ++i)
        RR[i] = (RR[i >> 1] >> 1) | ((i & 1) << (L-1));
    NTT(a, 1), NTT(b, 1);
    for(int i = 0; i <= limit; ++i)
        a[i] = 1ll* a[i] * b[i] % p;
    NTT(a, -1);
}
signed main()
{
	n = read(), m = read(); int t = read();
	for(int i = 1; i <= n; i++) a[i-1] = (read() + p) % p;
	b[0] = 1;
	if(t == 0)
		for(int i = 1; i <= n; i++)	b[i] = 1ll * b[i-1] * (m + i - 1) % p * qpow(i, p-2) % p;
	if(t == 1)
		for(int i = 1; i <= n; i++)	b[i] = (1ll *(-b[i-1]) * (m - i + 1 + p) % p * qpow(i, p-2) % p + p) % p;
	poly_mul(a, b, 2 * n);
	for(int i = 1; i <= n; i++)
		cout << a[i-1]<<" ";
	
}```
2021/12/4 19:22
加载中...