#P3293. [SCOI2016] 美味

[SCOI2016] 美味

Description

A restaurant has nn dishes, numbered 1,2,,n1, 2, \ldots, n. The evaluation value of dish ii is aia_i. There are mm customers. The ii-th customer's expected value is bib_i, and their preference value is xix_i. Therefore, the ii-th customer considers the deliciousness of dish jj to be bi(aj+xi)b_i \oplus (a_j + x_i), where \oplus denotes the XOR operation.

The ii-th customer wants to pick the dish they consider the most delicious, i.e., the one with the maximum deliciousness value, but due to price and other factors, they can only choose from dishes lil_i through rir_i. Please help them find the most delicious dish.

Input Format

The first line contains two integers n,mn, m, the number of dishes and the number of customers.

The second line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n, the evaluation value of each dish.

Lines 33 to m+2m + 2 each contain four integers b,x,l,rb, x, l, r, indicating the customer's expected value, preference value, and the allowed range of dishes.

Output Format

Output mm lines, each containing one integer, the maximum deliciousness value chosen by that customer.

4 4
1 2 3 4
1 4 1 4
2 3 2 3
3 2 3 3
4 1 2 4
9 
7 
6 
7

Hint

Constraints.

For 100%100\% of the testdata, it holds that 1n2×1051 \le n \le 2 \times 10^5, 0ai,bi,xi<1050 \le a_i, b_i, x_i < 10^5, 1lirin1 \le l_i \le r_i \le n (1im1 \le i \le m), 1m1051 \le m \le 10^5.

Translated by ChatGPT 5