字符串哈希
作者:
六便士
,
2022-03-12 22:43:22
,
所有人可见
,
阅读 209
#include<isotream>
using namespace std;
typedef unsigned long long ULL;
const int N = 100010,P = 131;
int n,m;
char str[N];
ULL h[N],p[N];
ULL get(int l,int r)
{
return h[r]-h[l-1] * p[r - l + 1];
}
int main()
{
scnaf("%d%d%s",&n,&m,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(l1,r1) == get(l2,r2)) put("Yes");
esle puts("No");
}
return 0;
}