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 f1316a7

Browse files
Update binary_indexed_tree.cpp
1 parent a651664 commit f1316a7

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

‎src/binary_indexed_tree.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,30 @@ void update(int indx, int x){
2424
indx += (indx & -indx);
2525
}
2626
}
27+
28+
int main() {
29+
int n;
30+
cin >> n;
31+
vector<long long> a(n);
32+
for (int i = 1; i <= n; i++) {
33+
cin >> a[i];
34+
update(i, a[i]);
35+
}
36+
int q;
37+
cin >> q;
38+
while (q--) {
39+
int choice;
40+
cin >> choice;
41+
if (choice) {
42+
int l, r;
43+
cin >> l >> r;
44+
cout << query(r) - query(l-1) << endl;
45+
} else {
46+
int p;
47+
long long x;
48+
cin >> p >> x;
49+
update(p, x);
50+
}
51+
}
52+
}
53+

0 commit comments

Comments
(0)

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