Fenwick Tree simple task (or not)?

Revision ru1, by sergw, 2016-11-05 14:28:34

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) ?

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
ru1 Russian sergw 2016-11-05 14:28:34 443 Первая редакция (опубликовано)