洛谷P4841 城市规划(多项式求逆)

传送门

 

这题太珂怕了……如果是我的话完全想不出来……

题解

 1 //minamoto
 2 #include<iostream>
 3 #include<cstdio>
 4 #include<algorithm>
 5 #define ll long long
 6 #define swap(x,y) (x^=y,y^=x,x^=y)
 7 #define mul(x,y) (1ll*(x)*(y)%P)
 8 #define add(x,y) (x+y>=P?x+y-P:x+y)
 9 #define dec(x,y) (x-y<0?x-y+P:x-y)
10 using namespace std;
11 const int N=1000005,P=1004535809;
12 inline int ksm(int a,ll b){
13     int res=1;
14     while(b){
15         if(b&1) res=mul(res,a);
16         a=mul(a,a),b>>=1;
17     }
18     return res;
19 }
20 int n,r[N],A[N],B[N],fac[N],finv[N],O[N],C[N],F[N],G[N];
21 inline void init(){
22     fac[0]=fac[1]=finv[0]=1;
23     for(int i=2;i<=n;++i) fac[i]=mul(fac[i-1],i);
24     finv[n]=ksm(fac[n],P-2);
25     for(int i=n-1;i;--i) finv[i]=mul(finv[i+1],i+1);
26 }
27 void NTT(int *A,int type,int len){
28     int limit=1,l=0;
29     while(limit<len) limit<<=1,++l;
30     for(int i=0;i<limit;++i)
31     r[i]=(r[i>>1]>>1)|((i&1)<<(l-1));
32     for(int i=0;i<limit;++i)
33     if(i<r[i]) swap(A[i],A[r[i]]);
34     for(int mid=1;mid<limit;mid<<=1){
35         int R=mid<<1,Wn=ksm(3,(P-1)/R);O[0]=1;
36         for(int j=1;j<mid;++j) O[j]=mul(O[j-1],Wn);
37         for(int j=0;j<limit;j+=R){
38             for(int k=0;k<mid;++k){
39                 int x=A[j+k],y=mul(O[k],A[j+k+mid]);
40                 A[j+k]=add(x,y),A[j+k+mid]=dec(x,y);
41             }
42         }
43     }
44     if(type==-1){
45         reverse(A+1,A+limit);
46         for(int i=0,inv=ksm(limit,P-2);i<limit;++i)
47         A[i]=mul(A[i],inv);
48     }
49 }
50 void Inv(int *a,int *b,int len){
51     if(len==1) return (void)(b[0]=ksm(a[0],P-2));
52     Inv(a,b,len>>1);
53     for(int i=0;i<len;++i) F[i]=a[i],G[i]=b[i];
54     NTT(F,1,len<<1),NTT(G,1,len<<1);
55     for(int i=0;i<(len<<1);++i)
56     F[i]=mul(mul(F[i],G[i]),G[i]);
57     NTT(F,-1,len<<1);
58     for(int i=0;i<len;++i) b[i]=(1ll*(b[i]<<1)%P+P-F[i])%P;
59 }
60 int main(){
61 //    freopen("testdata.in","r",stdin);
62     scanf("%d",&n);init();
63     int len=0;for(len=1;len<=(n*2);len<<=1);
64     A[0]=1;
65     for(int i=1;i<=n;++i) A[i]=mul(ksm(2,1ll*i*(i-1)/2),finv[i]);
66     Inv(A,B,len);
67     for(int i=1;i<=n;++i) C[i]=mul(ksm(2,1ll*i*(i-1)/2),finv[i-1]);
68     NTT(B,1,len),NTT(C,1,len);
69     for(int i=0;i<len;++i) B[i]=mul(B[i],C[i]);
70     NTT(B,-1,len);
71     printf("%d\n",mul(B[n],fac[n-1]));
72     return 0;
73 }

 

转载于:https://www.cnblogs.com/bztMinamoto/p/9748182.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/389569.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

支撑阻力指标_使用k表示聚类以创建支撑和阻力

支撑阻力指标Note from Towards Data Science’s editors: While we allow independent authors to publish articles in accordance with our rules and guidelines, we do not endorse each author’s contribution. You should not rely on an author’s works without seek…

高版本(3.9版本)python在anaconda安装opencv库及skimage库(scikit_image库)诸多问题解决办法

今天开始CV方向的学习&#xff0c;然而刚拿到基础代码的时候发现 from skimage.color import rgb2gray 和 import cv2标红&#xff08;这里是因为我已经配置成功了&#xff0c;所以没有红标&#xff09;&#xff0c;我以为是单纯两个库没有下载&#xff0c;去pycharm中下载ski…

python 实现斐波那契数列

# coding:utf8 __author__ blueslidef fun(arg1,arg2,stop):if arg10:print(arg1,arg2)arg3 arg1arg2print(arg3)if arg3<stop:arg3 fun(arg2,arg3,stop)fun(0,1,100)转载于:https://www.cnblogs.com/bluesl/p/9079705.html

单机安装ZooKeeper

2019独角兽企业重金招聘Python工程师标准>>> zookeeper下载、安装以及配置环境变量 本节介绍单机的zookeeper安装&#xff0c;官方下载地址如下&#xff1a; https://archive.apache.org/dist/zookeeper/ 我这里使用的是3.4.11版本&#xff0c;所以找到相应的版本点…

均线交易策略的回测 r_使用r创建交易策略并进行回测

均线交易策略的回测 rR Programming language is an open-source software developed by statisticians and it is widely used among Data Miners for developing Data Analysis. R can be best programmed and developed in RStudio which is an IDE (Integrated Development…

opencv入门课程:彩色图像灰度化和二值化(采用skimage库和opencv库两种方法)

用最简单的办法实现彩色图像灰度化和二值化&#xff1a; 首先采用skimage库&#xff08;skimage库现在在scikit_image库中&#xff09;实现&#xff1a; from skimage.color import rgb2gray import numpy as np import matplotlib.pyplot as plt""" skimage库…

SVN中Revert changes from this revision 跟Revert to this revision

譬如有个文件&#xff0c;有十个版本&#xff0c;假定版本号是1&#xff0c;2&#xff0c;3&#xff0c;4&#xff0c;5&#xff0c;6&#xff0c;7&#xff0c;8&#xff0c;9&#xff0c;10。Revert to this revision&#xff1a; 如果是在版本6这里点击“Revert to this rev…

归 [拾叶集]

归 心归故乡 想象行走在 乡间恬静小路上 让那些疲惫的梦 都随风飞散吧&#xff01; 不去想那些世俗 人来人往 熙熙攘攘 秋日午后 阳光下 细数落叶 来日方长 世上的路 有诗人、浪子 歌咏吟唱 世上的人 在欲望、信仰中 彷徨 彷徨又迷茫 亲爱的人儿 快结束那 无休止的独自流浪 莫要…

instagram分析以预测与安的限量版运动鞋转售价格

Being a sneakerhead is a culture on its own and has its own industry. Every month Biggest brands introduce few select Limited Edition Sneakers which are sold in the markets according to Lottery System called ‘Raffle’. Which have created a new market of i…

opencv:用最邻近插值和双线性插值法实现上采样(放大图像)与下采样(缩小图像)

上采样与下采样 概念&#xff1a; 上采样&#xff1a; 放大图像&#xff08;或称为上采样&#xff08;upsampling&#xff09;或图像插值&#xff08;interpolating&#xff09;&#xff09;的主要目的 是放大原图像,从而可以显示在更高分辨率的显示设备上。 下采样&#xff…

CSS魔法堂:那个被我们忽略的outline

前言 在CSS魔法堂&#xff1a;改变单选框颜色就这么吹毛求疵&#xff01;中我们要模拟原生单选框通过Tab键获得焦点的效果&#xff0c;这里涉及到一个常常被忽略的属性——outline&#xff0c;由于之前对其印象确实有些模糊&#xff0c;于是本文打算对其进行稍微深入的研究^_^ …

初创公司怎么做销售数据分析_初创公司与Faang公司的数据科学

初创公司怎么做销售数据分析介绍 (Introduction) In an increasingly technological world, data scientist and analyst roles have emerged, with responsibilities ranging from optimizing Yelp ratings to filtering Amazon recommendations and designing Facebook featu…

opencv:灰色和彩色图像的像素直方图及直方图均值化的实现与展示

直方图及直方图均值化的理论&#xff0c;实现及展示 直方图&#xff1a; 首先&#xff0c;我们来看看什么是直方图&#xff1a; 理论概念&#xff1a; 在图像处理中&#xff0c;经常用到直方图&#xff0c;如颜色直方图、灰度直方图等。 图像的灰度直方图就描述了图像中灰度分…

mysql.sock问题

Cant connect to local MySQL server through socket /tmp/mysql.sock 上述提示可能在启动mysql时遇到&#xff0c;即在/tmp/mysql.sock位置找不到所需要的mysql.sock文件&#xff0c;主要是由于my.cnf文件里对mysql.sock的位置设定导致。 mysql.sock默认的是在/var/lib/mysql,…

交换机的基本原理配置(一)

1、配置主机名 在全局模式下输入hostname 名字 然后回车即可立马生效&#xff08;在生产环境交换机必须有自己唯一的名字&#xff09; Switch(config)#hostname jsh-sw1jsh-sw1(config)#2、显示系统OS名称及版本信息 特权模式下&#xff0c;输入命令 show version Switch#show …

opencv:卷积涉及的基础概念,Sobel边缘检测代码实现及Same(相同)填充与Vaild(有效)填充

滤波 线性滤波可以说是图像处理最基本的方法&#xff0c;它可以允许我们对图像进行处理&#xff0c;产生很多不同的效果。 卷积 卷积的概念&#xff1a; 卷积的原理与滤波类似。但是卷积却有着细小的差别。 卷积操作也是卷积核与图像对应位置的乘积和。但是卷积操作在做乘…

机器学习股票_使用概率机器学习来改善您的股票交易

机器学习股票Note from Towards Data Science’s editors: While we allow independent authors to publish articles in accordance with our rules and guidelines, we do not endorse each author’s contribution. You should not rely on an author’s works without seek…

BZOJ 2818 Gcd

传送门 题解&#xff1a;设p为素数 &#xff0c;则gcd(x/p,y/p)1也就是说求 x&#xff0f;p以及 y&#xff0f;p的欧拉函数。欧拉筛前缀和就可以解决 #include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <map&…

LeetCode387-字符串中的第一个唯一字符(查找,自定义数据结构)

一开始想用HashMap&#xff0c;把每个字符放进去&#xff0c;然后统计出现的次数。 使用LinkedHashMap的话&#xff0c;键值对的顺序都是不会变的。 LinkedHashMap<Character,Integer> map new LinkedHashMap<>();map.put(i,1111);map.put(j,2222);map.put(k,3333…

r psm倾向性匹配_南瓜香料指标psm如何规划季节性广告

r psm倾向性匹配Retail managers have been facing an extraordinary time with the COVID-19 pandemic. But the typical plans to prepare for seasonal sales will be a new challenge. More seasonal products have been introduced over the years, making August the bes…