Skip to content

Instantly share code, notes, and snippets.

@jerinphilip
Created June 23, 2015 08:04
Show Gist options
  • Save jerinphilip/241feeda666e32ffeab0 to your computer and use it in GitHub Desktop.
Save jerinphilip/241feeda666e32ffeab0 to your computer and use it in GitHub Desktop.
Implementation of Binary Indexed Tree
class BIT{
int T[MAX], size;
public:
BIT(int n){
size = n;
for(int i=1; i<=n; i++)
T[size] = 0;
}
int get(int i){
int s = 0;
while(i>0){
s = s + T[i];
i = i - (i&(-i));
}
return s;
}
void add(int i, int v){
while(i<=size){
T[i] = T[i] + v;
i = i + (i&(-i));
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment