AcWing 841. 字符串哈希
原题链接
简单
作者:
大大怪0_0
,
2021-04-30 18:10:56
,
所有人可见
,
阅读 266
#include <iostream>
using namespace std;
typedef unsigned long long ull;
const int N = 100010;
int P = 131;
ull h[N], p[N];
int n, m;
char str[N];
int get(int l, int r)
{
return h[r] - h[l-1] * p[r-l+1];
}
int main()
{
cin >> n >> m;
scanf("%s", str + 1);
p[0] = 1;
for(int i = 1; i <= n; i ++)
{
p[i] = p[i - 1] * P;
h[i] = h[i-1] * P + str[i];
}
while(m --)
{
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
if(get(x1, y1) == get(x2, y2)) cout << "Yes" << endl;
else cout << "No" << endl;
}
return 0;
}