#P4097. 【模板】李超线段树 / [HEOI2013] Segment

    ID: 3033 远端评测题 1000ms 128MiB 尝试: 12 已通过: 1 难度: 8 上传者: 标签>贪心2013线段树各省省选递归河北块状链表,块状数组,分块

【模板】李超线段树 / [HEOI2013] Segment

Description

Maintain two operations in the 2D Cartesian coordinate system:

  1. Insert a line segment into the plane. The index of the i-th inserted segment is ii.
  2. Given a number kk, query among all segments that intersect the line x=kx = k, and return the index of the segment whose intersection point has the largest yy-coordinate.

Input Format

This problem enforces online input.

The first line contains an integer nn, the number of operations.

Then nn lines follow. On each line there are several integers separated by spaces. On the (i+1)(i + 1)-th line, the first integer is opop, indicating the type of the ii-th operation.

  • If op=0op = 0, then it is followed by an integer kk. This operation queries among all segments that intersect the line x=(k+lastans1)mod39989+1x = (k + lastans - 1) \bmod 39989 + 1, and returns the index of the segment whose intersection point has the largest yy-coordinate.
  • If op=1op = 1, then it is followed by four integers x0,y0,x1,y1x_0, y_0, x_1, y_1. Define xi=(xi+lastans1)mod39989+1x_i' = (x_i + lastans - 1) \bmod 39989 + 1, yi=(yi+lastans1)mod109+1y_i' = (y_i + lastans - 1) \bmod 10^9 + 1. This operation inserts a segment with endpoints (x0,y0)(x_0', y_0') and (x1,y1)(x_1', y_1').

Here lastanslastans is the answer to the previous query. Initially, lastans=0lastans = 0.

Output Format

For each query, output one line containing a single integer: the index of the segment whose intersection point has the largest yy-coordinate. If no segment intersects the query line, output 00. If multiple segments have the same maximum intersection yy-coordinate, output the smallest index among them, and lastanslastans 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 11

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 lastanslastans is updated to 22.

For the fourth operation, after decoding it becomes 0 11, and lastanslastans is updated to 00.

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 30%30\% of the testdata, n103n \leq 10^3 is guaranteed.

For 100%100\% of the testdata, it is guaranteed that 1n1051 \leq n \leq 10^5, 1k,x0,x1399891 \leq k, x_0, x_1 \leq 39989, 1y0,y11091 \leq y_0, y_1 \leq 10^9.

Notes

It is not guaranteed that x0x1x_0 \neq x_1. For a segment with x0=x1x_0' = x_1', its intersection with x=x0x = x_0' is defined to be the endpoint with the larger yy-coordinate.

Translated by ChatGPT 5