#P3683. [CERC2016] 地理哈希网格 Geohash Grid

[CERC2016] 地理哈希网格 Geohash Grid

Description

A "geohash" encodes 2D planar coordinates into integers, which facilitates storing and querying geographic data in databases. In this problem, a map is a 2n×2n2^n \times 2^n rectangular grid built on the standard 2D Cartesian coordinate system, where xx increases to the right and yy increases upward. A map cell is a unit square whose lower-left corner has integer coordinates (x,y)(x, y), where 0x,y<2n0 \le x, y < 2^n.

There are 22n2^{2n} cells on the 2n×2n2^n \times 2^n map. For a cell cc, its geohash value h(c)h(c) is a non-negative 2n2n-bit binary integer. Starting from the most significant bit and considering the entire map, repeat the following two steps nn times to obtain h(c)h(c):

  1. Split the map into left and right regions of equal area. If cell cc lies in the left half, this bit is 00; otherwise it is 11. Then restrict the scope to the half that contains cc.
  2. Split the map into bottom and top regions of equal area. If cell cc lies in the bottom half, this bit is 00; otherwise it is 11. Then restrict the scope to the half that contains cc.

A "geohash interval" [a,b][a, b] denotes all cells whose hash values lie in [a,b][a, b] (inclusive). In practice, we approximate a set on the map using a few geohash intervals. Given a set of cells CC and a positive integer tt, the optimal tt-approximation of CC is to use at most tt geohash intervals to cover all cells in CC (covering other cells is allowed) while minimizing the total covered area.

You are given a map and a cell set CC, where CC is represented by a simple polygon whose edges are parallel to the coordinate axes. Then you are given qq queries t1,t2,,tqt_1, t_2, \ldots, t_q. For each query tkt_k, you need to output the area of the optimal tkt_k-approximation that covers CC.

Input Format

The first line contains a positive integer nn (1n30)(1 \le n \le 30), the base-2 logarithm of the map size.

The second line contains a positive integer mm (4m200)(4 \le m \le 200), the number of polygon vertices.

Each of the next mm lines contains two integers xi,yix_i, y_i (0xi,yi2n)(0 \le x_i, y_i \le 2^n), giving the coordinates of the polygon’s vertices in counterclockwise order.

The input guarantees that the polygon is simple, its edges are parallel to the coordinate axes, and no two consecutive edges are parallel.

The next line contains a positive integer qq (1q100000)(1 \le q \le 100000), the number of queries.

Each of the next qq lines contains a positive integer tit_i (1ti109)(1 \le t_i \le 10^9), the parameter of a query.

Output Format

Output qq lines. For each query, output a single positive integer: the answer to that query.

3 8
1 1
5 1
5 4
3 4
3 8
0 8
0 5
1 5
4 2 3 5 7
32
30
26
24

Hint

The intervals [3,29][3, 29], [33,33][33, 33], and [36,37][36, 37] form an optimal 33-approximation, whose total covered area is 3030.

Translated by ChatGPT 5