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?
# | User | Rating |
---|---|---|
1 | tourist | 3857 |
2 | jiangly | 3747 |
3 | orzdevinwang | 3706 |
4 | jqdai0815 | 3682 |
5 | ksun48 | 3591 |
6 | gamegame | 3477 |
7 | Benq | 3468 |
8 | Radewoosh | 3463 |
9 | ecnerwala | 3451 |
10 | heuristica | 3431 |
# | User | Contrib. |
---|---|---|
1 | cry | 166 |
2 | -is-this-fft- | 161 |
3 | Qingyu | 160 |
4 | Dominater069 | 159 |
5 | atcoder_official | 157 |
6 | adamant | 155 |
7 | Um_nik | 152 |
8 | djm03178 | 151 |
9 | luogu_official | 150 |
10 | awoo | 148 |
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?
Name |
---|
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).
You sure?
I have read this paper previously .In this paper two BITs have been used . I want to know if we can achieve the same result using a single BIT.
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).
This algorithm will return the correct result but cost
time complexity if you query the range [2, n].
Can you provide some explanation for this complexity. Not able to get it.
Firstly R will go to the biggest 2k satisfying 2k ≤ n, then the progress will be
, between the progress
it would take k times. So the total time complexity is Θ(k2).