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

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

1 lộ trình

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 nn integers a1,a2,…,ana_1,a_2,\ldots,a_n, indexed from 11 to nn, the true minimum of a range [l,r][l,r] is m(l,r)=min⁡l≤i≤raim(l,r)=\min_{l\le i\le r}a_i.

A student proposes a rule resembling prefix sums. Define pi=min⁡1≤j≤iajp_i=\min_{1\le j\le i}a_j for 1≤i≤n1\le i\le n. The student's guess is g(l,r)=prg(l,r)=p_r if l=1l=1, and g(l,r)=pr−pl−1g(l,r)=p_r-p_{l-1} if l>1l>1.

For every query, report the true minimum and determine whether the guess equals it. The array never changes.

Input

  • The first line contains integers n,qn,q, the array length and number of queries, respectively.
  • The second line contains nn integers a1,…,ana_1,\ldots,a_n.
  • Each of the next qq lines contains integers l,rl,r, 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): 1≤n,q≤2000001\le n,q\le200000; −109≤ai≤109-10^9\le a_i\le10^9 for every 1≤i≤n1\le i\le n; 1≤l≤r≤n1\le l\le r\le n. n,q≤100n,q\le100.
  • Subtask 2 (30 points): 1≤n,q≤2000001\le n,q\le200000; −109≤ai≤109-10^9\le a_i\le10^9 for every 1≤i≤n1\le i\le n; 1≤l≤r≤n1\le l\le r\le n. ai≤ai+1a_i\le a_{i+1} for every 1≤i<n1\le i<n.
  • Subtask 3 (50 points): 1≤n,q≤2000001\le n,q\le200000; −109≤ai≤109-10^9\le a_i\le10^9 for every 1≤i≤n1\le i\le n; 1≤l≤r≤n1\le l\le r\le n. 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 (3,3,2,2,0)(3,3,2,2,0). On [2,2][2,2] the true minimum is 7 but the guess is 3−3=03-3=0. On [2,4][2,4] the values are 2 and 2−3=−12-3=-1. On [1,3][1,3] both equal 2. On [5,5][5,5] they are 0 and 0−2=−20-2=-2.

Example 2

Input

3 2
-5 0 2
2 3
3 3

Output

0 YES
2 NO

Explanation

Both guesses equal −5−(−5)=0-5-(-5)=0. The first range has minimum 0; the second has minimum 2.