Building Marble Tracks

시간 제한4초메모리 제한2048 MB

요약
선분을 우선순위가 높은 순서대로 처리하며 이미 선택한 선분과 교차하지 않는 것만 남기고, 남은 선분의 번호를 출력한다.
난이도

어려움10점 중 8점

유형
기하, 정렬, 이분 탐색
정답자
아직 제출이 없습니다

문제

Jonathan wants you to attach some marble tracks to the wall to play with. Each of them is a straight piece of plastic with a little indent on one side for the marble to roll in. After asking Jonathan how he wants them attached, he spends 15 minutes with some crayons to draw you a blueprint. After he hands it to you, you inform him that you can't build two tracks that intersect at inner points. Jonathan ponders this insight for a moment and then modifies his blueprint. But instead of properly fixing it, he decides to number all tracks from 1 (his most favorite) to n (his least favorite).

The first sample (original blueprint).

It is now your task to figure out which tracks to build. You decide to go through all tracks from his most to least favorite and build them if they do not intersect a track that you have already attached to the wall.

입력

The first line contains one integer nn (1≤n≤6⋅1041 \leq n \leq 6 \cdot 10^4) --- the number of marble tracks in the blueprint.

Each of the following nn lines contains four integers x_1,y_1,x_2,y_2x\_1, y\_1, x\_2, y\_2 (−105≤x_1,y_1,x_2,y_2≤105-10^5 \leq x\_1, y\_1, x\_2, y\_2 \leq 10^5 and x_1≠x_2x\_1 \neq x\_2). These represent a marble track from (x_1,y_1)(x\_1, y\_1) to (x_2,y_2)(x\_2, y\_2) in the blueprint.

They are given in order from most to least favorite. Two different tracks intersect in at most one point.

출력

Output one integer kk in one line, the number of tracks to build. In the next line, output kk integers, the indices of the tracks to build in increasing order.

힌트

As you might have noticed, the input format specifies x_1≠x_2x\_1 \neq x\_2 for each possible marble track. This is because you can't roll a marble down a vertical track.

예제3

  1. 예제 1

    입력
    6
    3 2 5 4
    0 4 4 0
    2 1 6 1
    5 4 7 2
    0 3 5 3
    4 2 6 0
    
    예상 출력
    4
    1 2 4 6
    
  2. 예제 2

    입력
    2
    0 0 2 2
    1 1 2 0
    
    예상 출력
    2
    1 2
    
  3. 예제 3

    입력
    10
    -30428 50667 -18028 82591
    -19828 85240 -16439 54314
    -16439 54314 -13911 33099
    -18028 82591 -13739 13271
    -13911 33099 -11978 -46941
    -13739 13271 14783 13050
    -11978 -46941 35511 -79125
    35511 -79125 35524 -89845
    35524 -89845 67295 -41898
    14783 13050 72720 -67171
    
    예상 출력
    6
    1 3 5 7 8 9