字符串哈希
#include<iostream>
#include<string>
using namespace std;
const int N = 100010, P = 131;
typedef unsigned long long ULL;
ULL h[N], p[N];
int n, m;
ULL query(int l, int r) {
return h[r] - h[l - 1] * p[r - l + 1];
}
int main() {
cin >> n >> m;
string s;
cin >> s;
p[0] = 1;
h[0] = 0;
for (int i = 0; i < n; i ++ ) {
p[i + 1] = p[i] * P;
h[i + 1] = h[i] * P + s[i];
}
while (m -- ) {
int l1, r1, l2, r2;
cin >> l1 >> r1 >> l2 >> r2;
if (query(l1, r1) == query(l2, r2)) cout << "Yes" << endl;
else cout << "No" << endl;
}
return 0;
}