[模板]kmp求Next数组
    
            
摘要:模板 #include <iostream> #include <string> using namespace std; void getNext(const string& p,int next[]) { int len = (int)p.size(); next[0] = -1; int k 
        
阅读全文
 
        
            
    二分法求LIS
    
            
摘要:二分法求LIS的本质并不是二分,而是存储整个序列数据的数组f[n]。 我们考虑到,f[i]实际上是长度为i的上升序列的"最后一个值",那么我们把他们拟人化,看看他们自己希望怎么更新。 假设我是f[3]=4,我的好朋友是f[4]=6。那么,如果“我”可以通过拓展一个大于我末尾的数字来更新自己,那我肯定
        
阅读全文
 
        
            
    P2568 GCD(线性筛-欧拉函数 模板)
    
            
摘要:有两个易错点: 1.欧拉函数的定义是1到n内互质的数,但是“互质”不一定要都是质数,其实就只需要gcd(a,b)=1就可以计算进去。所以,就不能放弃a=1,b=1的情况, 2.第一次做的时候自认为应该避免i=j的情况,但问题是经过化简之后的式子本身就已经考虑到i=j这个情况,并以此作为继续计算的基础
        
阅读全文
 
        
            
    【模板】线性筛素数
    
            
摘要:题目地址:洛谷 P3383 #include<cstdio> #include<iostream> using namespace std; const int MAXN=1e8+1000; int n,prime[MAXN],cnt=0; bool isPrime[MAXN]; void init
        
阅读全文
 
        
            
    模板 -- 除法分块
    
            
摘要:#include<cstdio> #include<iostream> #define ll long long using namespace std; int main(){ ll n; cin>>n; ll sum=0; for(ll l=1,r;l<=n;l=r+1){ r=n/(n/l);
        
阅读全文
 
        
            
    poj 1458 最长公共子序列
    
            
摘要:题目链接 #include<cstdio> #include<iostream> #include<cstring> using namespace std; char s1[200],s2[200]; int dp[300][300]; int main(){ while(~scanf("%s%s
        
阅读全文
 
        
            
    T206418 【模板】最长上升子序列 标程
    
            
摘要:题目链接:https://www.luogu.com.cn/problem/T206418 #include<cstdio> #include<iostream> #include<algorithm> using namespace std; const int MAXN=200000*25; i
        
阅读全文
 
        
            
    T206189 【模板】二分查找 标程
    
            
摘要:题目链接:https://www.luogu.com.cn/problem/T206189 #include<cstdio> #include<algorithm>//用到lower_bound using namespace std; const int MAXN=1e6+10;//注意范围 in
        
阅读全文
 
        
            
    P1082 同余方程(【模板】exgcd)
    
            
摘要:题目地址 #include<cstdio> #include<iostream> #define ll long long using namespace std; void exgcd(ll a,ll b,ll &x,ll &y){ if(!b){ x=1,y=0; return; } exgcd
        
阅读全文
 
        
            
    P1144 最短路计数
    
            
摘要:题目地址 注意点: 本题需要开双向边. #include<cstdio> #include<iostream> #include<queue> #include<cstring> #define int long long using namespace std; const int MAXN=2e
        
阅读全文
 
        
            
    P4147 玉蟾宫(【模板】悬线法)
    
            
摘要:题目地址 注意点: if(canGet[x][y-1])l[x][y]=max(l[x][y],l[x][y-1]); if(canGet[x][y-1])r[x][y]=min(r[x][y],r[x][y-1]);
        
阅读全文
 
        
            
    T106136 【模板】字符串哈希
    
            
摘要:题目地址 基本思想: hash[i]=hash[i-1]*base+s[i].(base:选定的质数,如101,171等) 本质:前缀积. 对于一个范围l~r,可以利用hash[r]-hash[l]*tmp[r-l+1]获取.(tmp:base的前缀积) 掌握技巧: 手动模拟.
        
阅读全文
 
        
            
    P3370 【模板】字符串哈希
    
            
摘要:题目地址 注意点: map直接用[]访问即可.
        
阅读全文
 
        
            
    T106021 【模板】乘法逆元(快速幂)
    
            
摘要:题目地址 注意点: 使用exgcd求乘法逆元需额外进行(相对)较多操作,建议使用快速幂求乘法逆元.
        
阅读全文
 
        
            
    T105910 【模板】O(1)快速乘
    
            
摘要:题目地址 基本思想: 直接扔掉高位的数字,在能乘的范围内乘. 由于正常情况下有符号整数会出现溢出的情况,所以使用无符号数值(unsigned long long)即可. 具体实现: 已知 a%p=a-⌊a/p⌋*p(a减去尽可能多的p). 则a*b%p=a*b-⌊a*b/p⌋*p. 这里a*b不会变
        
阅读全文
 
        
            
    P3304 [SDOI2013]直径(【模板】树直径的必经边)
    
            
摘要:题目地址 基本思路: 题目要求树直径的必经边,那么首先应当获取一条直径. 获取直径后从直径上的两个端点分别遍历一次直径,每次遍历直径时从直径上的每个点分别dfs一次并不经过直径上的点,如果深度可以被替换则说明非必经边.
        
阅读全文
 
        
            
    P5490 【模板】扫描线
    
            
摘要:题目地址 注意点: 线段树中使用获取具体长度时右端点应当+1,向线段树内插入值时右端点应当-1.(区间覆盖线段树)
        
阅读全文