Intervals and Queries 2
Time limit2sMemory limit512 MB
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 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 to the set. The new interval is larger than every interval added before it.2 a b(): Prints 1 if there is a path from the -th added interval to the -th added interval, and 0 otherwise. The first interval added is the 1st interval.
To move from interval to interval , it must hold that or . A path from interval to interval exists when you can move from to using only the intervals in the set.
Input
The first line contains the number of queries (). Each of the next lines contains one query. All values in the input are integers whose absolute value is at most . 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.