
算法模板
lixuwei2333
这个作者很懒,什么都没留下…
展开
-
树上莫队模板
题目链接:https://vjudge.net/problem/SPOJ-COT2教学博客:https://www.cnblogs.com/zwfymqz/p/9223425.html题目大意:查询链上点权不同数的个数。ps:如果是边权的话,那么u,v对应的区间是[st[u]+1,st[v]],无需lca。#include <bits/stdc++.h>#defin...原创 2019-10-25 14:25:02 · 229 阅读 · 0 评论 -
RMQ求LCA
题目链接:https://www.luogu.org/problem/P3379学习链接:https://blog.youkuaiyun.com/Diogenes_/article/details/81412316预处理时间复杂度O(NlogN)查询时间复杂度O(1)#include <bits/stdc++.h>#define rep(i, a, b) for(int ...原创 2019-10-23 16:49:05 · 287 阅读 · 0 评论 -
斜率优化dp
推荐学习博客:https://www.cnblogs.com/orzzz/p/7885971.html题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3507#include <bits/stdc++.h>#define rep(i, a, b) for(int i = (a); i <= (b); i++)#defin...原创 2019-10-18 21:20:29 · 137 阅读 · 0 评论 -
置换群定理
https://blog.youkuaiyun.com/liangzhaoyang1/article/details/72639208转载 2019-02-23 18:13:09 · 569 阅读 · 0 评论 -
查询区间内第一个大于x的数
#include <bits/stdc++.h>#define ls (o<<1)#define rs (o<<1|1)#define mid (l+r>>1)using namespace std;const int N = 2e5+100;int tree[4*N];void build(int o,int l,int r) {...原创 2019-02-21 10:23:10 · 1942 阅读 · 0 评论 -
回文树模板【求不同回文字串个数】
#include <bits/stdc++.h>using namespace std;const int MAX = 1e5+100;const int ALP = 26;struct Palindromic_Tree { int son[MAX][ALP]; //转移边 int fail[MAX]; //fail 指针 int cnt[MAX]; ...原创 2019-02-18 14:40:06 · 556 阅读 · 0 评论 -
最小费用最大流
// luogu-judger-enable-o2#include <bits/stdc++.h>using namespace std;const int N = 1e4+100;int n,m,S,T,tot;int head[N];struct node{ int v,cap,cost,nxt;}edge[int(2e5+100)];int dis[N...原创 2019-02-22 17:32:22 · 860 阅读 · 0 评论 -
矩阵快速幂【临时凑数待修改】
#include <bits/stdc++.h>#define ll long longusing namespace std;const ll mod = 2147493647;ll t[7][7]={ {1,2,1,4,6,4,1}, {1,0,0,0,0,0,0}, {0,0,1,4,6,4,1}, {0,...原创 2019-02-22 16:42:23 · 145 阅读 · 0 评论 -
RMQ
const int MAX = 1e6+100;int dp[MAX][25];void RMQ(){ for(int i = 1; i <= n; i++) dp[i][0] = s[i]; for(int i = 1; i < 25; i++) for(int j = 1; j + (1 << i) - 1 <= n; j++...原创 2019-02-17 10:28:02 · 134 阅读 · 0 评论 -
权值线段树
动态开点题目链接#include <bits/stdc++.h>#define ll long long#define mid (l+r>>1)using namespace std;const int N = 1e5+100;const ll inf = 1e10+10;ll L,R;int n, tot;int rt, ls[N*40], rs...原创 2019-02-10 22:30:22 · 279 阅读 · 0 评论 -
后缀数组模板【求不同字串的个数】
ldq链接:https://li-fish.github.io/2018/05/03/cjqx5558400d04kc2v3xgtu1d/sa[i]表示排名为i的后缀位置rank[i]表示以suf(i)的排名height[i]表示suf(sa[i])和suf(sa[i-1])的最长公共前缀ch下标从0开始,n是ch的长度#include <bits/stdc++.h...原创 2019-02-16 15:05:18 · 219 阅读 · 0 评论 -
扩展kmp模板
#include <bits/stdc++.h>using namespace std;const int N = 1e6+100;int sum[N];const int mod = 1e9+7;char s1[N], s2[N];int nxt[N], extend[N];void exkmp(char s1[],char s2[],int next1[],in...原创 2019-02-16 09:14:59 · 425 阅读 · 0 评论 -
读入挂
调用直接使用read(读整数)或read_ss(读字符串)即可。namespace FastIO{ #define BUF_SIZE 100000 bool IOerror=0; inline char nc(){ static char buf[BUF_SIZE], *p1=buf+BUF_SIZE, *pend=buf+BUF_SIZE; ...转载 2019-02-09 10:46:19 · 276 阅读 · 0 评论 -
cdq分治求三维偏序
这题最恶心的地方在于去重题目链接#include <bits/stdc++.h>#define mid (l+r>>1)using namespace std;const int N=1e5+100;struct node{ int a,b,c,id,num; bool operator <(node x) const { //需要保...原创 2019-02-07 22:40:27 · 306 阅读 · 1 评论 -
FFT/NTT模板
模板题,多项式乘法题目链接 0 1 2 a[0] - a[2] X a b c b[0] - b[2]________________ 0c 1c 2c 0b 1b 2...原创 2019-01-21 19:17:37 · 243 阅读 · 0 评论 -
splay模板
https://li-fish.github.io/categories/ACM/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/Splay/原创 2019-01-21 19:09:06 · 189 阅读 · 1 评论 -
数据离散化
#include <bits/stdc++.h>#define ll long longusing namespace std;const int N = 110000;int s[N];int main() { ios::sync_with_stdio(0); int n; cin>>n; vector<int> k...原创 2019-01-20 14:33:38 · 168 阅读 · 0 评论 -
Anti-SG 贾志豪定理
原创 2019-03-13 21:06:51 · 378 阅读 · 0 评论 -
tarjan模板
照抄kuangbin模板,感觉很不错。题目链接:https://vjudge.net/problem/ZOJ-3795##include <bits/stdc++.h>#define ll long long#define mp make_pair#define pb push_back#define rep(i,a,b) for(int i = (a); i...原创 2019-03-15 10:39:36 · 331 阅读 · 0 评论 -
A+B>=K(?????)
A 的取值范围[l1,r1], B 的取值范围[l2,r2]。问有多少种取值方案满足A+B>=K。时间复杂度O(1)用对拍稍微验证了一下代码的正确性ll nb(ll l1,ll r1,ll l2,ll r2,ll k) { ll ans=0; ll lll=k-r1; ll rrr=k-l1; if(lll>r2)return an...原创 2019-08-22 08:34:16 · 451 阅读 · 0 评论 -
Floyd求最小环模板
int val[maxn + 1][maxn + 1]; // 原图的邻接矩阵inline int floyd(const int &n) { static int dis[maxn + 1][maxn + 1]; // 最短路矩阵 for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) ...原创 2019-08-19 08:48:50 · 205 阅读 · 0 评论 -
树形背包模板
题目大意:给一个N个点的森林,从中选取恰好M个点,当你选择一个点时,必须选择他的父亲节点。问能获得的最大点权和是多少。数据范围见题目链接:https://www.luogu.org/problem/P2014#include <bits/stdc++.h>#define rep(i, a, b) for(int i = (a); i <= (b); i++)#d...原创 2019-07-26 11:02:43 · 289 阅读 · 0 评论 -
高斯消元模板【double】
题目链接:https://www.luogu.org/problem/P3389#include <bits/stdc++.h>#define rep(i, a, b) for(int i = (a); i <= (b); i++)#define per(i, a, b) for(int i = (a); i >= (b); i--)#define pb pus...原创 2019-07-31 10:09:32 · 310 阅读 · 0 评论 -
莫队模板
//莫队模板题//区间内不同数的个数:https://vjudge.net/problem/SPOJ-DQUERY#include<bits/stdc++.h>using namespace std;const int M = 1e6 + 10;int s[M],num[M],vis[M],block,ans,m;struct node{ int l,r,id;...原创 2019-07-24 13:50:59 · 205 阅读 · 0 评论 -
斯坦纳树模板
给出n个点,然后给出m条双向边,边有边权。再给出一个大小为k的点集,求使得点集联通的最小花费。时间复杂度O(n*3^k + cE*2^k),其中c为spfa常数。#include <bits/stdc++.h>#define rep(i, a, b) for(int i = (a); i <= (b); i++)using namespace std;con...原创 2019-07-03 20:11:58 · 489 阅读 · 0 评论 -
拉格朗日插值模板
https://paste.ubuntu.com/p/fpZmyBXYpY/原创 2019-06-03 16:26:18 · 351 阅读 · 0 评论 -
虚树模板
copy from:https://li-fish.github.io/2018/09/04/cjtk4cs8l008s04c2emfcercy/题目链接:https://www.luogu.org/problemnew/show/P2495题目大意:给一颗树,根为1,边有边权。m次询问,每次询问给出k个关键点,割边使得根与任意关键点不连通,求最小花费。#include <bi...原创 2019-05-31 10:43:36 · 210 阅读 · 0 评论 -
点分治入门
题目链接:https://codeforces.com/contest/161/problem/D题目大意,求树上路径长度为K的路径条数。 (k<=500)#include <bits/stdc++.h>#include <ext/pb_ds/assoc_container.hpp>#include <ext/pb_ds/hash_policy.h...原创 2019-05-22 21:30:25 · 129 阅读 · 0 评论 -
可持久化并查集
n个集合 m个操作操作: 1 a b合并a,b所在集合 2 k回到第k次操作之后的状态(查询算作操作) 3 a b询问a,b是否属于同一集合,是则输出1否则输出0 1≤n≤10^5,1≤m≤2×10^5 做法一:rope,但是会MLE。空间复杂度O(玄学)#include <bits/stdc++.h>#define r...原创 2019-04-22 20:09:02 · 177 阅读 · 0 评论 -
整除分块、迪利克雷卷积、莫比乌斯反演、积性函数线性筛
基础教学博客:https://www.cnblogs.com/zhouzhendong/p/8627380.html可能退役前都学不完的VFK(跳骚国王)blog :http://vfleaking.blog.uoj.ac/slide/87#/N以内质数的个数:N/logNN的因子个数:sqrt(N)N的质因子个数:log10(N) (误)整除分块for(int l=1...转载 2019-04-13 11:03:35 · 326 阅读 · 0 评论 -
bitset
https://www.cnblogs.com/magisk/p/8809922.html原创 2019-04-03 17:16:33 · 93 阅读 · 0 评论 -
洛谷-普通平衡树 【pbds】
题目链接:https://www.luogu.org/problemnew/show/P3369使用教程:https://baijiahao.baidu.com/s?id=1610302746201562113&wfr=spider&for=pctree差不多可以当作强化版set来用吧。/// int类型/// null_type为映射类型, 低版本g++为 null...原创 2019-04-15 21:14:17 · 1578 阅读 · 5 评论 -
数列分块模板
操作1:区间开方操作2:区间求和#include <bits/stdc++.h>#define ll long long#define mp make_pair#define pb push_back#define rep(i,a,b) for(ll i = (a); i <= (b); i++)#define per(i,a,b) for(ll i = (a...原创 2019-03-15 20:11:19 · 149 阅读 · 0 评论 -
AC自动机
https://vjudge.net/problem/HDU-2222#include <bits/stdc++.h>using namespace std;const int MAX = 250001;const int N = 1000010;const int SIGMA_SIZE = 26;int ch[MAX][SIGMA_SIZE];int va...原创 2019-01-25 08:19:59 · 126 阅读 · 0 评论 -
树链刨分模板
单点修改查询链上点权最大值 下面线段树的实现有很多冗余的东西,主要看两个dfs。#include<bits/stdc++.h>#define lson (o<<1)#define rson (o<<1|1)#define mid (l+r>>1)#define ll long long#define N 51000using...原创 2019-01-18 10:02:29 · 193 阅读 · 0 评论 -
POJ - 1426 Find The Multiple(数位dp,输出符合要求的某个结果)
题目链接 题目大意:找一个大于等于N的数,使这个数每一位只有0和1,且能被N整除。Sample Input 2 6 19 0Sample Output 10 100100100100100100 111111111111111111数位dp记录不可行路径#include <iostream>#include <...原创 2018-07-28 11:26:19 · 185 阅读 · 0 评论 -
网络流最大流模板
#include &amp;amp;amp;lt;bits/stdc++.h&amp;amp;amp;gt;using namespace std;const int N = 1e4+100;int n,m,s,t,tot;int head[N];struct node{ int nxt,cap,to;}edge[int(2e5+100)];int cur[N],deep[N];void ae(int u,int v,...原创 2018-07-24 09:57:11 · 304 阅读 · 0 评论 -
线段树模板
查询区间和 区间修改,区间查询#include&amp;lt;bits/stdc++.h&amp;gt;#define LL long long#define N 100000using namespace std;int i,n,m,h,t;LL data;struct node{ LL data,lazy,len;}tree[4*N];void build(int root,...原创 2018-06-06 21:15:49 · 166 阅读 · 0 评论 -
堆优化的Dijkstra(cmp函数的写法)
#include &lt;bits/stdc++.h&gt;using namespace std;const int N=11000;int dis[11000];vector&lt;int&gt;len[N];vector&lt;int&gt;edge[N];struct cmp{ bool operator()(int x,int y){ return ...原创 2018-06-04 20:43:07 · 310 阅读 · 0 评论 -
不要62(数位dp)
不要62LL dfs(int pos,int prev,bool limit){ int i; if(pos==0) return 1; if(!limit&&dp[pos][prev]!=-1) return dp[pos][prev]; int up; LL ans=0; up = limit?a[pos]:9; ...原创 2018-05-14 20:29:35 · 136 阅读 · 0 评论