Блог пользователя MOOONI

Автор MOOONI, история, 5 часов назад, По-английски

There is a vector of intervals (called v) that is initially empty. There are Q queries to process. two types of queries might appear:

  1. Insert an interval (x, y) to an arbitrary place in v. (1 <= x <= y <= 10 ^ 5)

  2. 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

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
5 часов назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by MOOONI (previous revision, new revision, compare).

»
4 часа назад, # |
  Проголосовать: нравится +1 Проголосовать: не нравится

segment tree.

»
69 минут назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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.