Mathison and the furthest point
Practice
2 (2 votes)
Hard
Segment trees
Problem
49% Success 536 Attempts 50 Points 5s Time Limit 256MB Memory 1024 KB Max Code

Mathison has taken a course in Computational Geometry. He managed to solve almost all problems from his latest problem sheet. The hardest one was sent to you and is described below.

You are given a \(C \times C\) grid than currently contains no active points and on which you can perform certain operations.
An operation can be an activation \((x, y)\), in which so you mark the point at coordinates \((x, y)\) as active if the point was not already marked. Otherwise, you do nothing.
The second type of operation is a query \((x, y)\) \((x_1, y_1)\) \((x_2, y_2)\): you have to find the greatest manhattan distance between the point \((x, y)\) and any active point that lies inside the rectangle with the bottom-left corner in \((x_1, y_1)\) and the top-right one in \((x_2, y_2)\).

You are given N such operations and you have to execute them all!

Input
The first line of the input file contains one integer, N, representing the number of operations.
Each of the next N lines will contain either an activation or a query in the following format:

  • 0 x y: mark the point at \((x, y)\) as active
  • 1 x y \(x_1\) \(y_1\) \(x_2\) \(y_2\): find the greatest manhattan distance between \((x, y)\) and any active point from \(Rectangle((x_1, y_1), (x_2, y_2))\)

Output
The output file will contain a line for each operation of type 1. If there is no point in the given rectangle, you should print "no point!" (without quotes).

Constraints

  • \(1 \le N \le 2 \times 10^5\)
  • \(1 \le C \le 10^8\)
  • \( 0 \le x, y, x_1, y_1, x_2, y_2 \le C\)
  • \(x_1 \le x_2\) and \(y_1 \le y_2\) for all rectangles \(Rectangle((x_1, y_1), (x_2, y_2))\)
  • The manhattan distance between A and B is defined to be \(d(A, B) = |A_x - B_x| + |A_y - B_y|\).

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:50
8 votes
Tags:
Advanced Data StructuresData StructuresSegment Trees
Points:50
7 votes
Tags:
Advanced Data StructuresSegment treeData StructuresSegment Trees
Points:30
57 votes
Tags:
ApprovedCombinatoricsEasyException handlingMathNumber TheoryOpenProbabilityStatistics