随笔分类 -  模板

摘要://Stay foolish,stay hungry,stay young,stay simple#include#include#include#include int rd() { int ret=0,f=1;char c; while(c=getch... 阅读全文
posted @ 2018-04-24 18:34 GhostCai 阅读(133) 评论(0) 推荐(0)
摘要:插入x删除x 查询排名为x的数查询x的排名 求x的前驱、后继//Stay foolish,stay hungry,stay young,stay simple#include#include#include#includeusing namespace std;con... 阅读全文
posted @ 2018-04-23 15:37 GhostCai 阅读(138) 评论(0) 推荐(0)
摘要:边角暴力,大块整体,好写的暴力数据结构。区间查询,单点修改。(树状数组的活)//Stay foolish,stay hungry,stay young,stay simple#include#include#include#include#define R regis... 阅读全文
posted @ 2018-04-10 17:32 GhostCai 阅读(116) 评论(0) 推荐(0)
摘要:之前判负环只会SPFA记录访问次数那种naive做法,交上去基本都是TLE的。 原来单纯判负环是由更好的算法的。 记不清在哪里看到过 ,单判负环优先队列比队列快(?!),试了一下,T到飞起。 把BFS改成DFS,直觉上也能明晰地感觉到可以更快地“接近”负环。 UPD:被特殊数据卡成傻子了 阅读全文
posted @ 2018-04-10 14:38 GhostCai 阅读(99) 评论(0) 推荐(0)
摘要:树状数组优化LIS到nlogn,网上找了好多,感觉讲得都不是很明白,正好自己复习整理一下。基本的DP方程 f[i]=max(f[i],f[j]+1) (j#include using namespace std;const int MAXN=20000;int a[M... 阅读全文
posted @ 2018-03-28 13:35 GhostCai 阅读(121) 评论(0) 推荐(0)
摘要:求回文子串的长度,mp[i]保存以i为中心的回文子串的半径(长度一半) 利用mx和id,避免重复暴力求解,达到O(n)的时间复杂度 预先填充一些无关紧要的字符 #include<iostream> #include<cstring> #include<cstdio> using namespace 阅读全文
posted @ 2018-03-14 00:34 GhostCai 阅读(111) 评论(0) 推荐(0)
摘要:fail 失配数组 fail[i]表示以i为结尾的非前缀子串与s的前缀的最大匹配长度 在拼接两字符串后,求fail数组的同时就能求出匹配位置(fail[i]==len_origin的i-2*len_origin) #include<iostream> #include<cstdio> #includ 阅读全文
posted @ 2018-03-14 00:34 GhostCai 阅读(116) 评论(0) 推荐(0)
摘要:二分图匹配,寻找增广路。 洛谷这个模板题真的毒瘤。#include#include#include#define R registerusing namespace std;const int MAXN=1000005;inline int read_d(){ ... 阅读全文
posted @ 2018-03-06 22:31 GhostCai 阅读(117) 评论(0) 推荐(0)
摘要:ST表,O(nlogn)预处理,O(1)求区间最值 线段树也能解决,而且支持动态修改,但是对于不修改的序列,线段树查询logn,要慢4用f[i][j]表示一个区间[i,2^j] 利用倍增 f[i][j]=____(f[i][j-1],f[1+2^(j-1)][j-1]... 阅读全文
posted @ 2018-02-21 21:30 GhostCai 阅读(100) 评论(0) 推荐(0)
摘要:最规整的版本。 玩火需谨慎(&)//Writer:GhostCai && His Yellow Duck#includeusing namespace std;const long long MAXN=200005;long long n,m;long long a[... 阅读全文
posted @ 2018-02-09 21:28 GhostCai 阅读(129) 评论(0) 推荐(0)
摘要:用lowbit二分构造tree,巧妙 区间更改,就是[x,n]加w,[y+1,n]减w。 Tree数组有前缀和的思想,query(x)操作就是求[1,x]的前缀和,标准的updata(x,w)是单点操作,x点+w。 //Writer:GhostCai && His Yellow Duck #incl 阅读全文
posted @ 2018-01-29 00:27 GhostCai 阅读(94) 评论(0) 推荐(0)
摘要:离线tarjan(dfs) 链式前向星从1开始存,免了赋-1初值,方便异或运算,好处多多。 并查集fa数组的初始化可以写入dfs中顺便执行,少一个大循环。数组要开大,不然会报WA,可能它在乱搜吧。//Writer:GhostCai && His Yellow Duck... 阅读全文
posted @ 2018-01-27 22:11 GhostCai 阅读(124) 评论(0) 推荐(0)
摘要:tarjan (讲道理信息传递就是这样的?) 阅读全文
posted @ 2018-01-12 18:10 GhostCai 阅读(112) 评论(0) 推荐(0)
摘要:[证明] 待补充//Writer:GhostCai && His Yellow Duck#includeusing namespace std;int exgcd(int a,int b,int &x,int &y){ if(b==0){ x=1,... 阅读全文
posted @ 2018-01-12 17:53 GhostCai 阅读(97) 评论(0) 推荐(0)
摘要:输出一条路径#include#include#include#define MAXN 200000using namespace std;int m,n; int in[MAXN];struct Edge{ int next,to;}e[MAXN];int ec... 阅读全文
posted @ 2018-01-12 17:49 GhostCai 阅读(101) 评论(0) 推荐(0)
摘要:别忘了路径压缩。#include#include#include#define MAXN 300000using namespace std;int n,m;int fa[MAXN];int fnd(int x){ if(x!=fa[x]) return fa[... 阅读全文
posted @ 2018-01-12 17:45 GhostCai 阅读(91) 评论(0) 推荐(0)
摘要:克鲁斯卡尔 很好的一个处理方式是 间接排序也就是通过在另一个数组排序号,保留原始数据。#include#include#include#define MAXN 200000using namespace std;int m,n,ans;int u[MAXN],v[MA... 阅读全文
posted @ 2018-01-12 17:42 GhostCai 阅读(111) 评论(0) 推荐(0)
摘要:二进制处理int poww(int a,int b){ int ans=1,base=a; while(b!=0){ if(b&1!=0) ans*=base; base*=base; b>>=1... 阅读全文
posted @ 2018-01-04 01:28 GhostCai 阅读(103) 评论(0) 推荐(0)
摘要:欧拉筛,O(线性) 考虑三个地方,即可筛出积性函数f(x): 1.x为素数 2.p不整除于x 3.p整除于x(break) [x] 唯一分解定理 有素数表复杂度在lnn,没有则sqrt(n) [x] 威尔逊定理 [x] 费马小定理 设p为素数,a为正整数,若GCD(p,a)==1,则a^(p-1)≡ 阅读全文
posted @ 2018-01-04 01:16 GhostCai 阅读(132) 评论(3) 推荐(0)
摘要:单源最短路 阅读全文
posted @ 2017-12-20 23:38 GhostCai 阅读(118) 评论(0) 推荐(0)