随笔分类 - ACM模板
1
摘要:对于splay核心是旋转和伸展,其他操作基本都是利用伸展的特性:
阅读全文
摘要:Kruskal 1 #include<bits/stdc++.h> 2 using namespace std; 3 #define INF 0x3f3f3f3f 4 #define M(a, b) memset(a, b, sizeof(a)) 5 const int N = 1e3 + 10,
阅读全文
摘要:1 #include<iostream> 2 #include<algorithm> 3 #include<cstring> 4 #include<vector> 5 #include<set> 6 #include<map> 7 #include<queue> 8 using namespace
阅读全文
摘要:1 #include 2 using namespace std; 3 #define INF 0x3f3f3f3f 4 #define M(a, b) memset(a, b, sizeof(a)) 5 const int N = 1e3 + 5; 6 struct Edge { 7 int from, to, cap, flow, cost; 8 }; 9 10 ...
阅读全文
摘要:Dinic算法 1 #include<bits/stdc++.h> 2 using namespace std; 3 #define INF 0x3f3f3f3f 4 #define M(a, b) memset(a, b, sizeof(a)) 5 const int N = 1e3 + 5; 6
阅读全文
摘要:两次dfs模板: 1 #include<bits/stdc++.h> 2 using namespace std; 3 #define INF 0x3f3f3f3f 4 #define M(a, b) memset(a, b, sizeof(a)) 5 const int N = 1000 + 5;
阅读全文
摘要:给你一个长度为N的数组,一个长为K的滑动的窗体从最左移至最右端,你只能见到窗口的K个数,每次窗体向右移动一位,如下表: 你的任务是找出窗口在各位置时的max value,min value. 单调队列的入门题,单调队列我的理解有对时间和大小都单调,只会在队列两端进行操作(队尾前移看大小,队头后移看时
阅读全文
摘要:点双连通分量模板(Tarjan算法) 1 #include<bits/stdc++.h> 2 using namespace std; 3 #define M(a, b) memset(a, b, sizeof(a)) 4 #define INF 0x3f3f3f3f 5 const int N =
阅读全文
摘要:SPFA是队列优化后的Bellman-Ford,用于求带负权边的最短路,然而传说中O(k*n)的复杂度好像是错误的。
阅读全文
摘要:LCA-求树上两点最近公共祖先问题 lrj的紫书上提供了一种将LCA问题转化为RMQ问题的方法,即dfs一次处理出一个序列,first(u)代表u第一次出现的下标,则对于u,v的最近公共祖先的下标即为RMQ(first(u), first(v))。 LCA->RMQ(在线处理): Tarjan算法(
阅读全文
摘要:Treap(树堆)的大部分功能STL的set都可以实现,但因为set的过度封装使得某些特定的功能不能实现,比如求第k大的值。 Code:
阅读全文
摘要:对于求最长回文子串问题,暴力解法的时间复杂度是O(n3); 好一点的算法从每个点向两边扩展也要O(n2)的复杂度; Manacher算法用p[i]数组记录以i为对称轴的回文串的右端到i的距离以及一个maxright标志,利用了回文串的对称性,使每个点只要处理一遍,因此复杂度降到了O(n)。 模板:
阅读全文
摘要:1 #include 2 using namespace std; 3 const int maxn = 1000 + 5; 4 int C[maxn], n; 5 6 int lowbit(int x) {return x & -x;} 7 8 int sum(int x) { 9 int ret = 0; 10 while(x) { 11 ...
阅读全文
摘要:1 #include 2 using namespace std; 3 #define M(a, b) memset(a, b, sizeof(a)); 4 const int maxn = 1000 + 10; 5 6 struct AhoCorasickAutomata { 7 int ch[maxn][26], val[maxn], last[maxn], f[ma...
阅读全文
摘要:模板1:点修改:支持查询,更新; 1 #include<bits/stdc++.h> 2 using namespace std; 3 #define INF 0x3f3f3f3f 4 const int maxn = 1000 + 10; 5 int a[maxn], qL, qR, p, v;
阅读全文
摘要:1 #include 2 using namespace std; 3 int MOD; 4 5 int fast_pow_mod(int a, int b) { 6 int res = 1; 7 while(b) { 8 if (b & 1) res = res * a % MOD; 9 a = a * a % MOD; 10...
阅读全文
摘要:1 #include<bits/stdc++.h> 2 using namespace std; 3 #define MAXN 1000+10 4 int dp[MAXN][MAXN], a[MAXN]; 5 6 void InitRMQ(int l, int r, int n){ 7 int k
阅读全文
摘要:1 #include<bits/stdc++.h> 2 using namespace std; 3 4 typedef struct TrieNode{ 5 bool flag; 6 TrieNode *next[26]; 7 TrieNode(){ 8 flag = false; 9 memse
阅读全文
摘要:模板1: 1 #include<bits/stdc++.h> 2 using namespace std; 3 4 void InitNext(char *s, int *next){ 5 int i = 0, j = -1, len = strlen(s); 6 next[0] = -1; 7 w
阅读全文
摘要:1 #include<cstdio> 2 #include<iostream> 3 #include<algorithm> 4 #include<cmath> 5 #include<cstring> 6 #include<set> 7 #include<map> 8 #include<queue>
阅读全文
1

浙公网安备 33010602011771号