Skip to main content
Filter by
Sorted by
Tagged with
1 vote
1 answer
337 views

I'm currently attempting to solve the Reverse Pairs problem on LeetCode, where I need to count the number of reverse pairs (i, j) in an array nums such that 0 <= i < j < nums.length and nums[...
Vishal Jangid's user avatar
0 votes
1 answer
359 views

Given array of numbers of size n. We will perform 2 operations such as: Update: update range of numbers (l, r) Query: sum of numbers (l, r). To compute range update, range queries can we use only one ...
Rupasai Rangaraju's user avatar
1 vote
1 answer
332 views

This is a problem about substrings that I created. I am wondering how to implement an O(nlog(n)) solution to this problem because the naive approach is pretty easy. Here is how it goes. You have a ...
halcyon44's user avatar
3 votes
0 answers
316 views

I know that if we want to update node with index i, we need to recursively update node i = i + lowBit(i) until the new value exceeds the size of the binary indexed tree. My question is: how to prove ...
ihainan's user avatar
  • 75
0 votes
1 answer
535 views

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, ...
Hlib Pylypets's user avatar
0 votes
1 answer
3k views

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 ...
Kushagra's user avatar
3 votes
0 answers
270 views

Given an array A with n elements which starts with all 0s and another array W also with n elements (all greater than 0), we want to perform the following operation repeatedly; For a given k, ...
piedpiper's user avatar
  • 1,380
7 votes
4 answers
11k views

I found that many people use x += x & (-x), x -= x & (-x) to solve the interval tree problem (While implementing data structures like segment tree, binary indexed tree etc). Can you explain ...
eleven22's user avatar
0 votes
1 answer
81 views

I was given this challenge in a programming "class". Eventually I decided to go for the "Binary Indexed Trees" solution, as data structures are a thing I'd like to know more about. Implementing BIT ...
Nedas Bolevičius's user avatar
4 votes
1 answer
660 views

My question concerns the full reasoning behind the update step in Binary Indexed Trees (Fenwick Trees). As such, when updating our array with a certain increment, at a certain position, the update ...
user43389's user avatar
  • 729
1 vote
2 answers
140 views

Problem: I have an input of n vectors: (x, y, z): x ∈ {1..n},y ∈ {1..n},z ∈ {1..n} (every "dimension" is set(1..n)) *I mean that in one vector x,y,z can be the same(x=y=z), but for ∀v1,v2 =&...
bordus's user avatar
  • 35
3 votes
0 answers
306 views

Is Binary Index Tree and Binary Search Tree are same thing? If not whats the actual difference between them and when to use what?
0xAliHn's user avatar
  • 19.4k
1 vote
1 answer
534 views

The problem I have an array with N numbers. The numbers may be disctints and may also be unordered. I have to answer Q queries about how many distinct numbers there are between A and B. Where A, B ...
Diego Becquer's user avatar
1 vote
0 answers
146 views

Inversion count in an given array is a very famous with a time complexity of O(NlogN). However, I wonder whether there is a way to do it with update. Input format: first line consist of an integer n; ...
Brian Lee's user avatar
0 votes
1 answer
683 views

I searched on internet but couldn't find a good one. I got some help from geeksforgeeks.org but can't understand the construction part where we are subtracting v1-v2-v2-v4+v3 from aux[i][j] while ...
goku's user avatar
  • 156
0 votes
1 answer
334 views

I want to range query a string using Fenwick tree. But something is going wrong with my code. Concatenation is giving error Eror is:[Error] no match for 'operator+=' (operand types are 'std::vector >'...
nRT's user avatar
  • 13
1 vote
1 answer
560 views

I was trying to solve this algorithmic problem and I came across this nice solution: "The idea is to treat the ai, bi and ci asymmetrically. The BIT supports minimum queries for key intervals ...
aroma's user avatar
  • 1,421
1 vote
1 answer
788 views

For a given array of integers, we have to calculate XORed sum withing a given range [L, R], by XORed sum I mean Σ(Arr[i]^p) where i:[L,R] and p is some number. This can be easily done while ...
Roshan's user avatar
  • 150
0 votes
1 answer
542 views

Based on this paper, I found that it is quite brilliant to use two BITs to do RMQ in O(lg N), as it is easier to code than segment tree, and the paper claims it performs better than other data ...
shole's user avatar
  • 4,134
0 votes
1 answer
396 views

I am trying to solve the following problem: Given an array of items with integer weights (arbitrary order), we can have 2 possible operations: Query: Output the number of items that are of ...
Donald's user avatar
  • 1,330
0 votes
1 answer
345 views

This is the code for the sum query from Index 0 to Index X Int query(int x){ Int sum=0; for(; x>0; x -= x &(-x) ) sum += BIT[x]; Return sum; } I have two arrays BIT[] and a[]. I store ...
Sam_Buck's user avatar
-1 votes
1 answer
99 views

I am solving a problem. Count of Range Sum Given an integer array nums, return the number of range sums that lie in [lower, upper] inclusive. Range sum S(i, j) is defined as the ...
Isabella Lu's user avatar
-2 votes
1 answer
205 views

Can some one help me understand in binary index tree when we do range update- Why no we update every element why only starting element and ending element For example 0 we have to update array ...
Priyansh Nigam's user avatar
2 votes
0 answers
329 views

This question sounds very vague and needs some explanation: I learned about Binary Indexed Tree a few weeks ago. This data structure is a brilliant design. It actually took me very long to figure out ...
xialin's user avatar
  • 7,756
-1 votes
1 answer
67 views

We have an array arr[0 . . . n-1]. We should be able to efficiently find the minimum value from index qs (query start) to qe (query end) where 0 <= qs <= qe <= n-1 I know the data structure ...
user4415506's user avatar
1 vote
2 answers
3k views

Here is the problem, and here is a solution. First part is simple enough. It's the second part that I don't get, no matter how hard I try. You basically have two sets of intervals and need to find ...
thule's user avatar
  • 4,242
1 vote
2 answers
364 views

How can I use Binary Indexed Tree for range update such that each element A[k] in a range say [i..j] is updated to A[k]*c where c is some constant. And I need to do point queries after such update ...
Chandan Mittal's user avatar
7 votes
1 answer
6k views

How can I find the total number of Increasing sub-sequences of certain length with Binary Index Tree(BIT)? Actually this is a problem from Spoj Online Judge Example Suppose I have an array 1,2,2,10 ...
Mostafiz Rahman's user avatar
2 votes
1 answer
1k views

edit: I was trying to solve a spoj problem. Here is the link to the problem : http://spoj.pl/problems/BRCKTS I can think of two possible data structures for solving the problem one using segment tree ...
amitkarmakar's user avatar
  • 1,263