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

#PS0000130. So sánh trung bình bằng số nguyên (Compare Range Average)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

So sánh trung bình bằng số nguyên (Compare Range Average)

Compare Range Average

Source: Phước Hưng OJ

Version: Phuoc Hung OJ Extended

Problem Statement

Given integers a1,…,ana_1,\ldots,a_n, each query specifies an inclusive interval [l,r][l,r] and integers p,dp,d with d>0d>0 representing p/dp/d. Determine whether the arithmetic mean of the entries in the interval is at least p/dp/d. Equality is accepted. The array never changes.

Input

The first line contains n,qn,q, array length and query count.

The second line contains nn integers a1,…,ana_1,\ldots,a_n.

Each of the next qq lines contains integers l,r,p,dl,r,p,d.

Output

Print qq lines; print YES if the mean is at least p/dp/d, otherwise NO.

Subtasks

  • Subtask 1 (25 points): 1≤n≤1001\le n\le100; 1≤q≤1001\le q\le100; 1≤l≤r≤n1\le l\le r\le n for each query; −109≤ai≤109-10^9\le a_i\le10^9 for every 1≤i≤n1\le i\le n; −1012≤p≤1012-10^{12}\le p\le10^{12}; 1≤d≤10121\le d\le10^{12}.
  • Subtask 2 (25 points): 1≤n≤2000001\le n\le200000; 1≤q≤2000001\le q\le200000; 1≤l≤r≤n1\le l\le r\le n for each query; −109≤ai≤109-10^9\le a_i\le10^9 for every 1≤i≤n1\le i\le n; −1000≤p≤1000-1000\le p\le1000; 1≤d≤10001\le d\le1000.
  • Subtask 3 (50 points): 1≤n≤2000001\le n\le200000; 1≤q≤2000001\le q\le200000; 1≤l≤r≤n1\le l\le r\le n for each query; −109≤ai≤109-10^9\le a_i\le10^9 for every 1≤i≤n1\le i\le n; −1012≤p≤1012-10^{12}\le p\le10^{12}; 1≤d≤10121\le d\le10^{12}.

Example 1

Input

3 2
1 3 5
1 3 3 1
1 2 3 1

Output

YES
NO

Explanation

The mean of 1–3 is (1+3+5)/3=3(1+3+5)/3=3, equal to 3/13/1. The mean of 1–2 is (1+3)/2=2(1+3)/2=2, below 3.

Example 2

Input

3 3
-5 -2 4
1 2 -7 2
1 2 -3 1
3 3 3999999999 1000000000

Output

YES
NO
YES

Explanation

The first two entries average −7/2-7/2, equal to the first threshold but smaller than −3-3. The final entry is 4, above 3999999999/10000000003999999999/1000000000.