luogu 4725 【模板】多项式对数函数(多项式 ln)
- #include <cstdio>
- #include <string>
- #include <algorithm>
- #include <cstring>
- #include <vector>
- #define setIO(s) freopen(s".in","r",stdin)
- typedef long long ll;
- const int maxn=2100005;
- const ll mod=998244353;
- using namespace std;
- inline ll qpow(ll base,ll k) {
- ll tmp=1;
- for(;k;k>>=1,base=base*base%mod)if(k&1) tmp=tmp*base%mod;
- return tmp;
- }
- inline ll inv(ll a) { return qpow(a, mod-2); }
- inline void NTT(ll *a,int len,int flag) {
- for(int i=0,k=0;i<len;++i) {
- if(i>k) swap(a[i],a[k]);
- for(int j=len>>1;(k^=j)<j;j>>=1);
- }
- for(int mid=1;mid<len;mid<<=1) {
- ll wn=qpow(3, (mod-1)/(mid<<1)),x,y;
- if(flag==-1) wn=qpow(wn,mod-2);
- for(int i=0;i<len;i+=(mid<<1)) {
- ll w=1;
- for(int j=0;j<mid;++j) {
- x=a[i+j],y=w*a[i+j+mid]%mod;
- a[i+j]=(x+y)%mod, a[i+j+mid]=(x-y+mod)%mod;
- w=w*wn%mod;
- }
- }
- }
- if(flag==-1) {
- int re=qpow(len,mod-2);
- for(int i=0;i<len;++i) a[i]=a[i]*re%mod;
- }
- }
- ll A[maxn],B[maxn];
- struct poly {
- vector<ll>a;
- int len;
- poly(){}
- inline void clear() { len=0; a.clear(); }
- inline void rev() {reverse(a.begin(), a.end()); }
- inline void push(int x) { a.push_back(x),++len; }
- inline void resize(int x) { len=x; a.resize(x); }
- void getinv(poly &b,int n) {
- if(n==1) { b.clear(); b.push(inv(a[0])); return; }
- getinv(b,n>>1);
- int t=n<<1,lim=min(len,n);
- for(int i=0;i<lim;++i) A[i]=a[i];
- for(int i=lim;i<t;++i) A[i]=0;
- for(int i=0;i<b.len;++i) B[i]=b.a[i];
- for(int i=b.len;i<t;++i) B[i]=0;
- NTT(A,t,1),NTT(B,t,1);
- for(int i=0;i<t;++i) A[i]=(2-A[i]*B[i]%mod+mod)*B[i]%mod;
- NTT(A,t,-1);
- b.clear();
- for(int i=0;i<n;++i) b.push(A[i]);
- }
- poly Inv() {
- int n=1;
- while(n<=len)n<<=1;
- poly b;
- b.clear(), getinv(b,n);
- return b;
- }
- poly dao() {
- poly c;
- c.resize(len);
- for(int i=1;i<=len;++i) c.a[i-1]=a[i]*i%mod;
- return c;
- }
- poly jifen() {
- poly c;
- c.resize(len+1);
- for(int i=1;i<=len;++i) c.a[i]=a[i-1]*qpow(i,mod-2)%mod;
- c.a[0]=0;
- return c;
- }
- poly Ln() {
- poly c=dao()*Inv();
- return c.jifen();
- }
- poly operator * (const poly &b) const {
- int n=1;
- while(n<=len+b.len) n<<=1;
- for(int i=0;i<len;++i) A[i]=a[i];
- for(int i=len;i<n;++i) A[i]=0;
- for(int i=0;i<b.len;++i) B[i]=b.a[i];
- for(int i=b.len;i<n;++i) B[i]=0;
- NTT(A,n,1), NTT(B,n,1);
- for(int i=0;i<n;++i) A[i]=A[i]*B[i]%mod;
- NTT(A,n,-1);
- poly c;
- c.clear();
- for(int i=0;i<len+b.len-1;++i) c.push(A[i]);
- return c;
- }
- poly operator + (const poly &b) const {
- poly c;
- c.clear();
- for(int i=0;i<len;++i) c.push(a[i]);
- for(int i=0;i<b.len;++i) {
- if(i<len) c.a[i]=(c.a[i]+b.a[i])%mod;
- else c.push(b.a[i]);
- }
- return c;
- }
- poly operator - (const poly &b) const {
- poly c;
- c.clear();
- for(int i=0;i<len;++i) c.push(a[i]);
- for(int i=0;i<b.len;++i) {
- if(i<len) c.a[i]=(c.a[i]-b.a[i]+mod)%mod;
- else c.push((mod-b.a[i])%mod);
- }
- return c;
- }
- friend poly operator / (poly f,poly g) {
- poly Q;
- int l=f.len-g.len+1;
- f.rev(), g.rev(), g.resize(l), f.resize(l);
- g=g.Inv(), Q=f*g, Q.resize(l),Q.rev();
- return Q;
- }
- friend poly operator % (poly f,poly g) {
- poly u=f-(f/g)*g;
- u.resize(g.len-1);
- return u;
- }
- }po[4];
- inline void inv() {
- int n,x;
- scanf("%d",&n), po[0].clear();
- for(int i=0;i<n;++i) scanf("%d",&x), po[0].push(x);
- po[1]=po[0].Inv();
- for(int i=0;i<po[1].len;++i) printf("%lld ",po[1].a[i]);
- }
- inline void mult() {
- int n,m,x;
- scanf("%d%d",&n,&m);
- for(int i=0;i<=n;++i) scanf("%d",&x), po[0].push(x);
- for(int i=0;i<=m;++i) scanf("%d",&x), po[1].push(x);
- po[1]=po[0]*po[1];
- for(int i=0;i<po[1].len;++i) printf("%lld ",po[1].a[i]);
- }
- inline void divide() {
- int n,m,x;
- scanf("%d%d",&n,&m);
- for(int i=0;i<=n;++i) scanf("%d",&x), po[0].push(x);
- for(int i=0;i<=m;++i) scanf("%d",&x), po[1].push(x);
- po[2]=po[0]/po[1];
- for(int i=0;i<po[2].len;++i) printf("%lld ",po[2].a[i]);
- printf("\n");
- po[2]=po[0]%po[1];
- for(int i=0;i<po[2].len;++i) printf("%lld ",po[2].a[i]);
- }
- inline void Ln() {
- int n,x;
- scanf("%d",&n);
- for(int i=0;i<n;++i) scanf("%d",&x), po[0].push(x);
- po[0]=po[0].Ln();
- for(int i=0;i<n;++i) printf("%lld ",po[0].a[i]);
- }
- int main() {
- // setIO("input");
- Ln();
- return 0;
- }
luogu 4725 【模板】多项式对数函数(多项式 ln)的更多相关文章
- 洛谷P4725 【模板】多项式对数函数(多项式ln)
题意 题目链接 Sol 这个不用背XD 前置知识: \(f(x) = ln(x), f'(x) = \frac{1}{x}\) \(f(g(x)) = f'(g(x)) g'(x)\) 我们要求的是\ ...
- luogu P4725 多项式对数函数(多项式 ln)
LINK:多项式对数函数 多项式 ln 如题 是一个模板题.刚学会导数 几个知识点 \([f(x)\cdot g(x)]'=f(x)'g(x)+f(x)g(x)',f(g(x))'=f'(g(x))g ...
- 【Cogs2187】帕秋莉的超级多项式(多项式运算)
[Cogs2187]帕秋莉的超级多项式(多项式运算) 题面 Cogs 题解 多项式运算模板题 只提供代码了.. #include<iostream> #include<cstdio& ...
- 多项式总结&多项式板子
多项式总结&多项式板子 三角/反三角是不可能放的(也不可能真香的 多项式乘法(DFT,FFT,NTT,MTT) 背板子 前置知识:泰勒展开 如果\(f(x)\)在\(x_0\)处存在\(n\) ...
- [luogu P3384] [模板]树链剖分
[luogu P3384] [模板]树链剖分 题目描述 如题,已知一棵包含N个结点的树(连通且无环),每个节点上包含一个数值,需要支持以下操作: 操作1: 格式: 1 x y z 表示将树从x到y结点 ...
- Luogu P2742 模板-二维凸包
Luogu P2742 模板-二维凸包 之前写的实在是太蠢了.于是重新写了一个. 用 \(Graham\) 算法求凸包. 注意两个向量 \(a\times b>0\) 的意义是 \(b\) 在 ...
- luogu P3919 [模板]可持久化数组(可持久化线段树/平衡树)(主席树)
luogu P3919 [模板]可持久化数组(可持久化线段树/平衡树) 题目 #include<iostream> #include<cstdlib> #include< ...
- Luogu 4725 【模板】多项式对数函数
继续补全模板. 要求 $$g(x) = ln f(x)$$ 两边求导, $$g'(x) = \frac{f'(x)}{f(x)}$$ 然后左转去把多项式求导和多项式求逆的模板复制过来,就可以计算出$g ...
- luogu P4725 多项式对数函数 (模板题、FFT、多项式求逆、求导和积分)
手动博客搬家: 本文发表于20181125 13:25:03, 原地址https://blog.csdn.net/suncongbo/article/details/84487306 题目链接: ht ...
随机推荐
- C#各种委托介绍
委托是一个类,它定义了方法的类型,使得可以将方法当作另一个方法的参数来进行传递.事件是一种特殊的委托. 一.委托的声明 Delegate Delegate 我们常用到的一种声明 Delegate 至少 ...
- 9.Jmeter 多个threadgroup 中的配置元件会一次性进行初始化
例如3个threadGroup,每一个threadGroup中都会定义了 一些配置原件,例如 用户定义变量, jdbc 链接配置等. 当执行testplan(测试计划)时, 这些配置元件会一起初始 ...
- idea 如何运行maven项目
1:run→Edit configurations 2:配置tomcat,左边如果没有tomcat server的话,点击 “+”,选择tomcat server→local,在右边server选项 ...
- 小程序图片预览 wx.previewImage
list: [ 'http://img5.imgtn.bdimg.com/it/u=3300305952,1328708913&fm=26&gp=0.jpg', 'http://i ...
- Elasticsearch-索引新数据(创建索引、添加数据)
ES-索引新数据 0.通过mapping映射新建索引 CURL -XPOST 'localhost:9200/test/index?pretty' -d '{ "mappings" ...
- etcd api常用操作
如果需要使用v2 version api,启动etcd时候需要加入“ETCD_ENABLE_V2=true”参数,否则会报错“404 page not found” 获取etcd信息 版本信息 # c ...
- Http服务器搭建(CentOS 7)
注意ip地址为: 虚拟机ip设置 TYPE="Ethernet"BOOTPROTO="static"NAME="enp0s3"DEVICE= ...
- HDU-4507-吉哥系列故事-恨7不成妻
题目描述 单身! 依然单身! 吉哥依然单身! DS级码农吉哥依然单身! 所以,他生平最恨情人节,不管是214还是77,他都讨厌! 吉哥观察了214和77这两个数,发现: 2+1+4=7 7+7=7*2 ...
- cs244a-Introduction to Computer Networking-Unit1
Unit 1 学习目标: how an application use the Internet The structure of the Internet:The 4 layer model The ...
- [工具]Hydra-爆破
语法 hydra [[[-l LOGIN | -L FILE] [-p PASS | -P FILE]] | [-C ...