#P9848. [ICPC2021 Nanjing R] Cloud Retainer's Game

[ICPC2021 Nanjing R] Cloud Retainer's Game

题目描述

Cloud Retainer, the builder of the Dwelling in the clouds above Qingyun Peak, is very interested in mechanics. Although there is more than one month away from the Lantern Rite Festival in Liyue, she has already started the design of a gaming event for it.

The game is mainly about releasing pinballs to get a score as high as possible. It is played on the 2-dimensional plane with two horizontal straight lines y=0y = 0 and y=Hy = H. Between the two lines, there are nn tiny wooden boards and mm coins, both can be regarded as single points. The ii-th wooden board is located at (xi,yi)(x_i, y_i) while the ii-th coin is located at (xi,yi)(x'_i, y'_i).

A pinball is released from (109,109)(10^{-9}, 10^{-9}) by the player. Let v=(vx,vy)\overrightarrow{v} = (v_x, v_y) be the velocity of the ball (that is to say, if the ball is currently located at (x,y)(x, y) it will move to (x+vxϵ,y+vyϵ)(x + v_x\epsilon, y + v_y\epsilon) after ϵ\epsilon seconds). Initially v=(1,1)\overrightarrow{v} = (1, 1).

When the ball hits a wooden board or one of the two horizontal straight lines, vyv_y will be negated (that is, vyv_y becomes vy-v_y) while vxv_x remains unchanged. If the ball hits a coin, the player's score is increased by 11 and the velocity of the ball remains unchanged.

To gain a higher score, the player can choose to remove any number of wooden boards before the pinball is released. It is also OK not to remove any wooden board. Cloud Retainer wants you to help her estimate the difficulty by computing the maximum score the player can get after 101010101010^{10^{10^{10^{10}}}} seconds under the best strategy?

输入格式

There are multiple test cases. The first line of the input contains an integer TT indicating the number of test cases. For each test case:

The first line contains one integer HH (2H1092 \le H \le 10^9).

The second line contains one integer nn (1n1051 \le n \le 10^5) indicating the number of wooden boards.

For the following nn lines, the ii-th line contains two integers xix_i and yiy_i (1xi1091 \le x_i \le 10^9, 1yi<H1 \le y_i < H) indicating a wooden board located at (xi,yi)(x_i, y_i).

The following line contains one integer mm (1m1051 \le m \le 10^5) indicating the number of coins.

For the following mm lines, the ii-th line contains two integers xix'_i and yiy'_i (1xi1091 \le x'_i \le 10^9, 1yi<H1 \le y'_i < H) indicating a coin located at (xi,yi)(x'_i, y'_i).

It's guaranteed that the given (n+m)(n + m) points in the same test case will be distinct. It's also guaranteed that neither the sum of nn nor the sum of mm of all test cases will exceed 5×1055 \times 10^5.

输出格式

For each test case output one line containing one integer indicating the maximum score the player can get after removing some (or not removing any) wooden boards.

题目大意

参考题中所给图片,有上下两根直线,之间的距离为 HH,还有 nn 个镜子,可以反射光线,也可以让其穿过,有 mm 个物品,一开始有一束从原点出发四十五度向右上方射出的一条光线,请你控制每个镜子的开关,求这条光线最多能经过几个物品。

——By @紊莫

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

3
3

提示

The two sample test cases are shown below. Solid diamonds represent the remaining wooden boards, while hollow diamonds represent the removed wooden boards and round dots represent the coins.