#K59427. Longest Uniform Subarray

    ID: 30862 Type: Default 1000ms 256MiB

Longest Uniform Subarray

Longest Uniform Subarray

You are given an array of N integers and Q queries. For each query, you are given two indices L and R (1-indexed) representing the range of the subarray. Your task is to determine the length of the longest contiguous subarray within the given range in which all elements are equal.

Formally, for each query, consider the subarray \(a[L-1 \ldots R-1]\). Find the maximum integer \(k\) such that there exists an index \(i\) with \(L \le i \le R-k+1\) and \(a[i] = a[i+1] = \dots = a[i+k-1]\).

For example, given the array [1, 2, 2, 3, 3] and the query (1, 3), the subarray is [1, 2, 2] and the longest contiguous uniform segment is [2, 2] with a length of 2.

inputFormat

The input is read from standard input and has the following format:

  1. The first line contains an integer \(N\) which is the number of elements in the array.
  2. The second line contains \(N\) space-separated integers representing the array.
  3. The third line contains an integer \(Q\) representing the number of queries.
  4. Each of the next \(Q\) lines contains two space-separated integers \(L\) and \(R\) (1-indexed) representing a query.

outputFormat

For each query, output the length of the longest contiguous subarray with all equal elements. Each result should be printed on a new line to standard output.

## sample
5
1 2 2 3 3
3
1 3
2 4
3 5
2

2 2

</p>