#P4440. Anagram Substring Queries
Anagram Substring Queries
Anagram Substring Queries
Little Leticija is preparing for a programming exam. Even though she has solved a lot of tasks, there’s one still left unsolved, so she is asking you for help. You are given a word \(S\) and \(Q\) queries. In each query, you are given positive integers \(A\), \(B\), \(C\) and \(D\). Let word \(X\) be the substring of \(S\) from position \(A\) to \(B\) (inclusive) and word \(Y\) the substring from position \(C\) to \(D\) (inclusive). For each query, determine whether it is possible to rearrange the letters in \(Y\) to obtain \(X\). This is possible if and only if \(|X| = |Y|\) and the frequency of every character in \(X\) matches the frequency in \(Y\).
inputFormat
The first line contains the string \(S\). The second line contains an integer \(Q\) representing the number of queries. Each of the next \(Q\) lines contains four space-separated positive integers \(A\), \(B\), \(C\), and \(D\), specifying the start and end indices for the substrings \(X\) and \(Y\) respectively. It is assumed that positions in \(S\) are 1-indexed.
outputFormat
For each query, output a single line containing YES
if it is possible to rearrange the letters in \(Y\) to obtain \(X\), otherwise output NO
.
sample
abacaba
3
1 3 5 7
2 4 1 3
3 3 4 4
YES
NO
NO
</p>