Under construction

Still being built. Things may change

Intervals and Queries 2

Time limit2sMemory limit512 MB

Summary
Add intervals in order, and for each type 2 query print 1 if a path exists from the a-th to the b-th added interval, otherwise 0.
Level

Medium7 of 10

Topics
Union-find, Segment tree, Intervals
Solved
No attempts yet

Problem

Given NN queries, process them in order. There are two types of queries, as follows. At the start, the set is empty.

  • 1 x y (x < y): Adds a new interval (x,y)(x, y) to the set. The new interval is larger than every interval added before it.
  • 2 a b (a≠ba \neq b): Prints 1 if there is a path from the aa-th added interval to the bb-th added interval, and 0 otherwise. The first interval added is the 1st interval.

To move from interval (x1,y1)(x_1, y_1) to interval (x2,y2)(x_2, y_2), it must hold that x2<x1<y2x_2 < x_1 < y_2 or x2<y1<y2x_2 < y_1 < y_2. A path from interval I1I_1 to interval I2I_2 exists when you can move from I1I_1 to I2I_2 using only the intervals in the set.

Input

The first line contains the number of queries NN (1≤N≤100,0001 \le N \le 100{,}000). Each of the next NN lines contains one query. All values in the input are integers whose absolute value is at most 10910^9. A type 2 query is given only after at least two intervals have been added to the set.

Output

For each type 2 query, print the result.

Examples1

  1. Example 1

    Input
    5
    1 1 5
    1 5 11
    2 1 2
    1 2 9
    2 1 2
    
    Expected output
    0
    1