#abc304d. D - A Piece of Cake

D - A Piece of Cake

Score : 400400 points

问题描述

xyxy 平面上有一个矩形蛋糕,上面有一些草莓。蛋糕占据矩形区域 $\lbrace (x, y) : 0 \leq x \leq W, 0 \leq y \leq H \rbrace$。

蛋糕上有 NN 颗草莓,第 ii 颗草莓的坐标为 (pi,qi)(p_i, q_i),对于 i=1,2,,Ni = 1, 2, \ldots, N。没有两颗草莓具有相同的坐标。

高桥将会用刀将蛋糕切成几块,方法如下:

  • 首先,沿平行于 yy 轴的 AA 条直线切割蛋糕:直线 x=a1x = a_1x=a2x = a_2\ldotsx=aAx = a_A
  • 接着,沿平行于 xx 轴的 BB 条直线切割蛋糕:直线 y=b1y = b_1y=b2y = b_2\ldotsy=bBy = b_B

结果,蛋糕将被分成 (A+1)(B+1)(A+1)(B+1) 个矩形小块。高桥将从中选择一块来吃。请输出所选蛋糕块上可能包含的最少和最多草莓数量。

这里保证最终每块蛋糕边缘上没有草莓。更正式的描述,请参考以下约束条件。

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

Problem Statement

There is a rectangular cake with some strawberries on the xyxy-plane. The cake occupies the rectangular area $\lbrace (x, y) : 0 \leq x \leq W, 0 \leq y \leq H \rbrace$.

There are NN strawberries on the cake, and the coordinates of the ii-th strawberry are (pi,qi)(p_i, q_i) for i=1,2,,Ni = 1, 2, \ldots, N. No two strawberries have the same coordinates.

Takahashi will cut the cake into several pieces with a knife, as follows.

  • First, cut the cake along AA different lines parallel to the yy-axis: lines x=a1x = a_1, x=a2x = a_2, \ldots, x=aAx = a_A.
  • Next, cut the cake along BB different lines parallel to the xx-axis: lines y=b1y = b_1, y=b2y = b_2, \ldots, y=bBy = b_B.

As a result, the cake will be divided into (A+1)(B+1)(A+1)(B+1) rectangular pieces. Takahashi will choose just one of these pieces to eat. Print the minimum and maximum possible numbers of strawberries on the chosen piece.

Here, it is guaranteed that there are no strawberries along the edges of the final pieces. For a more formal description, refer to the constraints below.

Constraints

  • 3W,H1093 \leq W, H \leq 10^9
  • 1N2×1051 \leq N \leq 2 \times 10^5
  • 0<pi<W0 \lt p_i \lt W
  • 0<qi<H0 \lt q_i \lt H
  • ij    (pi,qi)(pj,qj)i \neq j \implies (p_i, q_i) \neq (p_j, q_j)
  • 1A,B2×1051 \leq A, B \leq 2 \times 10^5
  • 0<a1<a2<<aA<W0 \lt a_1 \lt a_2 \lt \cdots \lt a_A \lt W
  • 0<b1<b2<<bB<H0 \lt b_1 \lt b_2 \lt \cdots \lt b_B \lt H
  • pi∉{a1,a2,,aA}p_i \not \in \lbrace a_1, a_2, \ldots, a_A \rbrace
  • qi∉{b1,b2,,bB}q_i \not \in \lbrace b_1, b_2, \ldots, b_B \rbrace
  • All input values are integers.

Input

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

WW HH

NN

p1p_1 q1q_1

p2p_2 q2q_2

\vdots

pNp_N qNq_N

AA

a1a_1 a2a_2 \ldots aAa_A

BB

b1b_1 b2b_2 \ldots bBb_B

Output

Print the minimum possible number of strawberries mm and the maximum possible number MM on the chosen piece in the following format, separated by a space.

mm MM

Sample Input 1

7 6
5
6 1
3 1
4 2
1 5
6 2
2
2 5
2
3 4

Sample Output 1

0 2

There are nine pieces in total: six with zero strawberries, one with one strawberry, and two with two strawberries. Therefore, when choosing just one of these pieces to eat, the minimum possible number of strawberries on the chosen piece is 00, and the maximum possible number is 22.

Sample Input 2

4 4
4
1 1
3 1
3 3
1 3
1
2
1
2

Sample Output 2

1 1

Each piece has one strawberry on it.

update @ 2024/3/10 08:34:01