Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fe4955a

Browse files
author
atcoder-live
committed
BIT
1 parent f27f4a6 commit fe4955a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

‎bit.cpp‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Binary Indexed Tree (Fenwick Tree)
2+
// https://youtu.be/lyHk98daDJo?t=7960
3+
template<typename T>
4+
struct BIT {
5+
int n;
6+
vector<T> d;
7+
BIT(int n=0):n(n),d(n+1) {}
8+
void add(int i, T x=1) {
9+
for (i++; i <= n; i += i&-i) {
10+
d[i] += x;
11+
}
12+
}
13+
T sum(int i) {
14+
T x = 0;
15+
for (i++; i; i -= i&-i) {
16+
x += d[i];
17+
}
18+
return x;
19+
}
20+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /