Post Offices#2565

Post Offices

1 second
64 megabytes
Very hard

You are given the locations of all post offices on Earth and a set of destinations for various packages to be shipped. For each package, you must find the maximal set of post offices suitable as destinations for the package. This set must satisfy the following conditions:

For this problem, the Earth is considered to be a perfect sphere with a radius of 6381 km. The distance between two points is computed by the haversine formula:

A = sin((lat1-lat2)/2)^2 + cos(lat1) · cos(lat2) · (sin((long1-long2)/2)^2);

DISTANCE = 6381 · 2 · atan2(sqrt(A), sqrt(1-A));

(You may use other formulas if desired, but note that the arccosine formula has significant rounding errors for small distances, which may lead to incorrect results.)

Input

The input file is binary; all numbers are written in little-endian representation. It contains, in this order:

  • 4 bytes representing the number of post offices (an integer, no more than )

  • For each post office, there are two numbers (4 bytes each) representing the latitude and longitude (in degrees) of the post office. The numbers are single-precision IEEE754 floating point numbers. All latitudes are between and degrees; all longitudes are between and degrees.

  • 4 bytes representing the number of packages (an integer, no more than )

  • For each package, there are two numbers (4 bytes each) representing the latitude and longitude (in degrees) of the destination. The numbers are single-precision IEEE754 floating point numbers. All latitudes are between and degrees; all longitudes are between and degrees.

Output

The output file is also binary and contains only 32-bit integers in little-endian representation. For each of the lines in the input file, it must contain:

  • One integer—the number of post offices in the destination set

  • integers—the indices of the post offices in the destination set, sorted in ascending order (lower indices first). The index of the first post office in the input file is (so all indices are between and , inclusively).

Examples

Example 1

Loading
Loading