#P11110. [ROI 2023] 陶陶装苹果 (Day 2)

[ROI 2023] 陶陶装苹果 (Day 2)

Background

Translated from ROI 2023 D2T3

Tao Tao has nn apples with integer weights w1,w2,,wnw_1,w_2,\dots,w_n. They are placed on a table, and there are also two baskets with large enough capacity.

Tao Tao chooses an integer kk. For each apple with weight wikw_i \le k, he may put it into one of the baskets, or leave it on the table. Apples with weight greater than kk will always remain on the table.

If Tao Tao can place the apples of weight at most kk into the baskets so that the total weight of apples in the first basket equals xx, and the total weight of apples in the second basket equals yy, then (x,y)(x, y) is called a reachable pair for kk. If for all xx and yy satisfying 0xa0 \le x \le a and 0yb0 \le y \le b, (x,y)(x, y) is a reachable pair for kk, then (a,b)(a, b) is called k ⁣k-\! perfect.

Problem Description

Tao Tao will ask you qq times. For each triple (k,a,b)(k,a,b), determine whether (a,b)(a, b) is k ⁣k-\! perfect.

Input Format

The first line contains two integers nn and qq, representing the number of apples Tao Tao has and the number of queries to process (1n,q300,0001 \le n, q \le 300,000).

The second line contains nn integers w1,w2,,wnw_1,w_2,\dots,w_n, representing the weights of the apples (1wi10121 \le w_i \le 10^{12}).

The third line contains an integer zz, which will be used in the following input (0z1060 \le z \le 10^6).

The next qq lines describe the queries. Queries are numbered from 11 to qq. Each line contains three integers j,c,dj,c,d (0j,c,d10180 \le j, c, d \le 10^{18}), meaning that in this query $k = j - v \times z,a = c - v \times z,b = d - v \times z$, where vv is the sum of the indices of the previous queries whose answers were Yes. It is guaranteed that k,a,b0k,a,b \ge 0.

In this problem, for most testdata, zz equals 00. In this case, the values of k,a,bk,a,b are j,c,dj,c,d, respectively.

Output Format

For each query, if the pair (a,b)(a, b) is k ⁣k-\! perfect in that query, output Yes; otherwise output No.

8 5
17 1 3 2 100 5 6 1
0
6 15 3
9 4 4
5 15 3
17 34 1
16 33 2
Yes
No
No
Yes
No
8 5
17 1 3 2 100 5 6 1
1
6 15 3
10 5 5
6 16 4
18 35 2
21 38 7
Yes
No
No
Yes
No

Hint

Translated by ChatGPT 5