https://www.acwing.com/problem/content/description/140/
#include <iostream> #include <string.h> using namespace std; typedef unsigned long long ULL; const int N = 1000010, p = 131; char str[N]; // 1-indexed ULL power[N], h[N]; void init(int n) { power[0] = 1; for (int i = 1; i <= n; i ++ ) { power[i] = power[i - 1] * p; h[i] = h[i - 1] * p + str[i] - 'a'; } } ULL get(int l, int r) { return h[r] - h[l - 1] * power[r - l + 1]; } int main() { scanf("%s", str + 1); int n = strlen(str + 1); init(n); int m; scanf("%d", &m); while (m -- ) { int l1, r1, l2, r2; scanf("%d%d%d%d", &l1, &r1, &l2, &r2); if (get(l1, r1) == get(l2, r2)) puts("Yes"); else puts("No"); } return 0; }