This page is still under construction.

Parts of this page are still being built. What you see may change.

Radioactivity

Time limit1sMemory limit128 MB

Summary
For each pair of radiation radii, count houses not covered by either plant after houses in both zones donate a spare unit.
Level

Medium7 of 10

Topics
Geometry, Sorting, Binary search, Prefix sum
Solved
No attempts yet

Problem

A nuclear power plant is both a blessing and a curse of modern civilization. It carries many dangers, yet it is also the cheapest way to generate electricity. In this problem we consider the situation created by two nuclear power plants that stand close to each other.

Assume the ground is completely flat and every house lies on a 2D coordinate plane. The two plants are located at (ax,ay)(a_x, a_y) and (bx,by)(b_x, b_y). Any location whose distance from plant (ax,ay)(a_x, a_y) is at most R1R_1 (the boundary at distance exactly R1R_1 is included) is a high-risk radiation zone. Likewise, any location whose distance from plant (bx,by)(b_x, b_y) is at most R2R_2 is also a high-risk radiation zone.

The plant operators hand out one piece of protective equipment to each house in a high-risk zone. Therefore a house that lies in the high-risk zones of both plants receives two pieces. However, a single piece is already enough to keep a house safe.

A house outside every high-risk zone belongs to the low-risk zone and initially receives no equipment. A house holding two pieces may give its spare to a low-risk house, so that the low-risk house also has one piece. Even after this redistribution, some houses may still end up with no equipment.

Given the positions of the houses, the positions of the two plants, and several possible R1,R2R_1, R_2 pairs, write a program that, for each pair, computes the number of houses that end up without protective equipment.

Input

The input consists of at most 3 test cases. Each test case has the following format.

  • The first line contains the number of houses NN. (0<N≤2000000 < N \le 200000)
  • The next NN lines each contain the coordinates xi,yix_i, y_i of a house. (0≤xi,yi≤200000 \le x_i, y_i \le 20000) No two houses share the same location.
  • The next line contains ax,ay,bx,by,qa_x, a_y, b_x, b_y, q. (0≤ax,ay,bx,by≤200000 \le a_x, a_y, b_x, b_y \le 20000, 0<q≤200000 < q \le 20000) (ax,ay)(a_x, a_y) and (bx,by)(b_x, b_y) are the coordinates of the two plants, and qq is the number of R1,R2R_1, R_2 pairs to check.
  • The next qq lines each contain R1,R2R_1, R_2. (0<R1,R2≤130000 < R_1, R_2 \le 13000)

After all test cases, a final line contains a single 00.

Output

For each test case, print q+1q+1 lines. The first line prints the test case number in the form Case k: (kk starts from 1). The following qq lines print, in the input order of the R1,R2R_1, R_2 pairs, the number of houses that end up without protective equipment.

Examples1

  1. Example 1

    Input
    11
    95 75
    27 6
    93 5
    124 13
    34 49
    65 61
    81 49
    77 33
    110 50
    91 22
    110 25
    57 42 97 36 2
    31 25
    25 25
    0
    
    Expected output
    Case 1:
    2
    2