You are given a string s of length n consisting of lowercase English letters.
For two given strings s and t, say S is the set of distinct characters of s and T is the set of distinct characters of t. The strings s and t are isomorphic if their lengths are equal and there is a one-to-one mapping (bijection) f between S and T for which f(si) = ti. Formally:
- f(si) = ti for any index i,
- for any character
there is exactly one character
that f(x) = y,
- for any character
there is exactly one character
that f(x) = y.
For example, the strings "aababc" and "bbcbcz" are isomorphic. Also the strings "aaaww" and "wwwaa" are isomorphic. The following pairs of strings are not isomorphic: "aab" and "bbb", "test" and "best".
You have to handle m queries characterized by three integers x, y, len (1 ≤ x, y ≤ n - len + 1). For each query check if two substrings s[x... x + len - 1] and s[y... y + len - 1] are isomorphic.
The first line contains two space-separated integers n and m (1 ≤ n ≤ 2·105, 1 ≤ m ≤ 2·105) — the length of the string s and the number of queries.
The second line contains string s consisting of n lowercase English letters.
The following m lines contain a single query on each line: xi, yi and leni (1 ≤ xi, yi ≤ n, 1 ≤ leni ≤ n - max(xi, yi) + 1) — the description of the pair of the substrings to check.
For each query in a separate line print "YES" if substrings s[xi... xi + leni - 1] and s[yi... yi + leni - 1] are isomorphic and "NO" otherwise.
7 4 abacaba 1 1 1 1 4 2 2 1 3 2 4 3
YES YES NO YES
The queries in the example are following:
- substrings "a" and "a" are isomorphic: f(a) = a;
- substrings "ab" and "ca" are isomorphic: f(a) = c, f(b) = a;
- substrings "bac" and "aba" are not isomorphic since f(b) and f(c) must be equal to a at same time;
- substrings "bac" and "cab" are isomorphic: f(b) = c, f(a) = a, f(c) = b.
#define happy
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
const ll INF=1e18;
const int MOD=1e9+7;
ll rd(){
ll x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
template<class T>
pair<T,T> operator+(const pair<T,T> &l,const pair<T,T>& r){
return {(l.f+r.f)%MOD,(l.s+r.s)%MOD};
}
template<class T>
pair<T,T> operator-(const pair<T,T> &l,const pair<T,T>& r){
return {(l.f-r.f+MOD)%MOD,(l.s-r.s+MOD)%MOD};
}
template<class T>
pair<T,T> operator*(const pair<T,T> &l,const T& r){
return {(l.f*r)%MOD,(l.s*r)%MOD};
}
template<class T>
pair<T,T> operator*(const pair<T,T> &l,const pair<T,T>& r){
return {(l.f*r.f)%MOD,(l.s*r.s)%MOD};
}
array<pl,26> operator-(const array<pl,26>&a,const array<pl,26>&b){
array<pl,26> c;rep(i,0,25)c[i]=a[i]-b[i];
return c;
}
array<pl,26> operator*(const pl &a,const array<pl,26>&b){
array<pl,26> c;rep(i,0,25)c[i]=b[i]*a;
return c;
}
struct hsh{
string S;
vector<pl> po,ipo;
vector< array<pl,26> >cum;
pl base,invbase;
ll modpow(ll b,ll p){
return !p?1:modpow(b*b%MOD,p/2)*(p&1?b:1)%MOD;
}
ll inv(ll x){
return modpow(x,MOD-2);
}
void gen(string _S){
S=_S;
po.resize(sz(S)),ipo.resize(sz(S)),cum.resize(sz(S)+1);
po[0]=ipo[0]={1,1};
base.s=rand()%MOD;
base.f=rand()%MOD;
invbase.s=inv(base.s);
invbase.f=inv(base.f);
rep(i,1,sz(S)-1){
po[i]=po[i-1]*base;
ipo[i]=ipo[i-1]*invbase;
}
rep(i,0,sz(S)-1){
cum[i+1]=cum[i];
cum[i+1][S[i]-'a']=cum[i+1][S[i]-'a']+po[i];
}
}
vpl get(int l,int r){
array<pl,26> a=ipo[l]*(cum[r+1]-cum[l]);
vpl z;rep(i,0,25)z.pb(a[i]);
sort(all(z));
return z;
}
};
hsh H;
int main(){
#ifdef happy
freopen("in.txt","r",stdin);
#endif
int n=rd(),m=rd();
string t;
cin>>t;
H.gen(t);
rep(i,0,m-1){
int x=rd()-1,y=rd()-1,len=rd();
if(H.get(x,x+len-1)==H.get(y,y+len-1))
puts("YES");
else puts("NO");
}
}