Create BIT.cc
This commit is contained in:
parent
2bc8d54288
commit
9f5f1f6043
|
@ -0,0 +1,22 @@
|
|||
#include "../include.hh"
|
||||
|
||||
template<typename T>
|
||||
struct BIT {
|
||||
int n;
|
||||
vector<T> c;
|
||||
BIT(size_t n) : n(n), c(n + 1) {}
|
||||
void add(size_t i, const T& k) {
|
||||
while (i <= n) {
|
||||
c[i] += k;
|
||||
i += lowbit(i);
|
||||
}
|
||||
}
|
||||
T getsum(size_t i) {
|
||||
T res = {};
|
||||
while (i) {
|
||||
res += c[i];
|
||||
i -= lowbit(i);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue