## Editorial for Wesley's Anger Contest 5 Problem 2 - MATH 137 at Squirreloo

Remember to use this editorial

**only**when stuck, and**not to copy-paste code from it**. Please be respectful to the problem author and editorialist.**Submitting an official solution before solving the problem yourself is a bannable offence.**Author:

##### Subtask 1

Since , for each query we can simply iterate over the array in reverse order, breaking when we find an element that lies outside the range .

**Time Complexity:**

##### Subtask 2

The intended solution for this subtask is to maintain a suffix min and suffix max array and then binary search for the longest suffix for which the maximum and minimum elements of the suffix lie in the range . This requires preprocessing to create the suffix min/max arrays and then a binary search for each query.

**Time Complexity:**

## Comments