const ull P = 131;
ull h[maxn], po[maxn]; //h存hash,po存P^n
int l[3], r[3];
char s[maxn]; //输入串
ull geth(int l, int r) { //返回s[l,r]的hash值
return h[r] - h[l - 1] * po[r - l + 1];
}
int main() {
int T, len, m;
ull temp;
//sci(T);
T = 1;
po[0] = 1;
for (int i = 1; i < maxn; i++) {
po[i] = po[i - 1] * P;
}
while (T--){
scanf("%s", s);
len = strlen(s);
for (int i = 0; i < len; i++) {
h[i] = h[i-1] * P + (ull)s[i];
}
sci(m);
while (m--){
for (int i = 1; i <= 2; i++) {
sci(l[i]); sci(r[i]);
}
if (geth(l[1] - 1, r[1] - 1) == geth(l[2] - 1, r[2] - 1))printf("Yes\n");
else printf("No\n");
}
}
return 0;
}
hash
最新推荐文章于 2024-02-28 15:30:29 发布