#P8861. Segment Set Queries
Segment Set Queries
Segment Set Queries
You are given an initially empty set of segments. You need to process \(q\) queries. Each query is of one of the following three types:
- Add a new segment \([l_i, r_i]\).
- For every segment in the set that intersects with \([l_i, r_i]\), modify it to be its intersection with \([l_i, r_i]\).
- Output the sum of lengths of the intersections between each segment in the set and \([l_i, r_i]\).
Two segments \([a,b]\) and \([c,d]\) intersect if and only if \(\max\{a,c\} \leq \min\{b,d\}\). Their intersection is \([\max\{a,c\}, \min\{b,d\}]\). The length of a segment \([a,b]\) is defined as \(b-a\). Note that a segment may degenerate to a point.
Some test cases require performing these operations online.
inputFormat
The first line contains an integer \(q\) \( (1 \le q \le 10^5)\), the number of queries. Each of the next \(q\) lines contains three integers:
op l r
Here, op
is an integer (1, 2, or 3) denoting the type of the query, and \(l\), \(r\) represent the left and right endpoints of the segment \([l, r]\). It is guaranteed that \(l \le r\).
outputFormat
For each query of type 3, output one line containing a single integer – the sum of the lengths of intersection between \([l, r]\) and each segment in the set.
sample
6
1 1 5
1 3 7
3 2 6
2 4 4
3 1 10
1 2 8
6
0
</p>