#P83. [CSP-S 2022] Multiplication game

[CSP-S 2022] Multiplication game

Person in Charge

Problem Description

Little L and Little Q are playing a strategy game.

Given an array AA of length nn and an array BB of length mm, we define an n×mn \times m matrix CC such that Cij=Ai×BjC_{ij} = A_i \times B_j. All indices start from 11.

The game consists of qq rounds. For each round, four parameters l1,r1,l2,r2l_1, r_1, l_2, r_2 are given in advance, satisfying 1l1r1n1 \le l_1 \le r_1 \le n and 1l2r2m1 \le l_2 \le r_2 \le m.

In each round, Little L first selects an index xx in the range [l1,r1][l_1, r_1], then Little Q selects an index yy in the range [l2,r2][l_2, r_2]. The score of both players for this round is defined as CxyC_{xy}.

Little L aims to maximize this score, while Little Q aims to minimize it. Both players are sufficiently smart and will always adopt the optimal strategy in each move.

Please find the score obtained in each round under their optimal strategies.

Input Format

The first line contains three positive integers n,m,qn, m, q, representing the length of array AA, the length of array BB, and the number of game rounds respectively.

The second line contains nn integers, denoting the elements AiA_i of array AA.

The third line contains mm integers, denoting the elements BiB_i of array BB.

The next qq lines each contain four positive integers, representing l1,r1,l2,r2l_1, r_1, l_2, r_2 for the corresponding round of the game.

Output Format

Output qq lines, each with an integer representing the score of the corresponding round under the optimal strategies of Little L and Little Q.

Samples

3 2 2
0 1 -2
-3 4
1 3 1 2
2 3 2 2
0
4
6 4 5
3 -1 -2 1 2 0
1 2 -1 -3
1 6 1 4
1 5 1 4
1 4 1 2
2 6 3 4
2 5 2 3
0
-2
3
2
-1

Sample (1) Explanation

Matrix CC for this test case is as follows:

$$\begin{bmatrix} 0 & 0 \\ -3 & 4 \\ 6 & -8 \end{bmatrix}$$

In the first round, no matter whether Little L chooses x=2x=2 or x=3x=3, Little Q can always select a corresponding yy to make the final score negative. Thus, the optimal choice for Little L is to select x=1x=1, which guarantees a score of 00.

In the second round, Little L can choose x=2x=2, and Little Q has no choice but to select y=2y=2, resulting in a score of 44.

Sample (3)

See game/game3.in and game/game3.ans in the contestant's directory.

Sample (4)

See game/game4.in and game/game4.ans in the contestant's directory.

Data Range

For all test data, 1n,m,q1051 \le n, m, q \le 10^5 and 109Ai,Bi109-10^9 \le A_i, B_i \le 10^9. For each round of the game, 1l1r1n1 \le l_1 \le r_1 \le n and 1l2r2m1 \le l_2 \le r_2 \le m.

Test Case No. n,m,qn, m, q \le Special Condition
11 200200 1, 2
22 1
33 2
454 \sim 5 None
66 10001000 1, 2
787 \sim 8 1
9109 \sim 10 2
111211 \sim 12 None
1313 10510^5 1, 2
141514 \sim 15 1
161716 \sim 17 2
182018 \sim 20 None

Where:

  • Special Property 1: It is guaranteed that Ai,Bi>0A_i, B_i > 0.
  • Special Property 2: For each round of the game, either l1=r1l_1 = r_1 or l2=r2l_2 = r_2.