Skip to content

Commit

Permalink
Merge pull request #5 from LogSingleDog/master
Browse files Browse the repository at this point in the history
update hash
  • Loading branch information
LogSingleDog authored Jul 22, 2024
2 parents 481dff7 + c6889ff commit c6e74a5
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions 1-字符串.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,49 @@ ull get(int l, int r)
return (Hash[r] - (Hash[l - 1] * base[r - l + 1]) % mod + mod) % mod;
}
```
### Our Hash
```cpp
const int N = 1050000;
array<int,2> mod = {1572869,6291469};
array<int,2> bas = {131,137};
array<int,2> base[N];
string a;
int lena;
array<int,2> hasha[N];
void init(){
ll tmp1;
base[0] = {1,1};
for(int i=1;i<=N*2-2;i++){
for(int j=0;j<2;j++){
tmp1 = 1ll*base[i-1][j]*bas[j];tmp1%=mod[j];
base[i][j] = tmp1%mod[j];
}
}
}
void geta(){
hasha[0] = {0,0};
ll tmp1;
for(int i=1;i<=2*lena;i++){
for(int j=0;j<2;j++){
tmp1 = 1ll*hasha[i-1][j]*base[1][j];
tmp1%=mod[j];
hasha[i][j] = tmp1+a[i] - 'A';
hasha[i][j]%=mod[j];
}
}
}
array<int,2> cala(int l){
array<int,2> res={0,0};
int r = l+lena-1;
ll tmp1;
for(int i=0;i<2;i++){
tmp1 = 1ll*hasha[l-1][i]*base[r-l+1][i];tmp1%=mod[i];
res[i] = (hasha[r][i]-(tmp1)%mod[i]+mod[i])%mod[i];
res[i]%=mod[i];
}
return res;
}
```



Expand Down

0 comments on commit c6e74a5

Please sign in to comment.