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

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

I was going through a problem and got stuck in its sub-problem. In simple terms, the sub-problem is ---

Given an array of size n and q queries.
In each query you will get an element x and you have to return the largest index idx such that arr[idx] >= x or state that such index does not exists. If such an index exists, then update its value to x.

Constraints :
1 <= n,q <= 1e5
1 <= arr[i],x <= 1e9

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

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

It can be done offline with sweepline. I recently created a blog and practice contest on this.

Online version of a similar problem on Atcoder

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

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

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

Binary search on suffix maximum.

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

    Thanks for the answer.
    but, what if we have another type of query which updates the element at given index, then how do we approach this ??

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

Can't this be solved with a segment tree? for each node we save it's max, let's say max is in the [mid, right] segment, we keep jumping until it's not, else we jump to the left segment until l==r

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

    Or we can just even use suffix maximum like the guy said, notice that max is strictly increasing from right to left, find the first element such that it's >= x

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

    Thanks a lot, mate