题目
![](https://i-blog.csdnimg.cn/direct/debab48b370746ee8095ef4d9b797d55.png)
代码
#include<bits/stdc++.h>
typedef unsigned long long ULL;
const int N = 1e5+10;
const int P = 131;
char str[N];
ULL h[N], p[N];
ULL get_hash(int l, int r)
{
return h[r] - h[l-1] * p[r-l+1];
}
int n, m;
int main()
{
scanf("%d%d", &n, &m);
scanf("%s", str+1);
p[0] = 1;
for(int i = 1; i <= n; i++)
{
p[i] = p[i-1] * P;
h[i] = h[i-1] * P + str[i];
}
while (m -- )
{
int l1, r1, l2, r2;
scanf(" %d %d %d %d", &l1, &r1, &l2, &r2);
if(get_hash(l1, r1) == get_hash(l2, r2)) puts("Yes");
else puts("No");
}
return 0;
}