There is a vector of intervals (called v) that is initially empty. There are Q queries to process. two types of queries might appear:
Insert an interval (x, y) to an arbitrary place in v. (1 <= x <= y <= 10 ^ 5)
What is the last interval among the first t elements in v, that contains the number x?
the number of queries is at most 10 ^ 5
Auto comment: topic has been updated by MOOONI (previous revision, new revision, compare).
segment tree.
How?
that is unfortunately beyond my area of expertise
First, process all type 1 queries according to their final position. For example, if the queries are of the form:
type=1 x=1000 y=1000 index=1
1 1000 1000 2
1 1000 1000 1
label the first interval as interval 2, the second as interval 3, the third as interval 1. Then, for each type 2 query, you can use a set or something to keep track of the label of the t-th element of v. From there on you can just use a merge-sort tree.