Advertisement
VladSmirN

хэши

Nov 18th, 2020 (edited)
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.41 KB | None | 0 0
  1. ll MD  = 1000000009;
  2. ll L  = 53;
  3. ll MAXSIZE = 200005;
  4. vector<ll>st(MAXSIZE,0);
  5. vector<ll> createHash(string s){
  6.     vector<ll>h(s.size()+1,0);
  7.     for(int i=0;i<s.size();++i){
  8.         h[i+1] = (h[i]*L +s[i])%MD;
  9.     }
  10.     return h;
  11. }
  12. ll getHash(vector<ll>&h ,ll l,ll r){
  13.     return (h[r] - h[l-1]*st[r-l+1] +MD*MD)%MD;
  14. }
  15.  
  16. st[0] = 1;
  17.     for(int i=1;i<MAXSIZE;++i){
  18.         st[i] = (st[i-1]*L)%MD;
  19.     }
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement