orazma

a.cpp

May 4th, 2026
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define pb push_back
  4. #define pf push_front
  5. #define f first
  6. #define s second
  7. using namespace std;
  8.  
  9. const int MAXN = 1e6 + 10;
  10. const int MOD = 1e9 + 7;
  11.  
  12. ll hhash[MAXN], st[MAXN];
  13.  
  14. ll get(int l, int r, int n) {
  15.   return ((((hhash[r] - hhash[l - 1] + MOD) % MOD) * st[n - l]) % MOD);
  16. }
  17. int p = 43;
  18.  
  19. int main() {
  20.     string s;
  21.     cin >> s;
  22.     st[0] = 1;
  23.     int n = s.size();
  24.     for(int i = 1; i <= n; i++) {
  25.       st[i] = (st[i - 1] * p) % MOD;
  26.     }
  27.     s = '!' + s;
  28.     for(int i = 1; i <= n; i++) {
  29.       hhash[i] = (hhash[i - 1] + (s[i] - 'a' + 1) * st[i]) % MOD;
  30.     }
  31.     int q;
  32.     cin >> q;
  33.     while (q--) {
  34.       int l1, r1, l2, r2;
  35.       cin >> l1 >> r1 >> l2 >> r2;
  36.       if (get(l1, r1, n) == get(l2, r2, n)) cout << "Yes" << endl;
  37.       else cout << "No" << endl;
  38.     }
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment