#P8818. [CSP-S 2022] 策略游戏

    ID: 7586 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>贪心线段树2022O2优化st表CSP S 提高级

[CSP-S 2022] 策略游戏

Description

Xiao L and Xiao Q are playing a strategy game.

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

The game has qq rounds. In each round, 44 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 the game, Xiao L first chooses an index xx between l1r1l_1 \sim r_1, and then Xiao Q chooses an index yy between l2r2l_2 \sim r_2. The score of this round is defined as CxyC_{x y}.

Xiao L’s goal is to make this score as large as possible, while Xiao Q’s goal is to make it as small as possible. Both players are sufficiently smart and always use optimal strategies.

Question: Under both players’ optimal strategies, what is the score in each round?

Input Format

The first line contains three positive integers nn, mm, qq, representing the lengths of array AA, array BB, and the number of game rounds.

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

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

Then follow qq lines. Each line contains four positive integers, representing l1,r1,l2,r2l_1, r_1, l_2, r_2 for this round.

Output Format

Output qq lines. Each line contains one integer, representing the score in that round under the players’ optimal strategies.

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

Hint

Sample Explanation #1

In this dataset, the matrix CC is as follows:

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

In the first round, no matter whether Xiao L chooses x=2x = 2 or x=3x = 3, Xiao Q can choose some yy to make the final score negative. Therefore, choosing x=1x = 1 is optimal for Xiao L, because then the score is guaranteed to be 00.

In the second round, since Xiao L can choose x=2x = 2, Xiao Q can only choose y=2y = 2, so the score is 44.

Sample #3

See the attachments game/game3.in and game/game3.ans.

Sample #4

See the attachments game/game4.in and game/game4.ans.

Constraints

For all testdata, 1n,m,q1051 \le n, m, q \le {10}^5, 109Ai,Bi109-{10}^9 \le A_i, B_i \le {10}^9. For each round, 1l1r1n1 \le l_1 \le r_1 \le n, 1l2r2m1 \le l_2 \le r_2 \le m.

Test point ID 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 105{10}^5 1, 2
141514 \sim 15 1
161716 \sim 17 2
182018 \sim 20 None

Here, special property 1: guarantee Ai,Bi>0A_i, B_i > 0.
Special property 2: guarantee that for each round, either l1=r1l_1 = r_1 or l2=r2l_2 = r_2.

Translated by ChatGPT 5