#5002. Problem 1. Forklift Certified
Problem 1. Forklift Certified
Problem 1. Forklift Certified
USACO 2025 US Open Contest, Platinum
Farmer John is training to become forklift certified! As part of his training, he needs to clear () boxes, conveniently labeled through , from an old warehouse.
The boxes can be modeled as axis-aligned rectangles in a 2-dimensional plane, where the -direction is east and the -direction is north. Box has its southwest corner at and its northeast corner at . All coordinates are integers in the range , and no two corners from two different rectangles share the same or coordinate. All boxes have a non-zero area, and no two boxes intersect.
Farmer John plans to remove the boxes one at a time out of the southwest entrance of the warehouse. However, he can only remove a box if no part of any other box lies both south and west of the box's northeast corner due to physical limitations of the forklift.
An example with is shown below. To remove box , there cannot be any other boxes in the shaded region. Boxes and prevent box from being removed, but box does not.
Help Farmer John decide how to remove all the boxes! Your code should operate in two separate modes, defined by an integer flag :
- Mode 1 (): Generate a permutation of specifying a valid box removal order. If there are multiple valid orders, find any. It can be proven that such an order always exists.
- Mode 2 (): For each , output if Farmer John can remove box if boxes have already been removed, and otherwise.
INPUT FORMAT (input arrives from the terminal / stdin):
Each input consists of () independent test cases. It is guaranteed that the sum of all within each input does not exceed .
The first line of input contains and . (Note that is the same for each test case.) Each test case is then formatted as follows: The first line contains a single integer .Each of the next lines contains four space-separated integers : the locations of the southwest and northeast corners of box .
OUTPUT FORMAT (print output to the terminal / stdout):
For each test case: If , output a single line with space-separated integers, where the -th integer is the label of the -th box to remove.If , output a single line with a binary string of characters specifying the answer for each .
SAMPLE INPUT:
2 1 4 1 6 2 8 6 2 7 3 3 1 4 7 5 4 8 5 3 1 5 3 6 4 1 5 2 2 3 6 4
SAMPLE OUTPUT:
1 3 2 4 2 3 1
The first test case corresponds to the example above. Box is not blocked by anything, box is blocked by box , box is blocked by box , and box is blocked by boxes and .
SAMPLE INPUT:
2 2 4 1 6 2 8 6 2 7 3 3 1 4 7 5 4 8 5 3 1 5 3 6 4 1 5 2 2 3 6 4
SAMPLE OUTPUT:
1011 011
For the first test case, box is blocked by box , so Farmer John cannot remove it before removing box .
SCORING: Inputs 3-5: , .Input 6: , .Inputs 7-13: , no additional constraints.Inputs 14-16: , no additional constraints.
Problem credits: Austin Geng