#K75082. Nested Sequence Operations

    ID: 34340 Type: Default 1000ms 256MiB

Nested Sequence Operations

Nested Sequence Operations

We define a Nested Sequence data structure which supports three operations:

  1. add L R – Add a new range [L,R][L, R] to the sequence.
  2. check x – Check whether the integer xx lies in any of the current ranges. An integer xx is considered inside a range if LxRL \le x \le R.
  3. merge v w – Merge the range at index v with the range at index w. The merged range becomes the union of the two, i.e. if the ranges are [L1,R1][L_1, R_1] and [L2,R2][L_2, R_2], then the new range is [min(L1,L2),max(R1,R2)][\min(L_1,L_2), \max(R_1,R_2)].

    The operations are provided via standard input. For each check operation, output the result to standard output.

inputFormat

The first line contains an integer NN, the number of operations. Each of the following NN lines contains an operation in one of the following formats:

• add L R • check x • merge v w

Note: For the merge operation, indices are 00-based and refer to the order in which ranges were added.

outputFormat

For each check operation, output a single line containing either 'Yes' if the queried integer is contained in any active range, or 'No' otherwise.## sample

4
add 1 5
add 10 15
check 3
check 6
Yes

No

</p>