CSES - Static Range Minimum Queries

Xem dạng PDF

Gửi bài giải

Điểm: 1,00 (OI)
Giới hạn thời gian: 1.0s
Giới hạn bộ nhớ: 512M
Input: stdin
Output: stdout

Nguồn bài:
https://cses.fi/problemset/task/1647
Dạng bài
Ngôn ngữ cho phép
C, C++, Java, Kotlin, Pascal, PyPy, Python, Scratch

Given an array of ~n~ integers, your task is to process ~q~ queries of the form: what is the minimum value in range ~[a,b]~?

Input

  • The first input line has two integers ~n~ and ~q~: the number of values and queries.

The second line has ~n~ integers ~x\_1,x\_2,\dots,x\_n~: the array values.

Finally, there are ~q~ lines describing the queries. Each line has two integers ~a~ and ~b~: what is the minimum value in range ~[a,b]~?

Output

  • Print the result of each query.

Constraints

  • ~1 \le n,q \le 2 \cdot 10^5~
  • ~1 \le x\_i \le 10^9~
  • ~1 \le a \le b \le n~

Example Input

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

Example Output

2
1
1
4

Bình luận

Hãy đọc nội quy trước khi bình luận.


Không có bình luận tại thời điểm này.