Блог пользователя _amit.nehra_

Автор _amit.nehra_, история, 8 месяцев назад, По-английски

There are N numbers(1 to N), arranged in increasing order. There are q operation that has to be performed on permutation. In ith operation, we'll have Li, Ri(two indices) and we have to reverse the permutation from arr[Li] to arr[Ri]. At last, after performing all operations, we have to return value at kth position.

N<=10^9
q<=10^5
1<= Li, Ri <=N
k<=N

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

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

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

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

Link to the question?

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

I think i have done similar question using Treap data structure.

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

unfortunately I can't help you :_(

»
8 месяцев назад, # |
  Проголосовать: нравится -9 Проголосовать: не нравится

You can use treap or splay tree.

»
8 месяцев назад, # |
Rev. 2   Проголосовать: нравится +6 Проголосовать: не нравится

You can use treaps as others have said but since this is from an OA, treap is definitely not the intended solution.

lets say after q queries x is at position k, then doing the q queries again in reverse would take x back to position x since it's a permutation. So what we can do is reverse query array and then find at what index k will be after q queries and this can be done quite easily. that index will be our answer.