代码如下,其中 lowbit CE 了。
class BinaryIndexedTree {
private:
int tree[Maxn];
auto lowbit = [](const int &t) -> int { return t&(-t); };
public:
inline void Add(int t, bool flag) {
// printf("bit.Add(%d, %d)\n", t, flag);
for(; t<=N; t+=lowbit(t)) tree[t] += (flag ?1 :-1);
}
inline int Ask(int t) {
int res = 0;
for(; t; t-=lowbit(t)) res += tree[t];
return res;
}
} bit;