#include <bits/stdc++.h>
using namespace std;

int main() {
    int q,a,b;
    string S,T;
    cin>>q>>S>>T;
    int s=S.size();
    int t=T.size();

    if(s < t){
        for(int i=0;i<q;i++){
            cin>>a>>b;
            cout<<"No"<<endl;
        }
        return 0;
    }
    
    vector<int> P(s-t+2);
    for(int i=0;i<=s-t;i++){
        if(S[i]==T[0]){
            b=0;
            for(int k=1;k<t;k++){
                if(S[i+k]!=T[k]){
                    b=1;
                }
            }
            if(b==1){
                if(i==0){
                    P[i]=0;
                }else{
                    P[i]=P[i-1];
                }
            }else{
                if(i==0){
                    P[i]=1;
                }else{
                    P[i]=P[i-1]+1;
                }
            }
        }else{
            if(i==0){
                P[i]=0;
            }else{
                P[i]=P[i-1];
            }
        }
    }

    for(int i=0;i<q;i++){
        cin>>a>>b;
        if(b-a+1>=t){
            if(a==1){
                if(P[b-t]>0){
                    cout<<"Yes"<<endl;
                }else{
                    cout<<"No"<<endl;
                }
            }else{
                if(P[b-t]-P[a-2]>0){
                    cout<<"Yes"<<endl;
                }else{
                    cout<<"No"<<endl;
                }
            }
        }else{
            cout<<"No"<<endl;
        }
    }
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: