Pondo Compare
You are given a string s of length n and q queries.
Each query gives four integers l1,r1,l2,r2. Pondo wants to know whether the substring s[l1..r1] is lexicographically less than or equal to s[l2..r2] (1-indexed, inclusive).
A string a is lexicographically smaller than b if they first differ at a position where a has the smaller character, or if a is a proper prefix of b.
Input
The first line contains two integers n and q.
The second line contains the string s.
Each of the next q lines contains four integers l1,r1,l2,r2.
Output
Print q lines. The i-th line should be YES if s[l1..r1]≤s[l2..r2]
for the i-th query, and NO otherwise.
Constraints
- 1≤n≤5×105
- 1≤q≤106
- 1≤l1≤r1≤n
- 1≤l2≤r2≤n
- s consists only of lowercase English letters.
Example 1
10 4
abcdfabcde
1 5 6 10
1 4 6 9
1 10 1 10
6 9 1 5
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
6 5
banana
2 6 1 6
1 3 4 6
2 4 5 6
1 6 1 6
3 3 2 2
YES
NO
YES
YES
NO
Explanation
ananais smaller thanbanana.banis larger thanana.anais smaller thanna.bananais equal to itself.nis larger thana.
Comments0
No comments yet
Be the first to comment.
New comment
Log in to join the discussion.