推荐使用双哈希减少碰撞概率
#include <bits/stdc++.h>
using namespace std;
using u64 = uint64_t;
template <u64 seed, u64 mod = 998244353, class T = string>
struct Hash {
vector<u64> h, p;
Hash(T a) {
int n = a.size();
h.assign(n + 1, 0);
p.assign(n + 1, 1);
for (int i = 0; i < n; ++ i) {
h[i + 1] = (h[i] * seed + a[i]) % mod;
p[i + 1] = (p[i] * seed) % mod;
}
}
u64 get(int l, int r) {
return (h[r] + mod - h[l - 1] * p[r - l + 1] % mod) % mod;
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
string s;
cin >> s;
Hash<131, 1000000007> f(s);
Hash<13331, 998244353> g(s);
while (m -- ) {
int a, b, c, d;
cin >> a >> b >> c >> d;
if (f.get(a, b) == f.get(c, d) && g.get(a, b) == g.get(c, d)) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
return 0;
}