1 #include<bits/stdc++.h> 2 using namespace std; 3 const int size=1000005,p=131; 4 typedef unsigned long long ULL;//自然溢出 5 ULL f[size],key[size]; 6 int n,T,l1,r1,l2,r2; 7 char tmp[size]; 8 int main(){ 9 scanf("%s",tmp+1); 10 int len=strlen(tmp+1);f[0]=1; 11 for(int i=1;i<=len;++i) key[i]=key[i-1]*p+(ULL)tmp[i],f[i]=f[i-1]*p; 12 //按p进制计算 f数组预处理p的幂 13 scanf("%d",&T); 14 while(T--) 15 { 16 scanf("%d%d%d%d",&l1,&r1,&l2,&r2); 17 if(key[r1]-key[l1-1]*f[r1-l1+1]==key[r2]-key[l2-1]*f[r2-l2+1]) 18 //相当于两段补0对齐相减 判断hash是否相等 19 puts("Yes"); 20 else puts("No"); 21 } 22 return 0; 23 }