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

#SRD0000003. Truy vấn giá trị nhỏ nhất trên đoạn tĩnh (Static Range Minimum Queries)

HỌC THEO LỘ TRÌNH

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

3 lộ trình

Truy vấn giá trị nhỏ nhất trên đoạn tĩnh (Static Range Minimum Queries)

Static Range Minimum Queries

Source: CSES

Version: Phuoc Hung OJ Extended

Problem Statement

Given an array of nn integers and qq queries, find the minimum value within each inclusive interval [a,b][a,b]. The array remains unchanged. If the minimum occurs several times, print its value only.

Input

The first line contains n,qn,q, followed by a line with nn integers xix_i. Each of the following qq lines contains a,ba,b for an inclusive range-minimum query.

Output

For each query requesting a result, output one integer on its own line in input order. Update operations produce no output.

Subtasks

  • Subtask 1 (20 points): 1≤n≤2001\le n\le 200; 1≤q≤2001\le q\le 200; 1≤a≤b≤n1\le a\le b\le n for every query and 1≤xi≤1091\le x_i\le 10^9 for all ii.
  • Subtask 2 (25 points): 1≤n≤50001\le n\le 5000; 1≤q≤50001\le q\le 5000; 1≤a≤b≤n1\le a\le b\le n for every query and 1≤xi≤1091\le x_i\le 10^9 for all ii.
  • Subtask 3 (55 points): 1≤n≤2000001\le n\le 200000; 1≤q≤2000001\le q\le 200000; 1≤a≤b≤n1\le a\le b\le n for every query and 1≤xi≤1091\le x_i\le 10^9 for all ii.

Examples

Input

8 4
3 2 4 5 1 1 5 3
2 4
5 6
1 8
3 3

Output

2
1
1
4

Explanation

The minimum in [2,4][2,4] is 22, in [5,6][5,6] it is 11, and in the entire array it is 11. The single-element range [3,3][3,3] has minimum 44.