
hash
秘制函数
记录学习算法的过程
展开
-
acwing.字符串哈希(hash)
如果用s.substr(),总的时间复杂度为O(m*len),最坏为O(m*n)会超时。#include<bits/stdc++.h>using namespace std;int main(){ int n,m; cin>>n>>m; string s; cin>>s; s='.'+s; for(int i=1;i<=m;i++){ int l1,l2,r1,r2; cin>>l1>>r1>原创 2022-03-24 23:19:45 · 734 阅读 · 0 评论 -
acwing.模拟散列表(hash)
拉链法:#include<bits/stdc++.h>using namespace std;const int N=100003;//取距离最大范围最近的一个质数(大于最大范围且尽可能地远离2的整数次幂)int h[N],e[N],ne[N],idx;void haing(int x){ int a=(x%N+N)%N; e[idx]=x; ne[idx]=h[a]; h[a]=idx; idx++;}bool find(int x){ int a=(x%N+原创 2022-03-23 16:11:02 · 968 阅读 · 0 评论