Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct strhash {
- int n;
- vector <ll> st, h, h2;
- void build(string s, int pr) {
- st.resize(s.size() + 1);
- h.resize(s.size() + 1);
- h2.resize(s.size() + 1);
- n = s.size();
- s = "*" + s;
- st[0] = 1;
- for (int i = 1; i <= n; i++) {
- st[i] = (st[i - 1] * pr) % MOD;
- }
- for (int i = 1; i <= n; i++) {
- h[i] = (h[i - 1] * pr + s[i]) % MOD;
- h2[i] = (h2[i - 1] * pr + s[i]) % MOD2;
- }
- }
- pair <ll, ll> get(int l, int r) {
- 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};
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement