模板
goto_1600
我何来寂寞,哪有寂寞可言。
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
mat 加速模板
123原创 2022-10-14 16:56:10 · 217 阅读 · 1 评论 -
unordered_map/set自定义哈希函数
hash原创 2022-04-30 17:17:42 · 946 阅读 · 0 评论 -
LGV引理
Link 假设起点集为SSS,顶点集为TTT,求矩阵中S到T的不相交路径的方案数。 结论: LGV说白了就是解行列式的值,e(ai,bi)e(ai,bi)e(ai,bi)代表方格中ai到bi的走法,由于小学数学问题显然可以用组合数知道 e(ai,bi)=C(a到b的总步数,a到b行走的数量)e(ai,bi)=C(a到b的总步数,a到b行走的数量)e(ai,bi)=C(a到b的总步数,a到b行走的数量) [e(a1,b1)e(a1,b2)e(a1,b3)e(a2,b1)e(a2,b2)e(a2,b3)e(a3原创 2021-10-01 16:32:00 · 945 阅读 · 0 评论 -
高斯消元模板
Link #include<bits/stdc++.h> using namespace std; const int N=110; double a[N][N]; int n; void gauss() { for(int i=1;i<=n;i++){ int id=i; for(int j=i+1;j<=n;j++) if(fabs(a[j][i])>fabs(a[id][i])) id=j; if(fabs(a[id][i])<1e-6)原创 2021-10-01 15:39:39 · 205 阅读 · 0 评论 -
字符串 最小表示法
用于处理给定一个串,每次可以将最前面的字母放到最后面,O(n)O(n)O(n)求最小序。 用到最小表示法这个神奇的东西,运用双指针,然后暴力枚举k,运用一些性质来让指针对每一个位置只走一次,比如说当前枚举到k,s[i+k]>s[j+k]k,s[i+k]>s[j+k]k,s[i+k]>s[j+k]那么从s[i+k]开始的后缀都是不要的,直接让i+=k+1 模板题 代码: #include <iostream> #include <cstring> #include &原创 2021-09-27 17:04:53 · 226 阅读 · 2 评论 -
FWT模板
//#pragma GCC target("avx") //#pragma GCC optimize(2) //#pragma GCC optimize(3) //#pragma GCC optimize("Ofast") // created by myq #include<iostream> #include<cstdlib> #include<string> #include<cstring> #include<cstdio> #includ原创 2021-09-23 13:14:29 · 384 阅读 · 0 评论 -
可持久化并查集模板
Link //#pragma GCC target("avx") //#pragma GCC optimize(2) //#pragma GCC optimize(3) //#pragma GCC optimize("Ofast") // created by myq #include<iostream> #include<cstdlib> #include<string> #include<cstring> #include<cstdio> #i原创 2021-09-17 11:01:40 · 235 阅读 · 0 评论 -
后缀数组模板
#include<bits/stdc++.h> using namespace std; string s; const int N=300010; int sa[N]; int x[N]; int y[N]; int c[N]; int height[N]; int rk[N]; int n,m; void get_sa() { for(int i=1;i<=n;i++) ++c[x[i]=s[i]]; for(int i=1;i<=m;i++) c[i]+原创 2021-08-22 01:09:23 · 240 阅读 · 3 评论 -
min25
// Problem: #6053. 简单的函数 // Contest: LibreOJ // URL: https://loj.ac/p/6053 // Memory Limit: 256 MB // Time Limit: 2000 ms // // Powered by CP Editor (https://cpeditor.org) //#pragma GCC target("avx") //#pragma GCC optimize(2) //#pragma GCC optimize(3) //原创 2021-08-19 18:21:40 · 242 阅读 · 0 评论 -
MTT 模板(任意模数)
MTT能处理任意模数的FFT。就比如这题 题意: 求一个数列长度大于等于1的子序列和的乘积,首先考虑N^2 DP DP[i][j]代表考虑前i个数和为j的方案数,很容易处理出方案数,最后答案就是ΠsumDP[sum]\Pi sum^{DP[sum]}ΠsumDP[sum]。 还有另一种解法,考虑生成函数,对于每一个数选或者不选,把TA变成多项式的情形,就是1+xai1+x^{ai}1+xai然后乘起来,最后每个某个数M的答案就是xmx^mxm的系数,考虑幂次太大,我们要欧拉降幂一下,mod=99824435原创 2021-08-13 16:48:28 · 849 阅读 · 0 评论 -
BM 模板
//递推公式黑科技 #include<bits/stdc++.h> using namespace std; ///#define X first //#define Y second #define PB push_back //#define MP make_pair //#define MEM(x,y) memset(x,y,sizeof(x)); //#define bug(x) cout<<"bug"<<x<<endl; typedef long l原创 2021-08-01 16:03:10 · 298 阅读 · 0 评论 -
BSGS
#include<iostream> #include <unordered_map> #include<cmath> using namespace std; #define int long long int bsgs(int a,int b,int p) { if(1%p==b%p) return 0; unordered_map<int,int>mp; int k=sqrt(p)+1; int ak=1;原创 2021-07-21 15:26:30 · 230 阅读 · 0 评论 -
FFT高精度乘法
#include<iostream> #include<cmath> #include<vector> using namespace std; const int N=400010; struct Complex{ double x; double y; Complex() { } Complex (double _x,double _y) { x=_x,y=_y; }原创 2021-07-18 21:25:48 · 662 阅读 · 0 评论 -
自适应辛普森积分
主要是要会弄出f()值 simpson公式就是(f(l)+f®+(f(l+r)/2))*(r-l)/6 可以用的地方基本都是有弧度的曲线。 #include<iostream> #include <cmath> using namespace std; const double eps = 1e-12; double f(double x) { return sin(x)/x; } double simpson(double l,double r) { doubl.原创 2021-06-01 22:17:18 · 365 阅读 · 0 评论 -
中缀表达式
只能处理没有-号的 #include<iostream> #include<stack> #include<unordered_map> using namespace std; stack<char>op; stack<int>num; string s; void eval() { int b=num.top(); num.pop(); int a=num.top(); num.pop(); auto原创 2021-06-01 21:02:03 · 176 阅读 · 0 评论 -
权值线段树套传统线段树+懒标记持久化+动态开点
有 N 个位置,M 个操作。每个位置可以同时存储多个数。 操作有两种,每次操作: 如果是 1 a b c 的形式,表示在第 a 个位置到第 b 个位置,每个位置加入一个数 c。 如果是 2 a b c 的形式,表示询问从第 a 个位置到第 b 个位置,第 c 大的数是多少。 输入格式 第一行包含两个整数 N,M。 接下来 M 行,每行包含一条指令,形如 1 a b c 或 2 a b c。 输出格式 输出每个询问的结果,每个结果占一行。 数据范围 1≤N,M≤50000, 1≤a≤b≤N, 1 操原创 2020-12-14 11:42:15 · 285 阅读 · 0 评论 -
树套树板子
#include<iostream> #include<cstring> #include<stdlib.h> #include<time.h> using namespace std; const int N=50010; int n,m; int cnt; struct node{ int l; int r; int val; int key; int sz; }fhq[N*40]; struct nd{ int l; int r; i原创 2020-12-13 12:16:08 · 370 阅读 · 0 评论 -
二维树状数组
复杂度 Q∗log(N)∗log(M)Q*log(N)*log(M)Q∗log(N)∗log(M) #include<bits/stdc++.h> using namespace std; typedef long long ll; #define debug printf("---\n"); const int N=2050,M=10010; #define int long long int t1[N][N],t2[N][N],t3[N][N],t4[N][N]; int n,m; in.原创 2020-12-10 21:12:29 · 287 阅读 · 0 评论 -
fhqtreap 维护区间翻转
#include<bits/stdc++.h> using namespace std; struct node{ int l; int r; int val; int key; int sz; int lz; }fhq[100010]; int root; int cnt; void update(int now) { fhq[now].sz = 1+fhq[fhq[now].l].sz+fhq[fhq[now].r].sz; } int newnode(int val) {原创 2020-12-09 10:21:50 · 358 阅读 · 0 评论 -
普通平衡树 fhq yyds
#include<bits/stdc++.h> using namespace std; int cnt; int root; int x,y,z; struct node{ int l; int r; int val; int key; int sz; }fhq[100010]; int newnode(int x) { ++cnt; fhq[cnt].sz=1; fhq[cnt].key=rand(); fhq[cnt]原创 2020-12-07 21:53:46 · 405 阅读 · 0 评论 -
AC自动机
给定 n 个长度不超过 50 的由小写英文字母组成的单词,以及一篇长为 m 的文章。 请问,有多少个单词在文章中出现了。 #include<bits/stdc++.h> using namespace std; const int N=10010,S=55,M=1000010; char str[M]; int tr[N*S][26],q[N*S],idx; int cnt[N*S]; int ne[N*S]; void add() { int p=0; for(int i原创 2020-11-28 19:50:26 · 306 阅读 · 0 评论 -
2-sat模板
给定n个变量 给定m对关系 例如 aVb !aVb 让你构造出一组布尔值解满足题目要求 就是2sat的模板 把拓扑序后面的点当做可行解 #include<bits/stdc++.h> using namespace std; typedef long long ll; #define debug printf("---\n"); const int N=2000010,M=2000010; int h[N],ne[M],e[M],idx,top,id[N],dfn[N],low[N],stk[N原创 2020-11-24 17:26:54 · 295 阅读 · 0 评论 -
__int128
__int128 read(){ __int128 x=0,f=1; char ch=getchar(); while(!isdigit(ch)&&ch!=’-’)ch=getchar(); if(ch==’-’)f=-1; while(isdigit(ch))x=x10+ch-‘0’,ch=getchar(); return fx; } void print(__int128 x){ if(x<0)putchar(’-’),x=-x; if(x>9)print(x/10);//原创 2020-10-27 20:43:04 · 265 阅读 · 0 评论 -
PR算法 大数质因数分解优化
#include<bits/stdc++.h> using namespace std; const int MAXN = 100005; const int p[9] = {2, 3, 5, 7, 11, 13, 17, 19, 23}; typedef long long ll; typedef long double ld; template <typename T> void chkmax(T &x, T y) {x = max(x, y); } templat..原创 2020-10-25 14:39:05 · 904 阅读 · 0 评论 -
线段树找从1开始大于等于该值的模板
一开始我和大佬想的是二分再套线段树,然后tle了,想不到优化然后就查网了,如果左子树满足条件就不要递归右子树了可以优化一下,然后如果整段区间的最大值也不满足那就没必要往下递归了。 int query(int m,int l,int r,int val){ if(tree[m].l==tree[m].r) { if(tree[m].val>=val) return tree[m].l; return -1; }原创 2020-10-23 09:35:41 · 304 阅读 · 0 评论
分享