#P8233. Black Interval Query

    ID: 21412 Type: Default 1000ms 256MiB

Black Interval Query

Black Interval Query

You are given an infinite row of cells, initially all white. You need to support the following two types of operations:

  • 1 l r: Paint all cells from index l to r black.
  • 2 l r: Query how many contiguous subintervals within the range [l, r] are completely black.

A contiguous block of k black cells contributes \(\frac{k(k+1)}{2}\) subintervals. Note that if there are several disjoint black segments in the query range, you should calculate this number for each segment and sum them up.

It is guaranteed that all operations are processed sequentially and that once a cell is painted black it remains black forever.

inputFormat

The first line contains an integer Q (Q \(\geq 1\)), the number of operations.

Each of the next Q lines contains an operation in one of the following formats:

  • 1 l r — Paint cells from l to r (inclusive) black.
  • 2 l r — Query the number of all-black contiguous subintervals in the range [l, r].

It is guaranteed that l and r are integers.

outputFormat

For each query operation (type 2), output the answer on a new line.

sample

5
2 1 5
1 2 4
2 1 5
1 3 5
2 3 3
0

6 1

</p>