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

#SRD0000072. Mode trên đoạn tĩnh (Static Range Mode Query)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Mode trên đoạn tĩnh (Static Range Mode Query)

Static Range Mode Query

Source: Library Checker

Version: Phuoc Hung OJ Extended

Problem Statement

For each half-open range [l,r)[l,r) of the zero-indexed array, output any mode value and its frequency. If several values share the maximum frequency, any one is valid.

Input

Read n,qn,q, the array, and qq half-open ranges 0≤l<r≤n0\le l<r\le n using zero-based indices.

Output

Print mode_value frequency on one line for each query.

Subtasks

  • Subtask 1 (10 points): 1≤n≤501\le n\le 50, 0≤q≤600\le q\le 60. 0≤ai≤1090\le a_i\le10^9; 0≤q0\le q; 0≤l<r≤n0\le l<r\le n.
  • Subtask 2 (20 points): 1≤n≤30001\le n\le 3000, 0≤q≤30000\le q\le 3000. 0≤ai≤1090\le a_i\le10^9; 0≤q0\le q; 0≤l<r≤n0\le l<r\le n.
  • Subtask 3 (30 points): 1≤n≤200001\le n\le 20000, 0≤q≤200000\le q\le 20000. 0≤ai≤1090\le a_i\le10^9; 0≤q0\le q; 0≤l<r≤n0\le l<r\le n.
  • Subtask 4 (40 points): 1≤n≤1000001\le n\le 100000, 0≤q≤1000000\le q\le 100000. 0≤ai≤1090\le a_i\le10^9; 0≤q0\le q; 0≤l<r≤n0\le l<r\le n.

Examples

Input

5 3
3 7 1 2 1
1 5
3 4
0 4

Output

1 2
2 1
3 1

Explanation

Range [1,5)[1,5) has values [7,1,2,1][7,1,2,1]: mode 1 appears twice. Range [3,4)[3,4) contains only 2. In [0,4)[0,4) every value occurs once, so 3 1 and any other present value paired with 1 are all valid.