摘要:
//主席树 权值线段树+可持久化 //权值线段树:在此处指各个数字在某个区间内出现的次数 //那么第一棵权值线段树会记录[1,1]的数字出现次数 //第n棵权值线段树会记录[1,n]的数字出现次数 //例:数列为110001 //第一棵权值线段树记录为tree1[0]=0 tree1[1]=1 //第二棵权值线段树记录为tree2[0]=0 tree2[1]=2 //第六棵权值线段树记录... 阅读全文
posted @ 2018-07-08 18:44
radishえらい
阅读(302)
评论(0)
推荐(0)
摘要:
//主席树 可持久化线段树 //对于每次更新新建根节点 //将涉及到改变的节点全部新建,未涉及改变的节点全部用以前的节点代替 //可大大节省空间 #include #include #include #include #include #include using namespace std; int n,m,cnt,root[1000001],a[1000001]; struct uio{... 阅读全文
posted @ 2018-07-08 18:43
radishえらい
阅读(170)
评论(0)
推荐(0)
摘要:
注:由于本代码注释默认各位都已理解了fhqTreap的基本操作,因此本代码对于例如split,merge等基本 函数的注释未曾给出。若您看不懂本代码,您可以先移步这里。 阅读全文
posted @ 2018-07-08 18:42
radishえらい
阅读(1407)
评论(1)
推荐(0)
摘要:
//平衡树 替罪羊树 //不进行旋转 当左右子树重量相差过大(通常以3:1为界)就把树拍扁重构 //重构即以最中心节点为根节点 二分建树 #include #include #include #include #include #include #define lim 0.75//拍扁重构的标准 using namespace std; int n,root,size,cnt; int g... 阅读全文
posted @ 2018-07-08 18:42
radishえらい
阅读(163)
评论(0)
推荐(0)
摘要:
//Treap fhq版(不旋转) //所有操作依靠split()(分离)和merge()(合并)完成 //可支持区间操作和可持久化 比普通Treap更通用 //所有Treap中序遍历均为递增序列 #include #include #include #include #include #include #include using namespace std; int n,cnt,si... 阅读全文
posted @ 2018-07-08 18:41
radishえらい
阅读(871)
评论(0)
推荐(0)
摘要:
//平衡树 Treap //维护一个堆使得随机权值小(大)的数始终在上方 //使用随机权值目的:防止出题人卡 #include #include #include #include #include #include using namespace std; struct uio{ int l,r,siz,num,rd,tim;//左儿子,右儿子,子树大小+自己大小,点值,随机权值,出... 阅读全文
posted @ 2018-07-08 18:40
radishえらい
阅读(199)
评论(0)
推荐(0)
摘要:
//平衡树 Splay //利用双旋 防止树退化成链 //时间比Treap慢log(n) #include #include #include #include #include #include using namespace std; struct uio{ int son[2],fa,num,tim,siz;//左右儿子,父节点,点值,出现次数,子树大小+自己大小 }spl[10... 阅读全文
posted @ 2018-07-08 18:40
radishえらい
阅读(147)
评论(0)
推荐(0)
摘要:
//线段树 //每个节点代表一段区间 除叶节点外均有左右子节点 //左子节点:[L,(L+R)/2] 右子节点:[(L+R)/2+1,R] 叶节点长度为1 #include #include #include #include #include #include using namespace std; int n,a[1001],cnt=1;//cnt树点标号 struct uio... 阅读全文
posted @ 2018-07-08 18:29
radishえらい
阅读(143)
评论(0)
推荐(0)
摘要:
#include #include #include #include #include #include #define INF 99999999 using namespace std; int n,m,k,cnt; int len[500001],head[500001],jdg[500001],que[500001]; struct uio{ int to,next,wei; ... 阅读全文
posted @ 2018-07-08 17:32
radishえらい
阅读(106)
评论(0)
推荐(0)
摘要:
//trie树 //字典树 查找字符串 #include #include #include #include #include #include using namespace std; struct uio{ int son[27],val;//son[a]保存是否存在编号为a的子节点是否存在 val保存以该节点为尾节点的字符串权值 }trie[1001]; int n,cnt;... 阅读全文
posted @ 2018-07-08 17:32
radishえらい
阅读(124)
评论(0)
推荐(0)
摘要:
#include #include #include #include #include #include using namespace std; struct uio{ int from,to,que; }edge[1001]; int road[1001],n,m; int main() { cin>>n>>m; for(int i=1;i>edge[i].from... 阅读全文
posted @ 2018-07-08 17:31
radishえらい
阅读(99)
评论(0)
推荐(0)
摘要:
#include #include #include #include #include #include using namespace std; int n,m,INF=99999999; int e[1001][1001],road[1001],jdg[1001]; int main() { cin>>n>>m; for(int i=1;i>a>>b>>c; ... 阅读全文
posted @ 2018-07-08 17:30
radishえらい
阅读(93)
评论(0)
推荐(0)
摘要:
#include #include #include #include #include #include #include #include using namespace std; int n,m,s,t,cnt,head[100001]; int dis[100001],vis[100001]; struct uio{ int to,nxt,wei; }edge[10000001]... 阅读全文
posted @ 2018-07-08 17:30
radishえらい
阅读(112)
评论(0)
推荐(0)
摘要:
#include #include #include #include #include #include using namespace std; int m,n,ans,a[501],b[501],dp[501][501],pre[501][501],lcis[501]; int main() { scanf("%d",&n); for(int i=1;ib[j]&&dp[i... 阅读全文
posted @ 2018-07-08 17:29
radishえらい
阅读(149)
评论(0)
推荐(0)
摘要:
#include #include #include #include #include #include using namespace std; int n,m,jdg[5001],cnt,ans; struct uio{ int from,to,que; }road[200001]; int find(int x) { if(x==jdg[x]) retur... 阅读全文
posted @ 2018-07-08 17:28
radishえらい
阅读(116)
评论(0)
推荐(0)
摘要:
//dinic 最大流 //head[x]从0开始记 这样便于找反向边 异或即可 //当前弧优化 #include #include #include #include #include #include #include #define ll long long #define ull unsigned long long #define INF 0x3f3f3f3f using nam... 阅读全文
posted @ 2018-07-08 17:27
radishえらい
阅读(124)
评论(0)
推荐(0)
摘要:
//EK 最小费用最大流 //只需将最大流中的bfs改为SPFA即可 //注意 若要跑最大费用最大流 只需在加边时将正反边费用分别取反 //跑完最小费用最大流后把mincost取反即可 #include #include #include #include #include #include #include #define ll long long #define ull unsigned... 阅读全文
posted @ 2018-07-08 17:27
radishえらい
阅读(150)
评论(0)
推荐(0)
摘要:
//树链剖分 //将最短路上的区间分成若干条链 使得每一条链上的操作都能用线段树解决 //分轻重 重儿子为某节点的儿子中儿子最多的子节点 重儿子之间的边为重边 重边相连即为重链 #include #include #include #include #include #include using namespace std; int n,m,root,MOD,dot[100001],dot... 阅读全文
posted @ 2018-07-08 17:25
radishえらい
阅读(109)
评论(0)
推荐(0)
摘要:
//树状数组 //支持给某位置增加常数与查询前缀和 #include #include #include #include #include #include using namespace std; int n,a[1001],tree[1001];//tree树状数组 int lowbit(int x)//表示2^k k是二进制数x的末尾0个数 { return x&(-x); ... 阅读全文
posted @ 2018-07-08 17:25
radishえらい
阅读(99)
评论(0)
推荐(0)
摘要:
//双重Hash 可保证不重复 //空间较大 时间较慢 不易被卡 #include #include #include #include #include #include #define MOD1 233333339 #define MOD2 233333393 #define MOD3 233333939 #define base 233 #define ull unsigned long... 阅读全文
posted @ 2018-07-08 17:25
radishえらい
阅读(173)
评论(0)
推荐(0)
摘要:
#include #include #include #include #include #include #define ll long long using namespace std; ll n,jdg[1000001],prime[1000001],phi[1000001],cnt,ans; int main() { scanf("%lld",&n); phi[1]=1;... 阅读全文
posted @ 2018-07-08 17:24
radishえらい
阅读(98)
评论(0)
推荐(0)
摘要:
#include #include #include #include #include #include using namespace std; int n,m,jdg[10000001],prime[10000001],cnt; int main() { cin>>n>>m; jdg[1]=1; for(int i=2;in) bre... 阅读全文
posted @ 2018-07-08 17:24
radishえらい
阅读(94)
评论(0)
推荐(0)
摘要:
#include #include #include #include #include #include using namespace std; int jdg[10000001],n,m; int main() { cin>>n>>m; jdg[1]=1; for(int i=2;i>a; if(jdg[a]==0) cout... 阅读全文
posted @ 2018-07-08 17:23
radishえらい
阅读(107)
评论(0)
推荐(0)
摘要:
//三分 //劣于二分 但可以解决某些二分无法解决的问题 //求函数顶点可用 #include #include #include #include #include #include #define eps 1e-7 using namespace std; int n; double l,r,a[14]; double get(double x) { double num=0; ... 阅读全文
posted @ 2018-07-08 17:22
radishえらい
阅读(310)
评论(0)
推荐(0)
摘要:
//卢卡斯定理 可求在模p意义下的组合数 //公式:C(x,y)=C(x/p,y/p)*C(x%p,y%p) (mod p) #include #include #include #include #include #include #define ll long long #define ull unsigned long long #define INF 0x3f3f3f3f ll T,... 阅读全文
posted @ 2018-07-08 17:21
radishえらい
阅读(181)
评论(0)
推荐(0)
摘要:
//KMP //求匹配子串 #include #include #include #include #include #include using namespace std; int lena,lenb,next[1000001];//next[a]存放在a长度的子字符串中前后缀相同最长的长度 char a[1000001],b[1000001]; void getnxt() { ... 阅读全文
posted @ 2018-07-08 17:21
radishえらい
阅读(106)
评论(0)
推荐(0)
摘要:
#include #include #include #include #include #include using namespace std; long long a,b,MOD,ans=1; int main() { scanf("%lld%lld%lld",&a,&b,&MOD); while(b) { if(b&1) a... 阅读全文
posted @ 2018-07-08 17:17
radishえらい
阅读(105)
评论(0)
推荐(0)
摘要:
//矩阵快速幂 //满足c[x][y]=∑(i=1,i #include #include #include #include #include #define ll long long #define MOD 1000000007 using namespace std; ll n,k; struct uio{ ll squ[101][101],n,m; }mat; uio mult... 阅读全文
posted @ 2018-07-08 17:17
radishえらい
阅读(123)
评论(0)
推荐(0)
摘要:
//Manacher //可求最长回文子串长度 #include #include #include #include #include #include #define ma 11000005 using namespace std; int n,ans,length[mamxr) { mxr=length[i]+i; ... 阅读全文
posted @ 2018-07-08 17:16
radishえらい
阅读(153)
评论(0)
推荐(0)
摘要:
//高斯消元 //可解n元一次方程 //消成左上到右下的对角线 精度相对于上三角损失更大 #include #include #include #include #include #include #define eps 1e-7 using namespace std; int n; double coe[101][101],num[101]; int main() { scan... 阅读全文
posted @ 2018-07-08 17:15
radishえらい
阅读(143)
评论(0)
推荐(0)
摘要:
#include #include #include #include #include #include #include #include using namespace std; const int MAX_L=2005; //最大长度,可以修改 class bign { public: int len, s[MAX_L];//数的长度,记录数组 //构造函数 big... 阅读全文
posted @ 2018-07-08 17:13
radishえらい
阅读(122)
评论(0)
推荐(0)
摘要:
#include #include #include #include #include #include using namespace std; int n,m,k,ans,cnt,head[1001],vis[1001],match[1001]; struct uio{ int next,to; }edge[1000001]; int add(int x,int y) { ... 阅读全文
posted @ 2018-07-08 17:11
radishえらい
阅读(135)
评论(0)
推荐(0)
摘要:
//二叉查找树 //特点:每个点左子树上的点都小于该点,右子树上的点都大于该点 //没有取值相同的点 任意点的左右子树均为二叉查找树 //中序遍历严格单调递增 #include #include #include #include #include #include using namespace std; struct uio{ int num,cnt,dfs;//num取值 ... 阅读全文
posted @ 2018-07-08 17:10
radishえらい
阅读(119)
评论(0)
推荐(0)
摘要:
//单调队列 //队列元素递增或递减 元素最多进队出队各一次 //应用:复杂度为o(n^2)的动态规划 可求最大最小值 #include #include #include #include #include #include using namespace std; int n,m,a[1000001]; struct uio{ int minum,micnt; }mi[1000... 阅读全文
posted @ 2018-07-08 17:09
radishえらい
阅读(133)
评论(0)
推荐(0)
摘要:
//大步小步算法 BSGS //对于式子 x^y=z mod p 已知x,z和p可求y //由于费马小定理 y的取值范围为[0,p-1] //利用分块思想 将y分为a*m+b m=sqrt(p-1) //其中x^b预处理存在Hash中 枚举a即可 #include #include #include #include #include #include #include #define... 阅读全文
posted @ 2018-07-08 17:08
radishえらい
阅读(248)
评论(0)
推荐(0)
摘要:
#include #include #include #include #include #include #define ll long long using namespace std; ll n,p; void exgcd(ll a,ll b,ll &x,ll &y) { if(!b) { x=1;y=0; return; } ... 阅读全文
posted @ 2018-07-08 17:00
radishえらい
阅读(165)
评论(0)
推荐(0)
摘要:
#include #include #include #define maxn 105 #define INF 0x3f3f3f3f using namespace std; int head[maxn],maxcost[maxn][maxn],map[maxn][maxn]; bool used[maxn][maxn];//m int n,m,t,cnt,x,y,z,vis[maxn],d... 阅读全文
posted @ 2018-07-08 17:00
radishえらい
阅读(105)
评论(0)
推荐(0)
摘要:
#include #include #include #include #include #include #define ll long long using namespace std; ll n,p,a[3000001]; int main() { scanf("%lld%lld",&n,&p); a[1]=1; printf("%lld\n",a[1]); ... 阅读全文
posted @ 2018-07-08 16:59
radishえらい
阅读(146)
评论(0)
推荐(0)
摘要:
#include #include #include #include #include #include #define ll long long using namespace std; ll n,p; int main() { scanf("%lld%lld",&n,&p); ll a=n,ans=1,b=p-2; while(b) { if... 阅读全文
posted @ 2018-07-08 16:59
radishえらい
阅读(146)
评论(0)
推荐(0)
摘要:
//带偏移量的并查集≈并查集补集 //维护各点到父节点的距离 可用来分类 #include #include #include #include #include #include using namespace std; int n,f[1001],d[1001]; int find(int x) { if(x==f[x]) return x; d[x]+=... 阅读全文
posted @ 2018-07-08 16:58
radishえらい
阅读(291)
评论(0)
推荐(0)
摘要:
//Tarjan 强连通分量 //dfn[]时间戳 low[]经过一条非回溯边可到达的时间戳最小节点 即其能回溯到的最小节点 #include #include #include #include #include #include using namespace std; int n,m,cnt,head[10001]; int t,sta[10001],vis[10001]; int d... 阅读全文
posted @ 2018-07-08 16:55
radishえらい
阅读(132)
评论(0)
推荐(0)
摘要:
//tarjan 缩点 //把强连通分量染成同样的颜色 用数组记录一下强连通分量内所有点权和 #include #include #include #include #include #include using namespace std; int n,m,cnt,ans,head[10001]; int t,sta[10001],vis[10001]; int dot,dfn[10001... 阅读全文
posted @ 2018-07-08 16:55
radishえらい
阅读(160)
评论(0)
推荐(0)
摘要:
//Tarjan 割边 //当dfn[u] #include #include #include #include #include using namespace std; int n,m,cnt,ans,head[10001]; int dot,dfn[10001],low[10001]; int cut[200001]; struct uio{ int from,to,next,... 阅读全文
posted @ 2018-07-08 16:54
radishえらい
阅读(153)
评论(0)
推荐(0)
摘要:
//Tarjan 割点 //根节点满足子节点个数>=2即为割点 //非根节点满足dfn[u] #include #include #include #include #include using namespace std; int n,m,cnt,ans,head[100001]; int dot,dfn[100001],low[100001]; int cut[100001]; stru... 阅读全文
posted @ 2018-07-08 16:54
radishえらい
阅读(287)
评论(0)
推荐(0)
摘要:
//ST表 //计算RMQ 即区间最值 //思想:区间dp+倍增 //注:将代码内所有max改成min即可求最小值 #include #include #include #include #include #include using namespace std; int n,m,l,r,a[100001]; int Pow[31],Log[100001];//Pow[i]表示2的i次幂 L... 阅读全文
posted @ 2018-07-08 16:53
radishえらい
阅读(122)
评论(0)
推荐(0)
摘要:
//LCA //树链剖分 在线 #include #include #include #include #include #include using namespace std; int n,m,root,cnt,head[500001]; int hvyson[500001],fa[500001],siz[500001],dep[500001],top[500001]; struct ui... 阅读全文
posted @ 2018-07-08 16:52
radishえらい
阅读(108)
评论(0)
推荐(0)
摘要:
//LCA //倍增 在线 #include #include #include #include #include #include #define maxn 500001 using namespace std; int n,m,root,cnt; int head[2*maxn],depth[maxn],f[maxn][21];//depth深度 f[a][b]指a节点的第2^b个祖先 ... 阅读全文
posted @ 2018-07-08 16:51
radishえらい
阅读(117)
评论(0)
推荐(0)
摘要:
//LCA //Tarjan 离线 #include #include #include #include #include #include #define maxn 500001 using namespace std; int n,m,root,cnt,lca[maxn],head[maxn],jdg[maxn],fa[maxn],set[maxn];//set并查集 int cntg... 阅读全文
posted @ 2018-07-08 16:50
radishえらい
阅读(95)
评论(0)
推荐(0)
摘要:
//LCA //ST表 在线 #include #include #include #include #include #include #define maxn 500001 using namespace std; int n,m,cnt,root,head[maxn],depth[maxn]; int order[2*maxn],first[maxn];//order[x]dfs中第x次... 阅读全文
posted @ 2018-07-08 16:49
radishえらい
阅读(319)
评论(0)
推荐(0)

浙公网安备 33010602011771号