随笔分类 - 模板
摘要:自定义哈希 struct custom_hash { static uint64_t splitmix64(uint64_t x) { // http://xorshift.di.unimi.it/splitmix64.c x += 0x9e3779b97f4a7c15; x = (x ^ (x >
阅读全文
摘要:AC自动机 求解一个目标串匹配多个模式串的问题 下面模板求解的是有多少种模式串在目标串中出现 // Created by CAD #include <bits/stdc++.h> #define mst(name, value) memset(name,value,sizeof(name)) usi
阅读全文
摘要:快读 参考:算法笔记--快读(输入外挂)模板 基础版本: inline int read(){ int s=0,w=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();} while(ch>='0'&&ch
阅读全文
摘要:求 n 以内的素数和以及素数个数 复杂度: // Created by CAD #include <bits/stdc++.h> #define ll long long using namespace std; ll check(ll v,ll n,ll
阅读全文
摘要:后缀自动机 // Created by CAD #include <bits/stdc++.h> using namespace std; const int maxn=1e6+5; namespace sam{ int len[maxn<<1],link[maxn<<1],Next[maxn<<1
阅读全文
摘要:后缀自动机做题技巧 ①后缀自动机的总状态数小于,总转移边数小于 ②后缀自动机沿着 link 链接跳的总复杂度为,构造后缀自动机的总复杂度也是 性质: ①插入字符新增子串数:len[p]-len[link[p]] ②后缀链接:link[p]表示的字符串是p的后缀
阅读全文
摘要:回文自动机做题技巧 ① 灵活利用维护的各个数据: 节点x len[x]表示该节点表示的字符串的最长长度 fail[x]指向的节点表示的字符串是节点x表示字符串的最长子回文串 cnt[x]在经过以下处理后表示在s中该节点所表示字符串在s中的出现次数 for(int i=sz;i>=0;++i) cnt
阅读全文
摘要:最小表示法 参考:最小表示法 目的:O(n)求出一个序列循环同构中最小的那一个(在字符串中表示为字典序最小的一个循环同构) 优化内容:i,j 分别是当前比较的起始下标,k 是已比较的个数。当前假设,那么对于起始的字符串,$
阅读全文
摘要:pb_ds中的hash_table 参考: pd_ds中的hash 需要的头文件和命名空间: #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/hash_policy.hpp> using namespace __gnu_pbds;
阅读全文
摘要:求第k个父亲节点 参考:树上倍增的写法和应用(详细讲解,新手秒懂) // Created by CAD #include <bits/stdc++.h> using namespace std; const int maxn=5e5+5; vector<int> g[maxn]
阅读全文
摘要:###倍增法求最近公共祖先 参考:题解 P3379 【模板】最近公共祖先(LCA) 参考:树上倍增的写法和应用(详细讲解,新手秒懂) // Created by CAD #include <bits/stdc++.h> using namespace std; const int maxn=5e5+
阅读全文
摘要:回文自动机 参考: 回文树 // Created by CAD #include <bits/stdc++.h> #define ll long long using namespace std; const int maxn=3e5+5; namespace pam{ int sz,tot,las
阅读全文
摘要:二次剩余 参考: 二次剩余Cipolla算法学习笔记 #include <bits/stdc++.h> using namespace std; const int mod=1e9+9; namespace TwoRemain { template <typename A, typename B>
阅读全文
摘要:字典树 字典树比较普通字符串比较而言,字符的可操作性更强 const int maxn=5e5+5; //maxn为总结点个数,不是总深度 struct trie{ int nex[maxn][26],cnt=0; bool exist[maxn]; void insert(string s){ i
阅读全文
摘要:判断一个多边形的给定点是按顺时针给出还是逆时针 参考:判断一个多边形是顺时针还是逆时针的方法 bool judge(vector<double> x,vector<double> y,int n){ //1逆时针,0顺时针 if(n < 3) return 0.0>0; double s = y[0
阅读全文
摘要:得到某个位置的迭代器 参考: "C++ vector如何返回某一位置的迭代器?"
阅读全文
摘要:自定义 排序方式 参考: "优先队列(priority_queue)四种自定义排序方法" 一种方法是定义全局的重载函数,另一种方法是自定义一个结构体,然后重载函数。 只能用第二种方法。
阅读全文
摘要:Manacher 参考: "Manacher" 模板题: "P3805 【模板】manacher算法" 用于求最长回文串,复杂度为,其中 表示以 i 为中心的长度为奇数的回文子串,如 中, ,`d2[i] baab d2[1]=0,d2[2]=2` 马拉车算法的关键在于利用回文串的对称性
阅读全文
摘要:求迭代器在vector,set,map中的位置 利用 函数
阅读全文