Building Marble Tracks
Time limit4sMemory limit2048 MB
Given n non-vertical segments in priority order, scan them and keep each one that crosses none of the already kept segments, then print the kept indices.
- Level
Hard8 of 10
- Topics
- Geometry, Greedy, Segment tree
- Solved
- No attempts yet
Problem
Jonathan wants you to attach some marble tracks to the wall so he can play with them. Each track is a straight piece of plastic with a small indent on one side for the marble to roll in. After you ask how he wants them attached, he spends 15 minutes with crayons drawing a blueprint. You tell him that two tracks cannot be built if they intersect at an inner point. Jonathan thinks about this for a moment, then changes the blueprint. Instead of fixing the conflicts, he numbers all tracks from 1 (his most favorite) to (his least favorite).

The first sample (original blueprint).
You need to decide which tracks to build. You go through the tracks from his most favorite to his least favorite, and you build a track only if it does not intersect any track you have already attached to the wall.
Input
The first line contains one integer (), the number of marble tracks in the blueprint.
Each of the following lines contains four integers , , , (, ). They describe a track from to in the blueprint.
The tracks are given from most to least favorite. Two different tracks intersect in at most one point.
Output
Print one integer on the first line, the number of tracks to build. On the next line, print the indices of those tracks in increasing order.
Hint
As you might have noticed, the input format specifies for each track. This is because a marble cannot roll down a vertical track.