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 c201261

Browse files
Update binary_indexed_tree_range_query_range_update.cpp
1 parent e3db0c1 commit c201261

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

‎src/binary_indexed_tree_range_query_range_update.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1+
#include <iostream>
2+
#include <cstdio>
3+
#include <cstring>
4+
using namespace std;
5+
6+
const int MOD = 1000000000+7;
7+
const int INF = 1000000000+5;
8+
19
/**
210
* Description: BIT RURQ (Support range queries and range updates of 1-D array)
311
* Usage: query O(lg(N)), update O(lg(N))
412
* Source: https://github.com/dragonslayerx
13+
* Note: Use 1-based indexing
514
*/
615

716
// Remember to use 1 based indexing
@@ -52,3 +61,28 @@ class BitRPRQ {
5261
BIT::update(B2, r+1, r*v);
5362
}
5463
};
64+
65+
int main() {
66+
int t;
67+
scanf("%d", &t);
68+
while (t--) {
69+
int n, q;
70+
scanf("%d%d", &n, &q);
71+
BitRPRQ B;
72+
while (q--) {
73+
int choice;
74+
scanf("%d", &choice);
75+
int p, q;
76+
long long v;
77+
scanf("%d%d", &p, &q);
78+
if (choice==0) {
79+
long long v;
80+
scanf("%lld", &v);
81+
B.Rupdate(p, q, v);
82+
} else {
83+
long long Answer = B.Rquery(q)-B.Rquery(p-1);
84+
printf("%lld\n", Answer);
85+
}
86+
}
87+
}
88+
}

0 commit comments

Comments
(0)

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