#abc344g. G - Points and Comparison

G - Points and Comparison

Score: 625625 points

问题描述

请注意特殊的输入格式。

xyxy 平面上有 NN 个点 (Xi,Yi)(X_i, Y_i),这些点在输入中给出。

同时,给出了 QQ 对整数 (Aj,Bj)(A_j, B_j)
定义 f(Aj,Bj)f(A_j, B_j) 为满足 YiAj×Xi+BjY_i \ge A_j \times X_i + B_j 的索引 ii 的数量。

j=1Qf(Aj,Bj)\displaystyle \sum^{Q}_{j=1} f(A_j,B_j)

此处,QQ 可能非常大,因此不直接给出 (Aj,Bj)(A_j, B_j)
而是给出 G0G_0RaR_aRbR_b,并通过以下方式生成 (Aj,Bj)(A_j, B_j)

  • 首先,对于 n0n \geq 0,定义 Gn+1=(48271×Gn)mod(2311)G_{n+1} = (48271 \times G_n) \mod (2^{31}-1)
  • 对于 j=1,2,,Qj=1,2,\dots,Q,按以下方式生成 (Aj,Bj)(A_j, B_j)
    • Aj=Ra+(G3j2mod(2×Ra+1))A_j = -R_a + (G_{3j - 2} \mod (2 \times R_a + 1) )
    • $B_j = -R_b + ((G_{3j - 1} \times (2^{31}-1) + G_{3 j}) \mod (2 \times R_b + 1) )$

通过这种方法可以证明,AjA_jBjB_j 满足以下约束条件:

  • RaAjRa-R_a \le A_j \le R_a
  • RbBjRb-R_b \le B_j \le R_b

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

Pay attention to the special input format.

There are NN points (Xi,Yi)(X_i,Y_i) in the xyxy-plane. You are given these points in the input.

Also, QQ pairs of integers (Aj,Bj)(A_j,B_j) are given.
Define f(Aj,Bj)f(A_j,B_j) as the number of indices ii satisfying YiAj×Xi+BjY_i \ge A_j \times X_i + B_j.

Find j=1Qf(Aj,Bj)\displaystyle \sum^{Q}_{j=1} f(A_j,B_j).

Here, QQ gets very large, so (Aj,Bj)(A_j,B_j) are not given directly.
Instead, G0G_0, RaR_a, and RbR_b are given, and (Aj,Bj)(A_j,B_j) are generated as follows:

  • First, for n0n \ge 0, define Gn+1=(48271×Gn)mod(2311)G_{n+1} = (48271 \times G_n) \mod (2^{31}-1).
  • For j=1,2,,Qj=1,2,\dots,Q, generate (Aj,Bj)(A_j,B_j) as follows:
    • Aj=Ra+(G3j2mod(2×Ra+1))A_j = -R_a + (G_{3j - 2} \mod (2 \times R_a + 1) )
    • $B_j = -R_b + ((G_{3j - 1} \times (2^{31}-1) + G_{3 j}) \mod (2 \times R_b + 1) )$

From this method, it can be shown that AjA_j and BjB_j satisfy the following constraints:

  • RaAjRa-R_a \le A_j \le R_a
  • RbBjRb-R_b \le B_j \le R_b

Constraints

  • All input values are integers.
  • 1N50001 \le N \le 5000
  • 1Q1071 \le Q \le 10^7
  • Xi,Yi108|X_i|, |Y_i| \le 10^8
  • The pairs (Xi,Yi)(X_i,Y_i) are distinct.
  • 0G0<(2311)0 \le G_0 < (2^{31}-1)
  • 0Ra1080 \le R_a \le 10^8
  • 0Rb10160 \le R_b \le 10^{16}

Input

The input is given from Standard Input in the following format:

NN

X1X_1 Y1Y_1

X2X_2 Y2Y_2

\vdots

XNX_N YNY_N

QQ

G0G_0 RaR_a RbR_b

Output

Print the answer as an integer.

Sample Input 1

7
2 -2
-1 -2
0 1
2 1
-2 2
1 2
0 -1
10
1 5 5

Sample Output 1

36

This input contains ten questions.
The generated (Aj,Bj)(A_j,B_j) are $(-2,4),(0,2),(-4,-2),(4,-5),(3,1),(-1,3),(2,-5),(3,-1),(3,5),(3,-2)$.