sergw's blog

By sergw, history, 8 years ago, In Russian

If we use simple Fenwick tree for finding sum, and every element of initial array is 0 or 1, and we have 2 type of queries:

1) replace given "1" to "0" value (and only 1->0 replacements, so, count of "1" decreases every time)

2) find position of K-th "1" in the array

So, "1)" could be done in O(log2(N)), and what about "2)"?

How to make second query in O(log2(N)) time too, not in O(log2(N)^2) ?

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

»
8 years ago, # |
  Vote: I like it +8 Vote: I do not like it

I think this is the answer for your question.