#P9826. The Mine of Abyss

The Mine of Abyss

The Mine of Abyss

Problem Description

Recently, a huge mine with nn crystals under deep ground has been detected in Byteland. The crystals are labeled by 1,2,,n1,2,\dots,n. The weight of each crystal is not confirmed, but a range can be estimated. Specifically, the weight of the ii-th crystal is an integer within the range [ai,bi][a_i,b_i]. You are the analyzer of this mine. You will be given qq operations, each operation is one of the following:

  • ''1 k a b\texttt{1 k a b}'' (1kn1 \leq k \leq n, 1ab1091\leq a\leq b\leq 10^9): The kk-th crystal is re-scanned. The new report shows its weight is an integer within the range [a,b][a,b]. The previous range is useless now.
  • ''2 l r\texttt{2 l r}'' (1lrn1\leq l\leq r\leq n): Assume some (maybe none or maybe all) crystals indexed in [l,r][l,r] are unearthed, let's measure their total weight, how many possible total weights may we get?

Input

The first line contains a single integer TT (1T51 \leq T \leq 5), the number of test cases. For each test case: The first line contains two integers nn and qq (1n,q500001 \leq n,q \leq 50\,000), denoting the number of crystals and the number of operations. In the next nn lines, the ii-th line contains two integers aia_i and bib_i (1ai,bi1091\leq a_i,b_i\leq 10^9), denoting the weight range of the ii-th crystal. Each of the next qq lines describes an operation in formats described in the statement above. It is guaranteed that all the values of ai,bi,a,ba_i,b_i,a,b are chosen uniformly at random from integers in their corresponding ranges. The randomness condition does not apply to the sample test case, but your solution must pass the sample as well.

Output

For each query, print a single line containing an integer, denoting the number of possible total weights.

Sample Input

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

Sample Output

3
5
9
13

Hint

In the first query, the total weight can be 00, 22 or 33. In the second query, the total weight can be 00, 11, 22, 33 or 44.

Source

2023“钉耙编程”中国大学生算法设计超级联赛(3)