AcWing 841. 字符串哈希
原题链接
简单
作者:
HalfSummer
,
2020-05-04 17:58:34
,
所有人可见
,
阅读 512
#include<iostream>
#include<cmath>
using namespace std;
const int P = 13331;
char s[100010];
unsigned long long h[100010] , p[100010];
unsigned long long get(int l,int r){
return h[r] - h[l - 1] * p[r - l + 1];
}
int main(){
int n ,m ;
cin >> n >> m;
for(int i = 1; i <= n;i ++) cin >> s[i];
p[0] = 1;
for(int i = 1;i <= n; i ++){
p[i] = p[i - 1] * P;
h[i] = h[i - 1] * P + s[i];
}
int l1,r1,l2,r2;
while(m --){
cin >> l1 >> r1 >> l2 >> r2;
if(get(l1, r1) == get(l2, r2)) cout << "Yes" <<endl;
else cout << "No" << endl;
}
return 0;
}