数论

快速乘:

ll qmul(ll x,ll y,ll mod)
{
ll ans=0;
while(y)
{
if(y&1) (ans+=x)%=mod;
y>>=1;
(x+=x)%=mod;
}
return ans;
}

快速幂:

ll qpow(ll x,ll y,ll mod)
{
ll ans=1;
while(y)
{
if(y&1) (ans*=x)%=mod;
y>>=1;
(x*=x)%=mod;
}
return ans;
}

Gcd:

ll gcd(ll a,ll b)
{
return b?gcd(b,a%b):a;
}

Exgcd:

void exgcd(ll a,ll b,ll &x,ll &y)
{
if(b) exgcd(b,a%b,y,x),y-=a/b*x;
else x=1,y=0;
}

Lucas:

void init()
{
f[0]=v[0]=1; for(int i=1;i<=mod;i++) f[i]=f[i-1]*i%mod;
v[mod-1]=mod-1; for(int i=mod-2;i;i--) v[i]=v[i+1]*(i+1)%mod;
}
ll lucas(ll a,ll b)
{
if(a<b)
return 0;
if(a<mod&&b<mod)
return 1ll*f[a]*v[b]%mod*v[a-b]%mod;
return 1ll*lucas(a%mod,b%mod)*lucas(a/mod,b/mod)%mod;
}

ExLucas:

ll num(ll x,ll p)
{
ll re=0;
while(x)
{
re+=x/p;
x/=p;
}
return re;
}
ll fac(ll n,ll p,ll pc)
{
if(!n) return 1ll;
ll sum=1ll;
for(int i=1;i<pc;i++) if(i%p) (sum*=i)%=pc;
ll ans=qpow(sum,n/pc,pc);
for(int i=1;i<=n%pc;i++) if(i%p) (ans*=i)%=pc;
return ans*fac(n/p,p,pc)%pc;
}
ll inv(ll n,ll p)
{
ll x,y;
exgcd(n,p,x,y);
((x%=p)+=p)%=p;
return x;
}
ll C(ll x,ll y,ll p,ll pc)
{
if(x<y) return 0ll;
int cnt=num(x,p)-num(y,p)-num(x-y,p);
return fac(x,p,pc)*inv(fac(y,p,pc),pc)%pc*inv(fac(x-y,p,pc),pc)%pc*qpow(p,cnt,pc)%pc;
}

BSGS:

map<ll,ll>MP;
ll bsgs(ll A,ll B,ll C) // x^A \equiv B (mod\ C)
{
ll m=ceil(sqrt(C+0.5));
MP.clear();
ll now=1;
for(int i=1;i<=m;i++)
{
(now*=A)%=C;
if(!MP[now]) MP[now]=i;
}
A=qpow(A,m,C);
now=1;
for(int i=0;i<=m;i++)
{
ll x,y;
exgcd(now,C,x,y);
x=(x*B%C+C)%C;
if(MP.count(x)) return i*m+MP[x];
(now*=A)%=C;
}
return 0;
}

求原根:

ll get_ori(ll p,ll phi)
{
int c=0;
for(int i=2;1ll*i*i<=phi;i++) if(phi%i==0)
{
f[++c]=i; f[++c]=phi/i;
}
for(int g=2;;g++)
{
int j;
for(j=1;j<=c;j++) if(qpow(g,f[j],p)==1) break;
if(j==c+1) return g;
}
return 0;
}

线性基:

for(i=1<<30;i;i>>=1)
{
for(j=1;j<=n;j++) if(!vis[j]&&a[j].v&i) break;
if(j>n) continue;
sum-=a[j].num; vis[j]=true;
for(k=1;k<=n;k++) if(!vis[k]&&a[k].v&i) a[k].v^=a[j].v;
}

图论

tarjan:

void tarjan(int p)
{
st[++top]=p; ins[p]=true;
dep[p]=low[p]=++cnt;
for(int i=head[p];i;i=nxt[i])
{
if(!dep[to[i]) tarjan(to[i]),low[p]=min(low[p],low[to[i]]);
else if(ins[to[i]]) low[p]=min(low[p],dep[to[i]]);
}
if(dep[p]==low[p])
{
Number++;
int t;
do
{
t=st[top--]; ins[t]=false;
f[Number][++f[Number][0]]=t;
}while(t!=p);
}
}

堆优化Dijkstra:

priority_queue<pair<int,int> >q;
void Dijkstra()
{
while(!q.empty()) q.pop();
memset(dis,0x3f,sizeof dis); dis[S]=0; q.push(mp(0,S));
while(!q.empty())
{
while(!q.empty()&&-q.top().first>dis[q.top().second]) q.pop();
if(q.empty()) return;
int x=q.top().second; q.pop();
for(int i=head[x];i;i=nxt[i]) if(dis[to[i]]>dis[x]+val[i])
{
dis[to[i]]=dis[x]+val[i];
q.push(mp(-dis[to[i]],to[i]));
}
}
}

spfa:

queue<int>q;
void spfa()
{
while(!q.empty()) q.pop();
memset(dis,0x3f,sizeof dis); dis[S]=0; q.push(S);
vis[x]=true;
while(!q.empty())
{
int x=q.front(); q.pop(); vis[x]=false;
for(int i=head[x];i;i=nxt[i]) if(dis[to[i]]>dis[x]+val[i])
{
dis[to[i]]=dis[x]+val[i];
if(!vis[to[i]]) q.push(to[i]),vis[to[i]]=true;
}
}
}

倍增lca

void dfs(int p, int fa) {
f[0][p] = fa;
dep[p] = dep[fa] + 1;
for (int i = 1; i <= 20; i ++ )
f[i][p] = f[i-1][f[i-1][p]];
for (int i = head[p]; i; i = nxt[i]) {
if(to[i] != fa) {
dfs(to[i], p);
}
}
} int lca(int x, int y) {
if (dep[x] < dep[y]) swap(x, y);
for (int i = 20; ~i; i -- ) {
if (dep[f[i][x]] >= dep[y]) {
x = f[i][x];
}
}
if (x == y) return x;
for (int i = 20; ~i; i -- ) {
if (f[i][x] != f[i][y]) {
x = f[i][x];
y = f[i][y];
}
}
return f[0][x];
}

数据结构

非旋转Treap

int merge(int x, int y) {
if (!x || !y) return x | y;
pushdown(x); pushdown(y);
if (a[x].key > a[y].key) {
a[x].rs = merge(a[x].rs, y);
pushup(x);
return x;
}
else {
a[y].ls = merge(x, a[y].ls);
pushup(y);
return y;
}
} par split(int x, int k) {
if(!k)
return (par) {0, x};
pushdown(x);
int ls = a[x].ls, rs = a[x].rs;
if (k == a[ls].size) {
a[x].ls = 0;
pushup(x);
return (par) {ls, x};
}
else if (k == a[ls].size + 1) {
a[x].rs = 0;
pushup(x);
return (par) {x, rs};
}
else if (k < a[ls].size) {
par t = split(ls, k);
a[x].ls = t.y;
pushup(x);
return (par) {t.x, x};
}
else {
par t = split(rs, k - a[ls].size - 1);
a[x].rs = t.x;
pushup(x);
return (par) {x, t.y};
}
}

OI模板のpoke流[大型考试复习必备/kl]的更多相关文章

  1. 日语能力考试N2必备训读动词

    日语能力考试N2必备训读动词 ア合う——あう——「自」合一.合到一起.准确味わう——あじわう——「他」品味.品尝預かる——あずかる——「他」照顾.保管.承担預ける——あずける——「他」寄存.处理难以了 ...

  2. Unity3D学习笔记(十三):委托、考试复习

    委托:比较什么时候用委托好   下课案例:不用下课铃 1.ClassManager需要拿到所有教室的引用,课堂管理者应该只负责计时并告知每间教室 2.每间教室应该是由当班老师负责是否需要下课,而课堂管 ...

  3. python期末考试复习

    期末考试复习 补修的python跟着大一一起学,考试肯定不会出难,于是就敲了一些代码,把他们放到博客上,来记录一下 代码都是一段一段的,且python代码不是很多,所以我都写到了一个文件里,作为练习 ...

  4. java高并发系列 - 第15天:JUC中的Semaphore,最简单的限流工具类,必备技能

    这是java高并发系列第15篇文章 Semaphore(信号量)为多线程协作提供了更为强大的控制方法,前面的文章中我们学了synchronized和重入锁ReentrantLock,这2种锁一次都只能 ...

  5. 从零开始的计算机网络基础(图文并茂,1.8w字,面试复习必备)

    前言 在互联网高速发展的今天,我们通过手机,电脑等通讯设备可以很轻松达到未出茅庐便知天下事的境界.每天我们都要访问数不胜数的网站,通过打开浏览器,输入网址两步搞定.当然更为常规的做法是打开浏览器,设置 ...

  6. HDU 1045 - Fire Net - [DFS][二分图最大匹配][匈牙利算法模板][最大流求二分图最大匹配]

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1045 Time Limit: 2000/1000 MS (Java/Others) Mem ...

  7. 【学习笔记】OI模板整理

    CSP2019前夕整理一下模板,顺便供之后使用 0. 非算法内容 0.1. 读入优化 描述: 使用getchar()实现的读入优化. 代码: inline int read() { int x=0; ...

  8. java 期末考试复习

      //Scanner这样写? Scanner input = new Scanner(System.in); //不断获得下一个单词 names[i] = toTitleCase(input.nex ...

  9. mysql考试复习

    基础创建 字段自动编号auto_increment ( 单词补充:increment 定期的加薪; 增量; 增加) 考点 添加自增 alter table [表名] modify [字段(id)] i ...

随机推荐

  1. Confluence 6 分享一个文件

    协同合作和编辑不仅仅是发生在页面中,很多时候你需要与你的项目小组针对文档,报告,图片,表格进行协同操作.不管是针对性的市场计划或者一个完整的项目计划,你可以在 Confluence 中让你的项目小组成 ...

  2. matplotlib中 plt.plot() 函数中**kwargs的参数形式

    plt.plot(x, y, **kwargs) **kwargs的参数大致有如下几种: color: 颜色 linestyle: 线条样式 marker: 标记风格 markerfacecolor: ...

  3. [ML] Gradient Boost

    参考链接: 1. https://medium.com/@cwchang/gradient-boosting-%E7%B0%A1%E4%BB%8B-f3a578ae7205 2. https://zh ...

  4. postgresql-基础-1

    概述 层状关系 网状关系 关系型数据库 关系型数据库 ​ 元祖:代表一行 ​ 属性:代表一列 ​ 主码:唯一确定一个元组的属性组,即主键 ​ 域:属性的取值范围 ​ 分量:元组中的一个属性值,即某一行 ...

  5. smarty中ifelse、foreach以及获取数组中键值名的一个实例

    <{if empty($history)}> <tr> <td colspan="6">Not any records!</td> ...

  6. 朴素贝叶斯文本分类-在《红楼梦》作者鉴别的应用上(python实现)

    朴素贝叶斯算法简单.高效.接下来我们来介绍其如何应用在<红楼梦>作者的鉴别上. 第一步,当然是先得有文本数据,我在网上随便下载了一个txt(当时急着交初稿...).分类肯定是要一个回合一个 ...

  7. [django]update_or_create使用场景

    update_or_create 作用是为了添加数据时防止重复. 先去查询, 如果没有在创建, 如果有则更新. update_or_create用法与密码存储实例 create方法 如果id是None ...

  8. ECMAScript 6 异步编程

    http://www.ruanyifeng.com/blog/2015/04/generator.html

  9. springmvc+mybatis多数据源切换

    前文:之前练习SSM时配置的都是单数据源,现在项目需求多数据源,所以自己查阅了以下资料,在controller中手动切换数据源成功,以下的配置细节. 实际上应该在dao层进行注解的方式切换,使用AOP ...

  10. CA证书申请+IIS配置HTTPS+默认访问https路径

    引用别人博文内容:https://www.cnblogs.com/lichunting/p/9274422.html 一.CA证书申请 (一). 新StartSSL注册帐号 1.    StartSS ...