PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SRD0000074. Các giá trị thường gặp (Frequent values)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Các giá trị thường gặp (Frequent values)

Frequent values

Source: SPOJ

Version: Phuoc Hung OJ Extended

Problem Statement

The given integer sequence is sorted in nondecreasing order. For each inclusive range [l,r][l,r], report the maximum number of occurrences of a single value within the range (not the value itself).

Input

Read n,qn,q, a nondecreasing array, and qq inclusive queries. There is no sentinel terminator.

Output

Print the maximum occurrence count for every range.

Subtasks

  • Subtask 1 (10 points): 1≤n≤501\le n\le 50, 1≤q≤601\le q\le 60. −100000≤ai≤100000-100000\le a_i\le100000; ai≤ai+1a_i\le a_{i+1}; 1≤l≤r≤n1\le l\le r\le n.
  • Subtask 2 (20 points): 1≤n≤40001\le n\le 4000, 1≤q≤40001\le q\le 4000. −100000≤ai≤100000-100000\le a_i\le100000; ai≤ai+1a_i\le a_{i+1}; 1≤l≤r≤n1\le l\le r\le n.
  • Subtask 3 (25 points): 1≤n≤300001\le n\le 30000, 1≤q≤300001\le q\le 30000. −100000≤ai≤100000-100000\le a_i\le100000; ai≤ai+1a_i\le a_{i+1}; 1≤l≤r≤n1\le l\le r\le n.
  • Subtask 4 (45 points): 1≤n≤1000001\le n\le 100000, 1≤q≤1000001\le q\le 100000. −100000≤ai≤100000-100000\le a_i\le100000; ai≤ai+1a_i\le a_{i+1}; 1≤l≤r≤n1\le l\le r\le n.

Examples

Input

10 3
-1 -1 1 1 1 1 3 10 10 10
2 3
1 10
5 10

Output

1
4
3

Explanation

Range [2,3]=[−1,1][2,3]=[-1,1] has maximum frequency 1. The whole array has four consecutive 1s, giving 4. Range [5,10][5,10] contains two 1s, one 3 and three 10s, giving 3.