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

Автор Lakh, история, 8 лет назад, По-английски

I read the approach for finding Range minimum value using 2 Binary Indexed Trees. Is it possible to do this problem using only one BIT when updates are also there?

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

»
8 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

No, a normal BIT is only able to answer prefix RMQs. A BIT doesn't have enough information to answer a general RMQ (as it doesn't even store the value of each element).

»
8 лет назад, скрыть # |
 
Проголосовать: нравится +12 Проголосовать: не нравится

Found one approach for solving RMQ using BIT(without updates). Suppose our query range is [L,R]. We know that BIT[i] stores the result from index [i-(i & (-i))+1] to index i.

So for given query we start from R. Now first we check if index [R-(R & (-R))+1]>=L or not. if yes we just update the minimum value using the value in BIT[R] and update R by subtracting (R & (-R)) from R . if not then we just take minimum of A[R] and current answer and update R to R-1.

We keep on doing this while(R>=L).