CSG-CPC
Online Judge

1178 : Kera’s line segment

         Time Limit: 2 Sec     Memory Limit: 512 Mb     Submitted: 37     Solved: 19    

Description

Kera likes line segments. He has n line segments, and each line segment can be described by li and ri on the number axis. Moreover, each line segment Kera has its preferred value vali.

Then there are m operations:

• (op = 1, li , ri , vali) — Add a line segment(li , ri , vali) on the number axis, according to the above.

• (op = 2, L, R) — Query the maximum difference of preferred values of all line segments that are fully contained by the interval represented by [L, R].

In addition, a line segment(li , ri , vali) fully contained by the interval(L, R) means: L ≤ li≤ ri ≤ R

Input

The first line contains two integer n and m.

Each of the next n lines contains 3 integers li, ri and vali.

Each of the next m lines contains 4 integers (op = 1, ai , bi , vali) or 3 integers (op = 2, A, B).

Specifically, in order to get the real input, you need to create a variable named LastAns with an initial value of 0.

For each operation(op = 1), li = ai xor LastAns, ri = bi xor LastAns.

For each operation(op = 2), L = A xor LastAns, R = B xor LastAns, then LastAns updated to result of this query.

In addition, xor means binary exclusive OR. 1 ≤ n, m ≤ 100000, 1 ≤ li ≤ ri ≤ 3000, 0 ≤ vali ≤ 1e9, 1 ≤ L ≤ R ≤ 3000.

Output

For each operation(op = 2) , print an integer to represent the maximum difference of preferred values. It is guaranteed that each query fully contains at least one line segment.

Sample

3 5
2 3 1
5 6 4
4 10 5
2 2 5
2 2 6
2 2 9
1 2 3 20
2 5 14
0
3
4
19

Hint

The real sample input:

3 5

2 3 1

5 6 4

4 10 5

2 2 5

2 2 6

2 1 10

1 6 7 20

2 1 10