Under construction

Still being built. Things may change

Plot of Land

Time limit1sMemory limit128 MB

Summary
Given up to 3000 pine points and one million query rectangles, report the convex hull area of the points inside each rectangle.
Level

Hard9 of 10

Topics
Geometry, Divide and conquer, Sorting
Solved
No attempts yet

Problem

Byteasar has dreamed of owning a plot of land in the Byteotian Forest since childhood, and now, working as a computer scientist, he can finally afford to make that dream come true.

A new part of the forest has just gone on sale, and Byteasar is the very first customer. Seen from above, this part of the forest is a square of size k×kk \times k, and nn pine trees grow inside it. As the first customer, Byteasar may choose among many proposed plot locations. Each proposal is a rectangle that lies entirely inside the forest. He has not yet decided which one to take.

After buying a plot, Byteasar intends to fence it. He is thrifty and wants the fence to be as short as possible while still enclosing every pine that grows on the plot. In particular, this means he does not have to fence the whole rectangular plot: the shortest fence that surrounds a set of trees runs along their convex hull. He also knows that every year he must pay a land tax proportional to the area of the fenced region, and it is mainly this sizeable tax that worries him.

Help Byteasar decide: for each plot location proposed by the forestry company, compute the area of the fenced region, that is, the area of the convex hull of the pines that lie inside that plot.

Input

The first line contains two integers kk and nn (1≤k≤1 000 0001 \le k \le 1\,000\,000, 3≤n≤3 0003 \le n \le 3\,000): the side length of the forest fragment and the number of pines growing in it. Each of the next nn lines contains two integers xix_i, yiy_i (0≤xi,yi≤k0 \le x_i, y_i \le k): the coordinates of the ii-th pine. You may assume that at most one pine stands at any given point.

The next line contains one integer mm (1≤m≤1 000 0001 \le m \le 1\,000\,000): the number of possible plot locations. Each of the next mm lines contains four integers aja_j, bjb_j, cjc_j, djd_j (0≤aj<bj≤k0 \le a_j < b_j \le k, 0≤cj<dj≤k0 \le c_j < d_j \le k), describing the rectangular plot [aj,bj]×[cj,dj][a_j, b_j] \times [c_j, d_j]. A pine counts as lying inside this plot when aj≤xi≤bja_j \le x_i \le b_j and cj≤yi≤djc_j \le y_i \le d_j (the plot boundary is included).

Output

Print mm lines. The jj-th line should contain a single real number, given to one digit after the decimal point: the area of the fenced region if the jj-th offer is chosen. You may assume that this area is always positive.

Because every pine sits at integer coordinates, the hull area is always a multiple of 0.50.5, so the single decimal digit is always either .0 or .5.

Hint

The figure shows the first two proposed plot locations from the sample, with the fenced region highlighted.

Examples3

  1. Example 1

    Input
    9 7
    1 1
    1 3
    3 3
    3 1
    6 5
    6 6
    7 3
    3
    0 4 0 4
    2 7 0 7
    3 7 3 6
    
    Expected output
    4.0
    10.0
    6.0
    
  2. Example 2

    Input
    2 3
    0 0
    1 0
    0 1
    1
    0 2 0 2
    
    Expected output
    0.5
    
  3. Example 3

    Input
    10 5
    0 0
    4 0
    4 4
    0 4
    2 2
    3
    0 4 0 4
    0 4 0 2
    2 4 0 4
    
    Expected output
    16.0
    4.0
    4.0