#P4097. 【模板】李超线段树 / [HEOI2013] Segment
【模板】李超线段树 / [HEOI2013] Segment
Description
Maintain two operations in the 2D Cartesian coordinate system:
- Insert a line segment into the plane. The index of the i-th inserted segment is .
- Given a number , query among all segments that intersect the line , and return the index of the segment whose intersection point has the largest -coordinate.
Input Format
This problem enforces online input.
The first line contains an integer , the number of operations.
Then lines follow. On each line there are several integers separated by spaces. On the -th line, the first integer is , indicating the type of the -th operation.
- If , then it is followed by an integer . This operation queries among all segments that intersect the line , and returns the index of the segment whose intersection point has the largest -coordinate.
- If , then it is followed by four integers . Define , . This operation inserts a segment with endpoints and .
Here is the answer to the previous query. Initially, .
Output Format
For each query, output one line containing a single integer: the index of the segment whose intersection point has the largest -coordinate. If no segment intersects the query line, output . If multiple segments have the same maximum intersection -coordinate, output the smallest index among them, and should also be updated to this smallest index.
6
1 8 5 10 8
1 6 7 2 6
0 2
0 9
1 4 7 6 7
0 5
2
0
3
Hint
Explanation for Sample
For the first operation, after decoding it becomes 1 8 5 10 8.
For the second operation, after decoding it becomes 1 6 7 2 6.
For the third operation, after decoding it becomes 0 2, and is updated to .
For the fourth operation, after decoding it becomes 0 11, and is updated to .
For the fifth operation, after decoding it becomes 1 4 7 6 7.
For the sixth operation, after decoding it becomes 0 5.
Constraints
For of the testdata, is guaranteed.
For of the testdata, it is guaranteed that , , .
Notes
It is not guaranteed that . For a segment with , its intersection with is defined to be the endpoint with the larger -coordinate.
Translated by ChatGPT 5
京公网安备 11011102002149号