#P4509. Historical Line Segment Intersection
Historical Line Segment Intersection
Historical Line Segment Intersection
In this problem, you are given N points in the plane, denoted as \(P_1,P_2,\ldots,P_N\). These points are connected in order to form \(N-1\) segments: \((P_1,P_2), (P_2,P_3), \ldots, (P_{N-1},P_N)\). You will then perform M operations on these points. There are two types of operations:
- Query Operation: Given a historical version \(T\) and a line defined by the equation \(Ax+By+C=0\) (in \(\LaTeX\) format: \(Ax+By+C=0\)), count how many segments (formed by consecutive points in that version) intersect with the line. Note that an intersection is counted if the line touches a segment's endpoint or if the line completely covers a segment.
- Insertion Operation: Given a historical version \(T\), an index i and a point \(P=(x,y)\), insert the point into that version between \(P_i\) and \(P_{i+1}\). In particular, if i is 0, insert the point before the first point; if i equals the current number of points, insert the point after the last point.
Each operation (whether a query or an insertion) produces a new historical version. The initial version is version 0, which is defined by the initial N points.
Your task is to process all operations and, for every query operation, output the number of segments that intersect the given line in the corresponding version.
inputFormat
The input begins with an integer N (\(N\ge 2\)) — the number of initial points. The following N lines each contain two integers representing the coordinates of the points.
Next, an integer M is given — the number of operations.
Each of the next M lines represents an operation. The format for an operation is one of the following:
- Query Operation:
1 T A B C
Here,T
is the historical version to base the query on, and the line is given by \(Ax+By+C=0\). - Insertion Operation:
2 T i x y
Here,T
is the historical version to base the insertion on,i
is the position at which to insert a new point with coordinates \((x,y)\). The new point will be inserted between thei
-th and(i+1)
-th points (ifi
is 0, the point is inserted before the first point; ifi
equals the number of points, it is inserted after the last point).
outputFormat
For each query operation, output one integer on a separate line — the number of segments in the specified historical version that intersect with the given line.
sample
3
0 0
5 0
5 5
3
1 0 0 -1 0
2 0 1 2 2
1 1 1 0 -3
2
1
</p>