#include "iostream"
#include "cstring"
using namespace std;
typedef unsigned long long ll;
const int N = 10000010;
char str[N];
ll Hash[N], p[N];
int main() {
cin >> (str + 1);
int n = strlen(str + 1);
p[0] = 1;
for(int i = 1; i <= n; ++i) {
Hash[i] = Hash[i - 1] * 131 + str[i] - 'a' + 1;
p[i] = p[i - 1] * 131;
}
int m;
cin >> m;
for(int i = 1; i <= m; ++i) {
int l, r;
cin >> l >> r;
cout << Hash[r] - Hash[l - 1] * p[r - l + 1] << endl;
}
return 0;
}
Hash模板
最新推荐文章于 2024-01-28 14:09:34 发布