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 s of length n and q queries.

Each query gives four integers l_1, r_1, l_2, r_2. Pondo wants to know whether the substring s[l_1 .. r_1] is lexicographically less than or equal to s[l_2 .. r_2] (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 l_1, r_1, l_2, r_2.

Output

Print q lines. The i-th line should be YES if s[l_1 .. r_1] \le s[l_2 .. r_2] for the i-th query, and NO otherwise.

Constraints

  • 1 \le n \le 5 \times 10^5
  • 1 \le q \le 10^6
  • 1 \le l_1 \le r_1 \le n
  • 1 \le l_2 \le r_2 \le n
  • s 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
  • abcdf is not less than or equal to abcde.
  • abcd is less than or equal to abcd.
  • abcdfabcde is less than or equal to itself.
  • abcd is a proper prefix of abcdf.

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
  • anana is smaller than banana.
  • ban is larger than ana.
  • ana is smaller than na.
  • banana is equal to itself.
  • n is larger than a.

Comments

There are no comments at the moment.