| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 
 | #include <bits/stdc++.h>#include <iostream>
 #include <algorithm>
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
 using namespace std;
 #define LL long long
 #define ll long long
 #define ULL unsigned long long
 #define ls rt<<1
 #define rs rt<<1|1
 #define MS 1000009
 #define INF 1e18
 #define mod 998244353
 #define Pi acos(-1.0)
 #define Pair pair<LL,LL>
 #define B1 131
 #define B2 13331
 
 LL n,m,k;
 char s[MS];
 LL hs;
 ULL bp[2][MS];
 ULL ha[2][MS],tha;
 
 void init_bp(){
 bp[0][0] = bp[1][0] = 1;
 for(int i=1;i<=hs;i++){
 bp[0][i] = bp[0][i-1]*B1;
 bp[1][i] = bp[1][i-1]*B2;
 }
 }
 
 void add_ha(int x){
 ++tha;
 ha[0][tha] = ha[0][tha-1]*B1 + x;
 ha[1][tha] = ha[1][tha-1]*B2 + x;
 }
 
 LL get_ha(int wh,int l,int r){
 return ha[wh][r] - ha[wh][l-1]*bp[wh][r-l+1];
 }
 
 int main() {
 ios::sync_with_stdio(false);
 cin >> s+1;
 hs = strlen(s+1);
 init_bp();
 for(int i=1;i<=hs;i++){
 add_ha(s[i]-'a'+1);
 }
 cin >> m;
 while(m--){
 LL l1,r1,l2,r2;
 cin >> l1 >> r1 >> l2 >> r2;
 if(get_ha(0,l1,r1) == get_ha(0,l2,r2) && get_ha(1,l1,r1) == get_ha(1,l2,r2)) cout << "Yes\n";
 else cout << "No\n";
 }
 
 
 return 0;
 }
 
 |