Rocket

3.7

3 votes
Datastructures, Mathematics, Circle, Hard, Geometry
Problem

Country A and B are in war. Assumption, the battle field is in 2D coordinate. Country B have built a defend system containing "rocket defense system" (RDS) and "wall". A RDS has radius R, that means if a rocket is at distance less than or equals R from the RDS then it is detected and destroyed. A wall can be considered as a straight segment, a rocket will be resisted if hitting it (both ends inclusive). At position (0,0), country A shoots rockets along a straight line to a target. You are given Q queries of several types:

1 x y: Country A shoot a rocket to position (tx,ty), you must answer whether it sucessfully reaches the target or find position where it is destroyed by a RDS or hits a wall.

2 x y: Country B builds a RDS at position (x,y).

3 x y z t: Country B builds a wall between two positions (x,y) and (z,t).

4 u: u-th RDS is destroyed by an army of country A.

5 v: v-th wall is destroyed by an army of country A.

Input Format

The first line contains four space-separated integers N,M,R,Q denoting the number of RDSs, the number of walls, the radius of RDS and the number of queries, respectively.

Each of the N next lines contains two space-separated integers x,y denoting position of a RDS.

Each of the M next lines contains four space-separated intergers x,y,z,t denoting position of a wall.

Q lines follow, each line contains a query as described above.

RDSs and walls are numbered according to their appearance.

Output Format

For each query of the first type, assuming d is euclidean distance the rocket goes before stopping (it is destroyed or resisted or reaches the target). Print the nearest integer to 1000×d (.5 is rounded up).

Constraints


  • 1N,M5×104
  • 1R106
  • 1Q105
  • 1x,y,z,t,tx,ty106
  • No RDS covers point (0,0)
  • 1u the number of RDSs at that time (destroyed include)
  • 1v the number of walls at that time (destroyed include)
  • Total numbers of RDSs and walls is at most 5×104

 

Time Limit: 5
Memory Limit: 512
Source Limit:
Explanation

 

Query 1: Distance = 324.242640687, so we print 4243.

Query 2: Distance =2614.099019514, so we print 4099.

Query 3: Distance 4.459387150, so we print 4459.

Editor Image

?