
模板
IDSY QAQ
日常三问:我被机残了吗?我密码被盗了吗?我的号还在吗?
展开
-
LCT 模板
const int MaxLct = 2 * 1e5;#define ls(p) (Tr[p].ch[0])#define rs(p) (Tr[p].ch[1])#define fa(p) (Tr[p].fa)#define rev(p) (Tr[p].rev)struct Node { int rev; int ch[2], fa;};struct Link_Cut_Tree { Node Tr[MaxLct + 5]; int st[MaxLct + 5]原创 2022-03-11 21:11:22 · 294 阅读 · 0 评论 -
ac自动机模板
const int Maxn = 1e6;const int Maxkind = 26;struct Ac_Automata { int cnt; int End[Maxn + 5]; int Tire[Maxkind + 5][Maxn + 5]; int dout[Maxn + 5]; void Init () { memset (dout, 0, sizeof dout); memset (Tire, 0, sizeof Tire);原创 2022-01-23 14:28:43 · 252 阅读 · 0 评论 -
费用流模板
#include <cmath>#include <queue>#include <vector>#include <cstdio>#include <cstdlib> #include <cstring>#include <iostream>#include <algorithm>using namespace std;#define fi first#define se second#d原创 2022-01-04 15:10:55 · 304 阅读 · 0 评论 -
连通分量
无向图1.求无向图的边双连通分量int dfn[Maxn + 5], low[Maxn + 5], timestamp;int id[Maxn + 5], dcc_cnt;int st[Maxn + 5], Top;bool is_bridge[Maxm * 2 + 5];void Tarjan (int u, int fa) { dfn[u] = low[u] = ++timestamp; st[++Top] = u; for (int i = Head[u]原创 2021-04-10 15:03:05 · 231 阅读 · 2 评论 -
二次项展开(矩阵加速)
#include <cmath>#include <stack>#include <queue>#include <vector>#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>#define LL long long#define ULL uns原创 2021-04-04 21:55:56 · 655 阅读 · 0 评论 -
欧拉回路
#include <cstdio>#include <algorithm>#include <stack>#include <map>#include <iostream>using namespace std;#define MAXN 200000struct node { int value, ed; node *next;}sa[MAXN + 5];int u[MAXN + 5];int a[MAXN + 5];原创 2020-08-20 19:41:04 · 184 阅读 · 0 评论 -
康托&康托逆展开
const int Maxn = 1e5 + 5;const LL Mod = 998244353;struct Cantor { int n; int c[Maxn], BIT[Maxn], Bit[Maxn]; LL order, fac[Maxn]; int lowbit (int x) { return x & -x; } void Update (int Index, int x, int *str) { for (int i = Index; i < Max原创 2021-02-05 09:41:25 · 116 阅读 · 0 评论 -
RMQ
ST表void build () { for (int i = 1; i <= n; i++) f[i][0] = a[i]; for (int len = 1; (1 << len) <= n; len++) { for (int l = 1; l + (1 << len) - 1 <= n; l++) { f[l][len] = Max (f[l][len - 1], f[l + (1 <<原创 2020-12-15 12:38:50 · 99 阅读 · 0 评论 -
高精度模板
template <typename T>T Max (T x, T y) { return x > y ? x : y; }template <typename T>T Min (T x, T y) { return x < y ? x : y; }template <typename T>T Abs (T x) { return x > 0 ? x : -x; }struct high_precision { vector &l原创 2020-12-08 20:58:17 · 170 阅读 · 1 评论 -
lca模板
1.树上倍增#include <queue>#include <cstdio>using namespace std;const int MAXN = 1e5 + 5;const int MAXTEP = 45;int n, m;int depth[MAXN], f[MAXN][MAXTEP];int len, head[MAXN];struct edge { int to, next;}e[MAXN * 2];void add (int, int);原创 2020-12-04 12:39:32 · 205 阅读 · 0 评论 -
线段树
区间最大值struct Segment_Tree { int l, r; int Max_Date;}Seg_Tr[MAXN * 4];int Max (int x, int y) { return x > y ? x : y; }void _Build (int p, int l, int r) { Seg_Tr[p].l = l; Seg_Tr[p].r = r; if (l == r) { Seg_Tr[p].Max_Date = a[l]; return; }原创 2020-11-21 09:13:33 · 120 阅读 · 0 评论 -
KMP
void Make_Next (char *str) { int i = 1, j = 0, len = strlen (str + 1); while (i <= len) { if (j == 0 || str[i] == str[j]) { i++; j++; Next[i] = j; } else { j = Next[j]; } }}int Kmp (char *s, char *str) { int i = 1, j = 0, len1原创 2020-11-14 11:51:38 · 126 阅读 · 0 评论 -
逆元
逆元1.void exgcd (LL a, LL b, LL &x, LL &y) { if (b == 0) { x = 1; y = 0; return; } exgcd (b, a % b, y, x); y -= a / b * x;}LL inv (LL a, LL p) { LL x, y; exgcd (a, p, x, y);// printf ("a = %d, p = %d, x = %d,原创 2020-11-02 14:04:38 · 144 阅读 · 0 评论 -
扩展欧几里得
扩展欧几里得1.void exgcd (long long a, long long b, long long &x, long long &y) { if (b == 0) { x = 1; y = 0; return; } exgcd (b, a % b, y, x); y -= a / b * x;}2.void exgcd (LL a, LL b, LL &x, LL &y) { if (b原创 2020-11-02 13:52:42 · 148 阅读 · 0 评论 -
向量
1.题目2.分析有四种操作方式 (a,b),(a,−b),(b,a),(b,−a)(a, b), (a, -b), (b, a), (b, -a)(a,b),(a,−b),(b,a),(b,−a)设第iii个方程的操作数量是AiA_iAi∴A1a+A2a+A3b+A4b=x①∴A_1a + A_2a + A_3b + A_4b = x①∴A1a+A2a+A3b+A4b=x①且A1b−A2b+A3a−A4a=y②且A_1b - A_2b + A_3a - A_4a = y②且A1b−A2原创 2020-10-23 20:56:16 · 180 阅读 · 0 评论 -
小球问题
#include <cstdio>#include <iostream>#define LL long longusing namespace std;const int MAXN = 1005;int dp[MAXN][MAXN], f[MAXN][MAXN];LL C (int, int);LL A (int, int);LL DP (int, int);//n个相同的球分到m个相同的盒子里LL factorial (int);LL quick_pow原创 2020-10-16 21:06:06 · 235 阅读 · 0 评论 -
筛素数
筛素数1.暴力筛#include <cstdio>#include <iostream>using namespace std;int n, q;bool check (int);int main () { scanf ("%d %d", &n, &q); for (int i = 1; i <= q; i++) { int x; scanf ("%d", &x); if (check原创 2020-10-08 14:33:04 · 133 阅读 · 0 评论 -
分数
分数基本运算 (+, -, *, /)LL Abs (LL x) { return x > 0 ? x : -x; }LL gcd (LL x, LL y) { x = Abs (x), y = Abs (y); if (x > y) swap (x, y); if (x == 0) return y; else return gcd (y % x, x);}LL lcm (LL x, LL y) { return x * (y / gcd (x, y));}s原创 2020-10-07 19:39:49 · 133 阅读 · 0 评论 -
矩阵的模板
矩阵1.基本运算(+, -, *)LL MO = INF;struct Matrix { int n, m; LL map[MAXN][MAXN]; Matrix() { memset(map, 0, sizeof map); } void read() { for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) {原创 2020-10-07 19:39:00 · 331 阅读 · 0 评论 -
背包
背包01背包#include <iostream>using namespace std;const int MAXN = 1005;int n, V;int v[MAXN], p[MAXN], f[MAXN];int Max (int x, int y) {return x > y ? x : y;}int main () { cin >> n >> V; for (int i = 1; i <= n; i++) cin原创 2020-10-07 19:38:09 · 115 阅读 · 0 评论 -
最小生成树
最小生成树prim1.朴素#include <iostream> using namespace std;const int MAXN = 1005;const int INF = 0x3f3f3f3f;int n;int dis[MAXN];int w[MAXN][MAXN];bool vis[MAXN];int prim ();int main () { cin >> n; for (int i = 1; i <= n; i++) f原创 2020-10-07 19:37:19 · 112 阅读 · 0 评论 -
最短路
最短路floyd#include <iostream>using namespace std;const int MAXN = 105;const int INF = 0x3f3f3f3f;int n, m;int dis[MAXN][MAXN];int Min(int x, int y) {return x < y ? x : y;}int Max(int x, int y) {return x > y ? x : y;}int main() { cin原创 2020-10-07 19:36:41 · 123 阅读 · 0 评论 -
快读快输
快速读入void read(int &x) { x = 0; int f = 1; char s = getchar(); while(s < '0' || s > '9') { if(s == '-') { f = -1; } s = getchar(); } while(s >= '0' && s <= '9') { x = (x << 3) + (x << 1) + s - 48; s =原创 2020-10-07 19:35:32 · 189 阅读 · 0 评论 -
堆
堆1.插入void put(int x) { heap[++len] = x; int fa, now = len; while(now > 1) { fa = now >> 1; if(heap[fa] <= heap[now]) break; swap(heap[fa], heap[now]); now = fa; } return;}2.返回堆顶值int get() { return heap[1];}3.取出堆顶值void po原创 2020-10-07 19:34:45 · 118 阅读 · 0 评论 -
树状数组
树状数组1.求lowbitint lowbit(int x) {return x & -x;}2.更新(pudate)void _Update(int index, int x) { for(int i = index; i <= n; i += _Lowbit(i)) BIT[i] += x; return;}3.求前缀和int _Sum(int x) { int sum = 0; for(int i = x; i > 0; i -= _Lowbit(i)原创 2020-10-07 19:33:57 · 127 阅读 · 0 评论 -
逆序对
求逆序对1.void merge_sort(int l, int r) { if(l == r) return; int mid = (l + r) / 2; merge_sort(l, mid); merge_sort(mid + 1, r); int i = l, j = mid + 1; int tem[MAXN], len = l; while(i <= mid && j <= r) { if(a[i] <= a[j]) { tem[原创 2020-10-07 19:32:50 · 102 阅读 · 0 评论 -
离散化
离散化1.#include <iostream>#include <algorithm>using namespace std;const int MAXN = 1005;int n;int rev[MAXN], a[MAXN];int main() { cin >> n; for(int i = 1; i <= n; i++) cin >> a[i], rev[i] = a[i]; sort(rev + 1, rev + 1原创 2020-10-07 19:32:00 · 124 阅读 · 0 评论 -
情报机器人(robot) + 三分小结
题面思路很容易想到思路,算出每两个机器人之间的"相遇时间"(即何时记录信号),再用最小生成树(kruskal)算出答案。难点:如何算出每两个机器人之间的“相遇时间”?考场上我脑子一抽,就想枚举(略加亿点小技巧)每两个机器人之间的相对运动关系,可是打了30多种情况后就放弃了(共有64种可能,而且打的还不一定是对的),于是打了一个暴力枚举t就跑了 (结果只有8分) , 可是我就没有思考t和两个机器人的距离的关系。建立一个直角坐标系,以t为x轴,以两机器人之间的距离为y轴,函数图像成一个单峰函数。 (易原创 2020-09-21 21:28:38 · 397 阅读 · 0 评论 -
有(chang)用(wang)的一些函数(后续可能会继续填)
1.exit(0);需要的头文件:#include <algorithm>同时,这个头文件还需要using namespace std;才能运行作用:跳出整个递归原创 2020-07-14 08:55:55 · 189 阅读 · 0 评论 -
各种排序模板
1.冒泡排序void Bubble_Sort(int arr[]) { for(int i = n; i >= 2; i--) { for(int j = 1; j <= i - 1; j++) { if(arr[j] >= arr[j + 1]) swap(arr[j], arr[j + 1]); } }}拓展:求逆序对int Bubble_Sort(int arr[]) { int sum = 0; for(int i = n; i >= 2; i原创 2020-07-25 21:18:17 · 188 阅读 · 0 评论 -
各种算法模板
离散化1.#include <iostream>#include <algorithm>using namespace std;const int MAXN = 1005;int n;int rev[MAXN], a[MAXN];int main() { cin >> n; for(int i = 1; i <= n; i++) cin >> a[i], rev[i] = a[i]; sort(rev + 1, rev + 1原创 2020-07-26 20:13:01 · 437 阅读 · 0 评论