-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhash.cpp
More file actions
67 lines (47 loc) · 1.26 KB
/
hash.cpp
File metadata and controls
67 lines (47 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <bits/stdc++.h>
using namespace std;
#define MAINRET(x) in##x
#define what_is(x) cout << #x << " is " << x << endl;
#define LL long long
#define arr2 array<int,2>
#define arr3 array<int,3>
void solve();
MAINRET(t) main(void) {
std::cin.tie(nullptr);
std::cin.sync_with_stdio(false);
solve();
}
constexpr int INF = std::numeric_limits<int>::max() / 2;
constexpr int NINF = -INF;
constexpr LL MX = 3 * 1e5;
constexpr int MD = (int)1e9 + 7;
int n, m, k;
struct hashes {
int base, inv, mod, sz;
vector<long long> powers = {1}, invpowers = {1}, psa = {0};
hashes(string s, int m = 1000000007, int b = 131) {
sz = s.size();
base = b;
mod = m;
inv = 1;
long long cur = base;
int exp = m - 2;
for (int exp=m-2; exp; exp>>=1) {
if (exp&1) inv = inv * cur % m;
cur = cur * cur % m;
}
for (int i=0; i<s.size(); i++) {
powers.push_back(powers.back()*base%mod);
invpowers.push_back(invpowers.back()*inv%mod);
psa.push_back((psa.back()+s[i]*powers[i])%mod);
}
}
hashes() {}
long long get(int l, int r) {
return (psa[r+1]-psa[l]+mod)*invpowers[l]%mod;
}
};
void solve() {
}
/*
*/