C++ set replacement in Python?

Revision en1, by code4dj, 2024-02-08 21:02:05

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

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English code4dj 2024-02-08 21:02:05 803 Initial revision (published)