AcWing 841. 字符串哈希
原题链接
简单
作者:
代码实现困难户
,
2021-08-17 09:33:22
,
所有人可见
,
阅读 150
#include<iostream>
#include<cstring>
using namespace std;
typedef unsigned long long u;
const int P=131,N=1e5+10;
char s[N];
int n,m;
u p[N],h[N];
int get(int l,int r)
{
return h[r]-h[l-1]*p[r-l+1];
}
int main()
{
p[0]=1;
cin>>n>>m>>s;
for(int i=0;i<strlen(s);i++)
p[i+1]=p[i]*P,h[i+1]=h[i]*P+s[i];
while(m--)
{
int l1,l2,r1,r2;
cin>>l1>>r1>>l2>>r2;
if(get(l1,r1)==get(l2,r2))
cout<<"Yes";
else cout<<"No";
cout<<endl;
}
return 0;
}