PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000317. Bẫy hiệu hai tiền tố nhỏ nhất (Minimum Prefix Trap)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Bẫy hiệu hai tiền tố nhỏ nhất (Minimum Prefix Trap)
Minimum Prefix Trap
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given an array of integers , indexed from to , the true minimum of a range is .
A student proposes a rule resembling prefix sums. Define for . The student's guess is if , and if .
For every query, report the true minimum and determine whether the guess equals it. The array never changes.
Input
- The first line contains integers , the array length and number of queries, respectively.
- The second line contains integers .
- Each of the next lines contains integers , the endpoints of the range.
Output
For each query print the true minimum and YES if the guess is correct, or NO otherwise, separated by a space.
Subtasks
- Subtask 1 (20 points): ; for every ; . .
- Subtask 2 (30 points): ; for every ; . for every .
- Subtask 3 (50 points): ; for every ; . Array elements may be equal or distinct and in any order.
Example 1
Input
5 4
3 7 2 5 0
2 2
2 4
1 3
5 5
Output
7 NO
2 NO
2 YES
0 NO
Explanation
The prefix minima are . On the true minimum is 7 but the guess is . On the values are 2 and . On both equal 2. On they are 0 and .
Example 2
Input
3 2
-5 0 2
2 3
3 3
Output
0 YES
2 NO
Explanation
Both guesses equal . The first range has minimum 0; the second has minimum 2.