Under construction

Still being built. Things may change

Rectangle Painting

Time limit12sMemory limit1024 MB

Summary
Paint horizontal runs of cells black on an infinite grid, and report the tallest height h such that some column in a range is black from y=0 up to h, with queries encrypted online.
Level

Hard8 of 10

Topics
Segment tree, Implementation
Solved
No attempts yet

Statement

There is an infinite grid that extends to the left, to the right, and upward. Every cell (x,y)(x, y) with x∈Zx \in \mathbb{Z} and y≥0y \ge 0 exists. Initially all cells are white. You have to process qq queries of two types:

  1. yiy_i lil_i rir_i: paint all cells (x,yi)(x, y_i) with li≤x≤ril_i \le x \le r_i black. A cell that is already black keeps its color.
  2. lil_i rir_i: consider all cells whose xx coordinate lies in [li;ri][l_i; r_i]. Find the highest cell such that all cells exactly under it are black. Formally, find the maximal hh such that there exists x∈[li;ri]x \in [l_i; r_i] where, for all y∈[0;h)y \in [0;h), the cell (x,y)(x, y) is black.

Queries are encrypted with the answers to earlier queries, so they must be processed online.

Input

The first line contains one integer qq (1≤q≤1051 \le q \le 10^{5}), the number of queries.

Each of the next qq lines contains an encrypted query. Let SS be the sum of the answers to all queries of the second type processed so far. Each query has one of the forms 11 (yi⊕S)(y_i \oplus S) (li⊕S)(l_i \oplus S) (ri⊕S)(r_i \oplus S) or 22 (li⊕S)(l_i \oplus S) (ri⊕S)(r_i \oplus S). The decrypted values satisfy 0≤yi≤2⋅1050 \le y_i \le 2 \cdot 10^{5} and 0≤li≤ri≤2⋅1050 \le l_i \le r_i \le 2 \cdot 10^{5}. The input values may not fit in 32-bit integers.

Add each new answer to SS after processing a query of the second type.

Output

For each query of the second type, print the answer on a separate line.

Hint

SEncryptedQueryAns
01 0 1 11 0 1 1-
02 0 102 0 101
11 1 9 91 0 8 8-
11 0 0 61 1 1 7-
11 0 3 91 1 2 8-
12 5 52 4 40
11 1 5 51 0 4 4-
12 5 52 4 42
32 0 52 3 62
51 7 6 31 2 3 6-

Examples1

  1. Example 1

    Input
    10
    1 0 1 1
    2 0 10
    1 1 9 9
    1 0 0 6
    1 0 3 9
    2 5 5
    1 1 5 5
    2 5 5
    2 0 5
    1 7 6 3
    
    Expected output
    1
    0
    2
    2