摘要: 倍增求LCA int LCA(int x,int y){ if(dep [x]>dep[y])swap(x,y); int k=dep [y]-dep [x]; for(int i=Log2[k];i >0;i--){ if((k>>i)&1)y=f[i][y]; } if (x =y)return 阅读全文
posted @ 2024-01-20 16:26 tju空明 阅读(18) 评论(0) 推荐(0)
摘要: 马拉车算法 char s[maxn],ss[maxn]; int p[maxn]; int len,center; int cnt=1; void init(){ memset(s,0,sizeof s); cnt=1,s[0]='@'; int len=strlen(ss); for(int i= 阅读全文
posted @ 2024-01-20 16:25 tju空明 阅读(10) 评论(0) 推荐(0)
摘要: 大数因数分解Pollard_rho #include <iostream> #include <cstdio> #include <algorithm> #include <cmath> #include <cstring> #include <map> using namespace std; c 阅读全文
posted @ 2024-01-20 16:25 tju空明 阅读(38) 评论(0) 推荐(0)
摘要: Miller Rabin素数判定 ll qmul(ll a,ll b,ll mod)//快速乘 { ll c=(ld)a/mod*b; ll res=(ull)a*b-(ull)c*mod; return (res+mod)%mod; } ll qpow(ll a,ll n,ll mod)//快速幂 阅读全文
posted @ 2024-01-20 16:24 tju空明 阅读(146) 评论(0) 推荐(0)
摘要: 欧拉筛 bool isprime[MAXN]; // isprime[i]表示i是不是素数 int prime[MAXN]; // 现在已经筛出的素数列表 int n; // 上限,即筛出<=n的素数 int cnt; // 已经筛出的素数个数 void euler() { memset(ispri 阅读全文
posted @ 2024-01-20 16:24 tju空明 阅读(209) 评论(0) 推荐(0)
摘要: KMP void getnext(char *p) { int lenp=strlen(p); nextt[0]=-1; int k=-1; int j=0; while(j<lenp-1) { //p[k]表示前缀,p[j]表示后缀(并没有“真”!) if(k 1||p[j]==p[k])//j在 阅读全文
posted @ 2024-01-20 16:23 tju空明 阅读(17) 评论(0) 推荐(0)
摘要: 求凸包模板 const int maxn = 50010; struct Point { int x, y; bool operator < (Point const& rhs) const {//重载为类的成员函数的时候,形参时运算符//的右操作数 return (x < rhs.x) || (x 阅读全文
posted @ 2024-01-20 16:22 tju空明 阅读(13) 评论(0) 推荐(0)
摘要: 二分查找 l 对于满足条件最左边 //最终l会等于r,返回l即可 while(l<r) { int mid=(l+r)/2; //适应l=mid+1 if(check(mid)){ r=mid; } else{ l=mid+1; //确定满足条件的最左边 } } l 对于满足条件最右边 while( 阅读全文
posted @ 2024-01-20 16:21 tju空明 阅读(28) 评论(0) 推荐(0)