关闭

[HDU] 6061 RXD and functions [NTT]

标签: ntt
320人阅读 评论(0) 收藏 举报
分类:

URL: http://acm.split.hdu.edu.cn/showproblem.php?pid=6061

Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 524288/524288
K (Java/Others) Total Submission(s): 702 Accepted Submission(s): 282

Problem Description
RXD has a polynomial function f(x), f(x)=∑ni=0cixi
RXD has a transformation of function Tr(f,a), it returns another function g, which has a property that g(x)=f(x−a).
Given a1,a2,a3,…,am, RXD generates a polynomial function sequence gi, in which g0=f and gi=Tr(gi−1,ai)
RXD wants you to find gm, in the form of ∑mi=0bixi
You need to output bi module 998244353.
n≤105

Input
There are several test cases, please keep reading until EOF.
For each test case, the first line consists of 1 integer n, which means degF.
The next line consists of n+1 intergers ci,0≤ci<998244353, which means the coefficient of the polynomial.
The next line contains an integer m, which means the length of a.
The next line contains m integers, the i - th integer is ai.
There are 11 test cases.
0<=ai<998244353
∑m≤105

Output
For each test case, output an polynomial with degree n, which means the answer.

Sample Input
2
0 0 1
1
1

Sample Output
1 998244351 1
Hint

(x1)2=x22x+1

题解

待求表达式可以拆开然后化成 a(n)=ni=0h(i)g(i) 的形式

注意到只要令 h(x)=h(nx) 就可到一个卷积式 (hg)(n)=ni=0h(ni)g(i)

然后NTT

#include<stdio.h>

typedef long long LL;
const int MAXN = 1 << 18;
const int p    = (119 << 23) + 1;
const int g    = 3;
const int NUM  = 23;
int C[MAXN], A[MAXN], B[MAXN], fac[MAXN], wn[MAXN], n, m, len, S;

void swap(int &x, int &y) {
    int t = x;
    x = y;
    y = t;
}

int mod_pow(int a, int k) {
    int res = 1;
    while(k) {
        if(k&1) res = 1LL * res * a % p;
        a = 1LL * a * a % p;
        k >>= 1;
    }
    return res;
}

void init() {
    fac[0] = 1;
    for(int i = 1; i < MAXN; ++i) {
        fac[i] = 1LL * fac[i - 1] * i % p;
    }
    for(int i = 0; i < NUM; ++i) {
        int t = 1 << i;
        wn[i] = mod_pow(g, (p - 1) / t);
    }
}

void rader(int y[]) {
    for(int i = 1, j = len >> 1, k; i < len - 1; ++ i) {
        if(i < j) swap(y[i], y[j]);
        k = len >> 1;
        while(j >= k) {
            j -= k;
            k >>= 1;
        }
        if(j < k) j += k;
    }
}

void NTT(int y[], int op) {
    rader(y);
    int id = 0;
    for(int h = 2; h <= len; h <<= 1) {
        ++id;
        for(int i = 0; i < len; i += h) {
            int w = 1;
            for(int j = i; j < i + h / 2; ++j) {
                int u = y[j];
                int t = 1LL * w * y[j + h / 2] % p;
                y[j] = (u + t) % p;
                y[j + h / 2] = (u - t) % p;
                w = 1LL * w * wn[id] % p;
            }
        }
    }
    if(op == -1) {
        for(int i = 1; i < len / 2; ++i) {
            swap(y[i], y[len - i]);
        }
        int inv = mod_pow(len, p - 2);
        for(int i = 0; i < len; ++i) {
            y[i] = 1LL * y[i] * inv % p;
            y[i] += p;
            y[i] %= p;
        }
    }
}

void slove() {
    for(len = 1; len < (n << 1); len <<= 1) ;
//  printf("len: %d\n", len);
    for(int i = 0; i < len; ++i) {
        A[i] = i > n ? 0 : 1LL * C[n - i] * fac[n - i] % p;
        B[i] = i > n ? 0 : 1LL * mod_pow(S, i) * mod_pow(fac[i], p - 2) % p;
//      printf("#%d %d\n", C[i], B[i]);
    }
    NTT(A, 1);
    NTT(B, 1);
    for(int i = 0; i < len; ++i) {
        B[i] = 1LL * A[i] * B[i] % p;
    }
    NTT(B, -1);
    int top = len - 1;
    while(top && !B[top]) --top;
    for(int i = 0; i <= n; ++i) {
        int ans = 1LL * B[n - i] * mod_pow(fac[i], p - 2) % p;
        printf(i == n ? "%d \n" : "%d ", ans);
    }
}

int main()
{
    init();
    while(scanf("%d", &n) != EOF) {
        for(int i = 0; i <= n; ++i) {
            scanf("%d", C + i);
        }
        scanf("%d", &m);
        S = 0;
        for(int i = 0, a; i < m; ++i) {
            scanf("%d", &a);
            S -= a;
            S += p;
            S %= p;
        }
        slove();
    }
    return 0;
}
0
0
查看评论
发表评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场

【HDU5951 2016ACM ICPC亚洲区沈阳站-重现赛 D】【博弈 DP】Recursive sequence n物品A元B元连续竞价的平衡点

Winning an Auction Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Oth...
  • snowy_smile
  • snowy_smile
  • 2016-10-31 13:26
  • 1413

FFT/NTT做题方法与调试技巧(+提高码题效率的一些想法)

FFT/NTT是卷积运算常见而实用的优化但是FFT/NTT的处理过程并不像暴力运算(差不多是多项式乘法)那样能够直观地反映卷积结果的实时变化。因此在使用FFT时将会或多或少地加大调试的难度。如果调试程...
  • STcyclone
  • STcyclone
  • 2016-05-07 18:59
  • 1641

HDU2056 Rectangles 【矩形面积交】

Rectangles Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...
  • u012846486
  • u012846486
  • 2015-01-19 10:26
  • 1238

HDU 6061 RXD and functions(NTT+卷积)

传送门 RXD and functionsTime Limit: 4000/2000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/...
  • qingshui23
  • qingshui23
  • 2017-08-04 12:07
  • 656

HDU6061 RXD and functions[NTT]

HDU6061 RXD and functions
  • ControlBear
  • ControlBear
  • 2017-08-02 17:16
  • 183

解题报告:HDU_6061 RXD and functions NTT

题目链接 题意及官方题解: 思路: 先感谢Q巨指点Qrz... 先求得系数式: 拆开组合数: 把系数提取出来稍作变换: 整理一下: 得到: 然后就可以直接进行NTT了。...
  • qq_32570675
  • qq_32570675
  • 2017-08-02 10:27
  • 855

hdu 6061 RXD and functions [快速数论变换]

RXD has a polynomial function f(x)f(x), f(x)=∑ni=0cixif(x)=∑i=0ncixi RXD has a transformation of fu...
  • hnust_xx
  • hnust_xx
  • 2017-08-02 20:02
  • 102

HDU6061 RXD and functions

题目链接题意​ 已知 f(x)=∑ni=0cixif(x)=\sum_{i=0}^nc_ix^i ,给定一个长度为 mm 的数列 A ,求 f(x−∑mi=1ai)f(x-\sum_{i=1}^m...
  • dDarkdawn
  • dDarkdawn
  • 2017-08-06 15:03
  • 176

2017 多小训练第三场 HDU 6061 RXD and functions

NTT #include using namespace std; typedef long long ll; const int mod=998244353; const int maxn=4e...
  • US10152130155
  • US10152130155
  • 2017-08-03 00:16
  • 271

HDU 6061 RXD and functions

通过二项式,可以得出: bk=∑ni=0ci∗Cki∗biasn−ib_k=\sum_{i=0}^n{c_i*C_i^k*bias^{n-i}} bk=∑ni=0ci∗i!k!∗(i−k)!∗bi...
  • xin_jun
  • xin_jun
  • 2017-08-06 14:11
  • 138
    个人资料
    • 访问:145470次
    • 积分:3775
    • 等级:
    • 排名:第9892名
    • 原创:242篇
    • 转载:17篇
    • 译文:0篇
    • 评论:27条
    最新评论