1
0
Fork 0

Create BIT.cc

This commit is contained in:
Ariel 2024-01-22 17:09:44 +08:00 committed by GitHub
parent 2bc8d54288
commit 9f5f1f6043
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 22 additions and 0 deletions

22
trees/BIT.cc Normal file
View File

@ -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;
}
};