You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
683 B

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ULL;
const int N = 100010;
const int P = 131;
int n, m;
string str;
ULL h[N], b[N];
ULL get(int l, int r) {
return h[r] - h[l - 1] * b[r - l + 1];
}
int main() {
cin >> n >> m >> str;
b[0] = 1; // p^0=1,初始化
for (int i = 1; i <= n; i++) {
b[i] = b[i - 1] * P; // 基数
h[i] = h[i - 1] * P + str[i - 1]; // 前缀和
}
while (m--) {
int l1, r1, l2, r2;
cin >> l1 >> r1 >> l2 >> r2;
if (get(l1, r1) == get(l2, r2))
puts("Yes");
else
puts("No");
}
return 0;
}