O(1)查询
int P = 131; //或者13331
char str[100005];
ull h[100005], p[100005];
ull get(int l, int r)
{
return h[r] - h[l - 1] * p[r - l + 1];
}
int main()
{
int n, m;
cin >> n >> m >> str + 1;
p[0] = 1;
for (int i = 1; i <= n; i++)//计算子串str[l ~ r]的哈希值
{
p[i] = p[i - 1] * P;
h[i] = h[i - 1] * P + str[i];
}
while (m--)
{
int l1, r1, l2, r2;
cin >> l1 >> r1 >> l2 >> r2;
if (get(l1, r1) == get(l2, r2))//比较子串str[l1 ~ r1]的哈希值与子串str[l2 ~ r2]的哈希值是否一致
{
cout << "Yes" << endl;
}
else
{
cout << "No" << endl;
}
}
return 0;
}