Pondo Compare
View as PDF
Submit solution
Points:
100
Time limit:
2.0s
PyPy 3
8.0s
Python 3
8.0s
Memory limit:
500M
Problem type
You are given a string of length
and
queries.
Each query gives four integers . Pondo wants to know whether the
substring
is lexicographically less than or equal to
(1-indexed, inclusive).
A string is lexicographically smaller than
if they first differ at a position
where
has the smaller character, or if
is a proper prefix of
.
Input
The first line contains two integers and
.
The second line contains the string .
Each of the next lines contains four integers
.
Output
Print lines. The
-th line should be
YES if
for the
-th query, and
NO otherwise.
Constraints
consists only of lowercase English letters.
Example 1
Input
10 4
abcdfabcde
1 5 6 10
1 4 6 9
1 10 1 10
6 9 1 5
Output
NO
YES
YES
YES
Explanation
abcdfis not less than or equal toabcde.abcdis less than or equal toabcd.abcdfabcdeis less than or equal to itself.abcdis a proper prefix ofabcdf.
Example 2
Input
6 5
banana
2 6 1 6
1 3 4 6
2 4 5 6
1 6 1 6
3 3 2 2
Output
YES
NO
YES
YES
NO
Explanation
ananais smaller thanbanana.banis larger thanana.anais smaller thanna.bananais equal to itself.nis larger thana.
Comments