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

Автор code4dj, история, 11 месяцев назад, По-английски

Not able to get python O(nlogn) solution to this problem. This problem can be solved by using set in C++, is there any replacement of it in python, or some implementation you have, which could be used in competitive programming platforms, please share.

Link to the problem

The problem is: You are given an array A of size N initially filled with 0. You have to process Q queries which are of two types:

1 i — Set Ai to 1.

2 i — Find the index of the nearest 0 to i. If there are two indices which are nearest to i print the index which is the smallest.

It is guanranteed that there will be atleast one 0 present in the entire array for query of type 2

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

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

Yes this is a common problem with python users. Pls answer it

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

Checkout this repository: PyRival. The replacement for set can be SortedList