标签:
typedef long long ll; typedef unsigned long long ull; const int MAGIC = 131; long long h[N], base[N]; long long MOD = (long long)1e9 + 7; inline void Hash(char *s) { int l = strlen(s); h[0] = 1; for (int i = 1; i <= l; ++i) h[i] = (h[i - 1] * MAGIC % MOD + s[i - 1] - 'a') % MOD; base[0] = 1; for (int i = 1; i <= l; ++i) base[i] = (base[i - 1] * MAGIC) % MOD; } inline long long get(int l, int r) { return (h[r] - h[l - 1] * base[r - l + 1] % MOD + MOD) % MOD; }
标签:
原文地址:http://blog.csdn.net/qq574857122/article/details/44905101