#P4169. Ayu's Angel Doll Search

    ID: 17416 Type: Default 1000ms 256MiB

Ayu's Angel Doll Search

Ayu received an angel doll seven years ago and buried it in the ground as a time capsule. Today, she has forgotten the exact location of the burial and only recalls a vague memory of possible coordinates in her small town, which can be regarded as a 2D plane.

There are two types of operations:

  1. Recording operation: Ayu recalls that she might have buried the angel doll at a point \((x, y)\). You need to record this point.
  2. Query operation: Ayu asks, if she is currently at point \((x, y)\), what is the minimum Manhattan distance to any recorded burial point? The Manhattan distance between two points \(A = (A_x, A_y)\) and \(B = (B_x, B_y)\) is defined as $$\operatorname{dist}(A,B)=|A_x-B_x|+|A_y-B_y|.$$ If no burial point has been recorded yet, output \(-1\).

The input consists of a number of operations. Process each operation in the order given.

inputFormat

The first line of input contains an integer \(Q\) representing the total number of operations. Each of the following \(Q\) lines contains an operation in the following format:

  • \(op\) \(x\) \(y\) where \(op\) is an integer indicating the type of operation.
  • If \(op = 1\), then the operation is to record a burial point at coordinates \((x, y)\).
  • If \(op = 2\), then the operation is a query: output the minimum Manhattan distance from point \((x, y)\) to any recorded burial point. If no point has been recorded, output \(-1\).

outputFormat

For each query operation (when \(op = 2\)), output a single line containing the minimum Manhattan distance to a recorded burial point. If there are no recorded points at the time of the query, output \(-1\).

sample

5
1 0 0
2 1 1
1 2 3
2 2 2
2 0 3
2

1 2

</p>