Advertisement
Alickon

Untitled

Oct 28th, 2023
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. struct strhash {
  2. int n;
  3. vector <ll> st, h, h2;
  4. void build(string s, int pr) {
  5. st.resize(s.size() + 1);
  6. h.resize(s.size() + 1);
  7. h2.resize(s.size() + 1);
  8. n = s.size();
  9. s = "*" + s;
  10. st[0] = 1;
  11. for (int i = 1; i <= n; i++) {
  12. st[i] = (st[i - 1] * pr) % MOD;
  13. }
  14. for (int i = 1; i <= n; i++) {
  15. h[i] = (h[i - 1] * pr + s[i]) % MOD;
  16. h2[i] = (h2[i - 1] * pr + s[i]) % MOD2;
  17. }
  18. }
  19. pair <ll, ll> get(int l, int r) {
  20. return {(h[r] - (h[l - 1] * st[r - l + 1]) % MOD + MOD) % MOD, (h2[r] - (h2[l - 1] * st[r - l + 1]) % MOD2 + MOD2) % MOD2};
  21. }
  22. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement