字符串hash,注意hash是关键字!
#include<bits/stdc++.h> using namespace std; typedef unsigned long long ull; const int N=1000005; const ull k=10007; char a[N]; ull ha[N],p[N]; int main(){ scanf("%s",a+1); int m,len=strlen(a+1); p[0]=1; for(int i=1;i<=len;++i){ ha[i]=(ull)ha[i-1]*k+a[i]-'a'+1; p[i]=(ull)p[i-1]*k; } scanf("%d",&m); for(int i=1;i<=m;++i){ int l1,r1,l2,r2; scanf("%d%d%d%d",&l1,&r1,&l2,&r2); if(ha[r1]-ha[l1-1]*p[r1-l1+1]==ha[r2]-ha[l2-1]*p[r2-l2+1])puts("Yes"); else puts("No"); } return 0; }