code4dj's blog

By code4dj, history, 11 months ago, In English

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

  • Vote: I like it
  • +4
  • Vote: I do not like it

»
11 months ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
11 months ago, # |
  Vote: I like it +3 Vote: I do not like it

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