A Fenwick tree (or binary indexed tree) is a fast data structure for storing and maintaining cumulative frequency tables.
Questions tagged [fenwick-tree]
75 questions
1
vote
1 answer
Compressing coordinates in Fenwick tree
Let's say we have n empty boxes in a row. We are going to put m groups of coins in some consequtive boxes, which are known in advance. We put the 1st group of coins in boxes from i_1 to j_1, the 2nd group in boxes from i_2 to j_2 and so on.
Let be…

Antoine
- 862
- 7
- 22
1
vote
2 answers
How to use Binary Indexed tree to count the number of elements that is smaller than the value at index?
The problem is to count the number of of values less than the value after index. Here is the code, but I can't understand how binary indexed tree has been used to do this?
#include
#include
#include
#define LL long…

Unbound
- 243
- 2
- 12
1
vote
0 answers
SPOJ D-Query , BIT but how?
I am trying to solve D-query problem on Spoj. http://www.spoj.com/problems/DQUERY/
I am thinking about set and memorizing the result but that is really slow. So I was thinking about that Binary Indexed tree could help me to get lgN for one query…

Dario
- 23
- 5
1
vote
0 answers
Minimum/Maximum value in a Binary Indexed Tree
I know how a BIT works. But I was wondering if a BIT can be used to find the minimum/maximum element in the complete range, or more specifically, to find the minimum (or maximum) value after all the update processes have been completed. Now, I know…

Born Again
- 2,139
- 4
- 25
- 27
0
votes
1 answer
How to make this fenwick tree LIS solution faster?
Longest increasing subsequence, but with fenwick tree
Where numbers can be non unique, positive, negative and up to +/- 2^31
Hi tried a lot, and it should work. But its slow. I know that segment trees are supposed to give the O(Nlog N ) solution,…

hopin
- 23
- 4
0
votes
0 answers
How to do and what are range updates in fenwick tree?
Please someone explain me the logic behind the implementation of the range updates in the fenwick tree using the method where we are given a range [i,j] (inclusive) and a value x, and we have to add x to all the elements of the given range. And we…

Majique Mantras
- 1
- 1
0
votes
0 answers
Range query question on fenwick/binary indexed tree
So I have an integer array in which I need to find the sum between range L to R
Also I need to add some value x(int) to range L to R i.e update operation.
I have solved these questions using fenwick tree range sum/update queries but this problem is…

Madhav mishra
- 313
- 4
- 20
0
votes
1 answer
Insertion and Deletion on segment tree or BIT tree?
I am having a hard time in solving a variant of Leetcode 307 Range Sum Query - Mutable and Leetcode 528: Random Pick with Index such that to design a data structure so that I can add elements and each element will has a weight and pop elements based…

Lala James
- 33
- 4
0
votes
0 answers
Get index of element in set (STL C++) in asysmtotically less than O(n)
I have heard that we can use binary search along with Fenwick tree to do it in O(logn*logn) . We can also use PBDS to do it in O(logn) . Can some one explain in detain how to do them . If there is some other way please tell that also.
user12183818
0
votes
1 answer
Fenwick tree(BIT). Find the smallest index with given cumulative frequency in O(logN)
let's say I have a BIT(Fenwick Tree) with non-negative values and I want to find the smallest index in it for given cumulative frequency in O(logN).
Now, I can do it O(log^2(N)) like this.
int l = 0, r = n;
while(l < r) {
int midd = l +…

Hlib Pylypets
- 328
- 2
- 8
0
votes
1 answer
how to increase the size limit of a mutable list in kotlin?
I was attempting to solve the multiset question (https://codeforces.com/contest/1354/problem/D) on codeforces using Fenwick Tree Data structure. I passed the sample test cases but got the memory limit error after submitting, the testcase is…

Kushagra
- 41
- 1
- 1
- 5
0
votes
0 answers
How to find inversion pairs in an array and their index positions?
I find difficult to find the inversion pairs in the array. I got the number of inversion pairs in the array but the logic seems so complex that I can't able to list pairs. I am new to C++, any help is appreciated.
Example:
Input: arr[] = {8, 4,…

Vlive
- 41
- 3
0
votes
1 answer
Remove repeated elements and give a Range Sum
I have a question regarding already asked this question:
SPOJ DQUERY : TLE Even With BIT?
What if I would like to not consider the repeated element to count when I make a range query?
following is an example:
Input
Line 1: n (1 ≤ n ≤ 10^6).
Line 2:…
user9267359
0
votes
1 answer
range update on array
You have n length array having all elements 0 initially. You have to execute 2-types of m commands.
type 1: l r (l ≤ l ≤ r ≤ n) — Increase all elements of the array by one,
whose indices belong to the range [l, r].
type 2: l r…

Prashant Priyadarshi
- 393
- 1
- 3
- 6
0
votes
0 answers
How do I calculate mod sum efficiently with query and updates
Given an array A(say A[1..n]={1,2,3})
now I want two queries:
1) Update(idx,val) : update value of A[idx]=val
2) int Query(MOD).....
int Query(int MOD) : // say MOD =2 , so 1%2 +2%2 + 3%2 =2
int ans=0;
for i=1 to i=n
…

user8517664
- 1
- 1
- 3