字符串哈希
作者:
L_566
,
2024-03-25 15:57:47
,
所有人可见
,
阅读 4
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int N=100010,P=131;
typedef unsigned long long ULL;
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];
}
signed main()
{
cin>>n>>m;
scanf("%s",str+1);
p[0]=1;
for(int i=1;i<=n;i++)
{
h[i]=h[i-1]*P+str[i];
p[i]=p[i-1]*P;
}
while(m--)
{
int l1,r1,l2,r2;
cin>>l1>>r1>>l2>>r2;
if(get(l1,r1)==get(l2,r2))
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
}
return 0;
}