Jinx and the Peacekeeper Camp
Time limit3sMemory limit1024 MB
Given guard rectangles with strengths, find for each horizontal or vertical segment the minimum protection among its points that at least one guard covers.
- Level
Hard9 of 10
- Topics
- Segment tree, Sorting, Divide and conquer
- Solved
- No attempts yet
Statement
Jinx plans an attack on a peacekeeper camp.
The camp is a field on the coordinate plane.
The camp has peacekeeper guards. Guard has strength and is responsible for one rectangle on the plane. Each rectangle is given by its upper left corner and lower right corner , with and . A point is protected by the guard of this rectangle if and .
A point of the camp can be protected by several guards, and their rectangles may overlap. Unfortunately for Jinx, this helps little. The protection of point equals the smallest strength among the guards protecting it.
The camp has approaches. The -th approach leads to all points inside one of two rectangles: either the rectangle with corners and , or the rectangle with corners and . Through a vertical approach, Jinx can reach a point if and . Through a horizontal approach, she can reach it if and .
For each approach, find the minimum protection over all points she can reach through it that are protected by at least one guard.
Input
The first line contains two integers and (, ), the number of guards and the number of approaches.
Each of the next lines describes one guard. Line contains five integers , , , and . The first four values are the coordinates of the upper left and lower right corners of the rectangle of guard , and is the strength of that guard (, ).
Each of the next lines describes one approach. The first character of the line is either x or y. If it is x, the approach is defined by and , and the line continues with , , . Otherwise, the approach is defined by and , and the line continues with , , .
Output
For each of the approaches, print on its own line the minimum protection among the points it can reach that are protected by at least one guard. If none of the points reachable through the approach is protected by a guard, print .