HDU 6061 RXD and functions
题目链接:HDU-6061
题意:给定f(x),求f(x-A)各项系数。
思路:推导公式有如下结论:
然后用NTT解决即可。
代码:
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long LL;
const LL MAXN=;
const LL MOD=; // NTT
// O(nlogn)
// Verified!
const LL P = MOD;
const LL G = ;
const LL NUM = ; LL wn[NUM];
LL A[MAXN], B[MAXN]; LL quick_mod(LL a, LL b, LL m)
{
LL ans = ;
a %= m;
while(b)
{
if(b & )
{
ans = ans * a % m;
b--;
}
b >>= ;
a = a * a % m;
}
return ans;
} void GetWn()
{
for(LL i=; i<NUM; i++)
{
LL t = << i;
wn[i] = quick_mod(G, (P - ) / t, P);
}
} void Prepare(char A[], char B[], LL a[], LL b[], LL &len)
{
len = ;
LL len_A = strlen(A);
LL len_B = strlen(B);
while(len <= * len_A || len <= * len_B) len <<= ;
for(LL i=; i<len_A; i++)
A[len - - i] = A[len_A - - i];
for(LL i=; i<len - len_A; i++)
A[i] = '';
for(LL i=; i<len_B; i++)
B[len - - i] = B[len_B - - i];
for(LL i=; i<len - len_B; i++)
B[i] = '';
for(LL i=; i<len; i++)
a[len - - i] = A[i] - '';
for(LL i=; i<len; i++)
b[len - - i] = B[i] - '';
} void Rader(LL a[], LL len)
{
LL j = len >> ;
for(LL i=; i<len-; i++)
{
if(i < j) swap(a[i], a[j]);
LL k = len >> ;
while(j >= k)
{
j -= k;
k >>= ;
}
if(j < k) j += k;
}
} void NTT(LL a[], LL len, LL on)
{
Rader(a, len);
LL id = ;
for(LL h = ; h <= len; h <<= )
{
id++;
for(LL j = ; j < len; j += h)
{
LL w = ;
for(LL k = j; k < j + h / ; k++)
{
LL u = a[k] % P;
LL t = w * (a[k + h / ] % P) % P;
a[k] = (u + t) % P;
a[k + h / ] = ((u - t) % P + P) % P;
w = w * wn[id] % P;
}
}
}
if(on == -)
{
for(LL i = ; i < len / ; i++)
swap(a[i], a[len - i]);
LL Inv = quick_mod(len, P - , P);
for(LL i = ; i < len; i++)
a[i] = a[i] % P * Inv % P;
}
} void Conv(LL a[], LL b[], LL n)
{
NTT(a, n, );
NTT(b, n, );
for(LL i = ; i < n; i++)
a[i] = a[i] * b[i] % P;
NTT(a, n, -);
} // 快速幂
// 求x^n%mod
// Verified!
LL powMod(LL x,LL n,LL mod)
{
LL res=;
while(n>)
{
if(n&) res=res*x % mod;
x=x*x % mod;
n>>=;
}
return res;
}
// 求逆元
// a和m应该互质
// 根据欧拉定理:a的逆即a^(phi(m)-1)
LL inv(LL a,LL m)
{
return powMod(a,m-,m);
// return powMod(a,eularPhi(m)-1,m);
}
LL mi[MAXN],invsum[MAXN],fac[MAXN];
LL c[MAXN];
int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif
GetWn();
int n;
while(scanf("%d",&n)!=EOF)
{
n++;
for(int i=;i<n;i++) scanf("%lld",&c[i]);
int m,s=;
scanf("%d",&m);
for(int i=;i<=m;i++)
{
int tmp;
scanf("%d",&tmp);
s=(s+tmp)%MOD;
}
int len=;
while(len<*n) len*=;
mi[]=fac[]=invsum[]=invsum[]=;
for(int i=;i<n;i++)
mi[i]=mi[i-]*(P-s)%MOD;
for(int i=;i<n;i++)
fac[i]=fac[i-]*i%MOD;
for(int i=;i<n;i++)
invsum[i]=inv(fac[i],MOD);
for(int i=;i<n;i++)
A[i]=mi[i]*invsum[i]%MOD;
for(int i=;i<n;i++)
B[i]=c[n-i-]*fac[n-i-]%MOD;
for(int i=n;i<len;i++)
A[i]=B[i]=;
Conv(A, B, len);
for(int i=;i<n;i++)
printf("%lld ",A[n-i-]*invsum[i]%MOD);
printf("\n");
}
return ;
}
HDU 6061 RXD and functions的更多相关文章
- 2017 多校3 hdu 6061 RXD and functions
2017 多校3 hdu 6061 RXD and functions(FFT) 题意: 给一个函数\(f(x)=\sum_{i=0}^{n}c_i \cdot x^{i}\) 求\(g(x) = f ...
- HDU 6061 - RXD and functions | 2017 Multi-University Training Contest 3
每次NTT都忘记初始化,真的是写一个小时,Debug两个小时- - /* HDU 6061 - RXD and functions [ NTT ] | 2017 Multi-University Tr ...
- HDU 6061 RXD and functions NTT
RXD and functions Problem Description RXD has a polynomial function f(x), f(x)=∑ni=0cixiRXD has a tr ...
- HDU 6061 RXD and functions(NTT)
题意 给定一个\(n\) 次的 \(f\) 函数,向右移动 \(m\) 次得到 \(g\) 函数,第 \(i\) 次移动长度是 \(a_i\) ,求 \(g\) 函数解析式的各项系数,对 ...
- HDU 6060 - RXD and dividing | 2017 Multi-University Training Contest 3
/* HDU 6060 - RXD and dividing [ 分析,图论 ] | 2017 Multi-University Training Contest 3 题意: 给一个 n 个节点的树, ...
- HDU 6063 - RXD and math | 2017 Multi-University Training Contest 3
比赛时候面向过题队伍数目 打表- - 看了题解发现确实是这么回事,分析能力太差.. /* HDU 6063 - RXD and math [ 数学,规律 ] | 2017 Multi-Universi ...
- HDU6061 RXD and functions【NTT】
\(RXD\ and\ functions\) Problem Description RXD has a polynomial function \(f(x)\), \(f(x)=\sum ^{n} ...
- HDU 6060 RXD and dividing(思维+计算贡献值)
http://acm.hdu.edu.cn/showproblem.php?pid=6060 题意: 给定一棵 n 个节点的树,1 为根.现要将节点 2 ~ n 划分为 k 块,使得每一块与根节点形成 ...
- 2017 ACM暑期多校联合训练 - Team 3 1008 HDU 6063 RXD and math (莫比乌斯函数)
题目链接 Problem Description RXD is a good mathematician. One day he wants to calculate: ∑i=1nkμ2(i)×⌊nk ...
随机推荐
- [CF850F] Rainbow Balls
题目大意 这里 题解 我们枚举最后剩下的球的种类,那么其他球可以看做没用了. 设选定的球有\(a_i\)个,球的总数为\(s=\sum_{i=1}^n a_i\). 现在问题变为:在一个长度为\(s\ ...
- yii2 查询数据库语法
$query0 = ImGroupUser::find()->where(['gid'=>'56680dfc60b215d62104a4d8'])->select('user_cli ...
- 【BZOJ2731】三角形覆盖问题
想象一条平行于\(y\)轴的扫描线,从低往高扫描.如何确定关键高度才能使每两个关键高度之间分割出的图形易于计算呢? 关键高度有:三角形底边高度.三角形上顶点高度.三角形交点的高度. 如此分割,我们 ...
- Java之使用链表实现队列
import java.util.Iterator; import java.util.NoSuchElementException; /** * 使用链表来实现队列 * 1.考虑结点的结构,包括当前 ...
- 百度地图JS API不能使用position:fixed
用于放置百度地图的dom元素及其任何一级父元素设置position:fixed属性时,js会报如下错误: Uncaught TypeError: Cannot read property 'offse ...
- PDF文档小技巧整理一览
1.福昕阅读器文档背景修改为保护眼睛的颜色? 1)文件 -> 偏好设置 -> 访问 -> 勾选 "改变文档颜色" 2)选择 '自定义颜色'->'页面背景颜色 ...
- Java入门:Java环境变量PATH、CLASSPATH、JAVA_HOME
一些初学者在用java HelloWorld指令运行程序的时候出现: Exception in thread "main" java.lang.NoClassDefFoundErr ...
- SFTP上传下载文件、文件夹常用操作
SFTP上传下载文件.文件夹常用操作 1.查看上传下载目录lpwd 2.改变上传和下载的目录(例如D盘):lcd d:/ 3.查看当前路径pwd 4.下载文件(例如我要将服务器上tomcat的日志文 ...
- bzoj千题计划130:bzoj1305: [CQOI2009]dance跳舞
http://www.lydsy.com/JudgeOnline/problem.php?id=1305 每个人拆为喜欢(yes)和不喜欢(no)两个点 二分答案 1.每两个人之间只能跳一次 喜欢则 ...
- openGL笔记-画基本图形
#include "iostream" #include <GL/glut.h> #include<cmath> #include<vector> ...