AcWing 138. 兔子与兔子
原题链接
简单
字符串hash的模板题,没啥好说的.
C++ 代码
#include<iostream>
using namespace std;
#include<string.h>
typedef unsigned long long ULL;
ULL h[1000010];
ULL p[1000010];
ULL get(ULL h[],ULL p[],int l,int r)
{
return (h[r]-h[l-1]*p[r-l+1]);
}
int main()
{
string str;
cin>>str;
p[0]=1;
h[0]=0;
for(int i=1;i<=str.size();i++)
{
h[i]=h[i-1]*131+str[i-1]-'a'+1;
p[i]=p[i-1]*131;
}
int m;
cin>>m;
while(m--)
{
int l1,r1,l2,r2;
cin>>l1>>r1>>l2>>r2;
cout<<(get(h,p,l1,r1)==get(h,p,l2,r2)?"Yes":"No")<<endl;
}
return 0;
}