luogu#P8861. 线段

    ID: 8109 远端评测题 3000ms 1024MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>线段树洛谷原创O2优化分治洛谷月赛

线段

Problem Description

There is an initially empty set of segments. You need to process qq queries. Each query is in one of the following three forms:

  1. Add a new segment [li,ri][l_i, r_i].
  2. For all segments in the set that intersect with [li,ri][l_i, r_i], modify each of them into its intersection with [li,ri][l_i, r_i].
  3. Compute the sum of lengths of the intersections between [li,ri][l_i, r_i] and all segments in the set that intersect with [li,ri][l_i, r_i].

Two segments [a,b][a,b] and [c,d][c,d] intersect if and only if max{a,c}min{b,d}\max\{a,c\} \leq \min\{b,d\}. Their intersection is [max{a,c},min{b,d}][\max\{a,c\}, \min\{b,d\}].

The length of a segment [a,b][a,b] is bab-a.

In some test points, you need to perform these operations online.

Note: In this problem, a segment may degenerate into a single point.

Input Format

The first line contains two positive integers qq and typetype, representing the number of operations and the forced online parameter.

The next qq lines each contain three positive integers opt,li,riopt, l_i', r_i', where optopt indicates the operation type.

Let lastlast be the answer to the previous type 33 query (lastlast is initially 00). Then the real values are $l_i = ( l_i' + type \times last ) \bmod ( 2 \times 10^5 + 1 )$, $r_i = ( r_i' + type \times last ) \bmod ( 2 \times 10^5 + 1 )$.

The data guarantees that 1liri2×1051 \leq l_i \leq r_i \leq 2 \times 10^5.

Output Format

For each type 33 query, output one line containing the answer.

9 0
1 1 5
1 6 8
1 2 3
3 3 8
2 4 6
1 5 9
2 2 7
3 2 7
3 3 6

4
4
2

Hint

Sample Explanation

The set of segments after each operation:

  • After the first: {[1,5]}\{ [1,5] \}
  • After the second: {[1,5],[6,8]}\{ [1,5],[6,8] \}
  • After the third: {[1,5],[6,8],[2,3]}\{ [1,5],[6,8],[2,3] \}
  • After the fifth: {[4,5],[6,6],[2,3]}\{ [4,5],[6,6],[2,3] \}
  • After the sixth: {[4,5],[6,6],[2,3],[5,9]}\{ [4,5],[6,6],[2,3],[5,9] \}
  • After the seventh: {[4,5],[6,6],[2,3],[5,7]}\{ [4,5],[6,6],[2,3],[5,7] \}

Constraints

Let k1,k2,k3k_1, k_2, k_3 be the numbers of queries with opt=1,2,3opt=1,2,3, respectively.

Test Point ID k1k_1 \leq k2k_2 \leq k3k_3 \leq type=type= Special Property
121 \sim 2 100100 =0=0 None
353 \sim 5 10510^5 55 3×1053 \times 10^5
686 \sim 8 10510^5 11 All type 22 operations are after all type 11 operations
9129 \sim 12 3×1053 \times 10^5
131713 \sim 17 li105ril_i \leq 10^5 \leq r_i
182018 \sim 20 5×1045 \times 10^4 None
212521 \sim 25 10510^5 =1=1

For all data, 1q5×1051 \leq q \leq 5 \times 10^5, k31k_3 \geq 1, 0li,ri2×1050 \leq l_i', r_i' \leq 2 \times 10^5, 1liri2×1051 \leq l_i \leq r_i \leq 2 \times 10^5, 0type10 \leq type \leq 1, 1opt31 \leq opt \leq 3.

Translated by ChatGPT 5