#FT0000220. Tìm búp bê thiên thần gần nhất (Angel Doll / SJY Placing Chess Pieces)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Tìm búp bê thiên thần gần nhất (Angel Doll / SJY Placing Chess Pieces)
Angel Doll / SJY Placing Chess Pieces
Source: Luogu
Version: Phuoc Hung OJ Extended
Problem Statement
Seven years ago, Ayu received an angel doll and buried it as a time capsule. She can no longer remember its exact location, but remembers some possible locations in her town.
Model the town as a Cartesian plane, and represent each location by nonnegative integer coordinates . Initially Ayu remembers possible locations. She then performs operations in order:
1 x y: remember another possible location . It is added to the known locations and remains available for every later operation.2 x y: at location , ask for the minimum distance to any location currently known.
Ayu moves only parallel to the coordinate axes, so the distance between and is (Manhattan distance).
Answer all type 2 queries in order. Duplicate point coordinates are allowed and do not change the nearest distance.
Input
- The first line contains two integers : the number of initially known locations and the number of operations.
- Each of the next lines contains two integers , the coordinates of one initially known location.
- Each of the following lines contains three integers : operation type
1adds point , and operation type2asks for the smallest distance from to any currently known point.
Output
For every type 2 operation, print one nonnegative integer: the minimum Manhattan distance to a point known at the time of that operation. Print nothing for type 1 operations.
Subtasks
- Subtask 1 (20 points): ; for every initial point and operation; ; inserted points remain forever.
- Subtask 2 (30 points): ; for every initial point and operation; ; inserted points remain forever.
- Subtask 3 (50 points): ; for every initial point and operation; ; inserted points remain forever.
Examples
Input
2 4
0 0
5 5
2 3 3
1 3 3
2 3 3
2 2 5
Output
4
0
3
Explanation
Initially Ayu knows locations and .
- Query
2 3 3: distances from to those two points are and , so print4. - Operation
1 3 3adds location without producing output. - Query
2 3 3: the query point now matches a known location, giving distance . - Query
2 2 5: distances to , , and are respectively , , and . Print3.
The output lines are therefore 4, 0, and 3.