Loading... ```cpp #include<bits/stdc++.h> using namespace std; const int N = 1010, P = 131; unsigned long long h[N], p[N]; int n, m; char str[N]; unsigned long long gethash(int l, int r){ return h[r] - h[l - 1] * p[r - l + 1]; } int main(){ scanf("%d %d %s", &n, &m, 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]; } int l1, r1, l2, r2; while(m--){ scanf("%d %d %d %d", &l1, &r1, &l2, &r2); if(gethash(l1, r1) == gethash(l2, r2)) printf("Yes\n"); else printf("No\n"); } return 0; } ``` Last modification:February 2, 2023 © Allow specification reprint Like 0 如果觉得我的文章对你有用,请随意赞赏
Comment here is closed