We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a967b45 commit c8cf016Copy full SHA for c8cf016
algorithms/data-structures/BinaryIndexedTree2d.cpp
@@ -0,0 +1,35 @@
1
+// Binary Indexed Tree of sum in 2d array
2
+// AbraaoCF - UFCG
3
+#include <bits/stdc++.h>
4
+using namespace std;
5
+#define maxx 1100
6
+int bit[maxx][maxx];
7
+void update(int idx, int idy, int value)
8
+{
9
+ while(idx <= maxx)
10
+ {
11
+ int idy_temp = idy;
12
+ while(idy_temp <= maxx)
13
14
+ bit[idx][idy_temp] += value;
15
+ idy_temp += (idy_temp &-idy_temp);
16
+ }
17
+ idx += (idx&-idx);
18
19
+ return;
20
+}
21
+int query(int idx,int idy)
22
23
+ int sum = 0;
24
+ while(idx > 0)
25
26
27
+ while(idy_temp > 0)
28
29
+ sum += bit[idx][idy_temp];
30
+ idy_temp -= (idy_temp &-idy_temp);
31
32
+ idx -= (idx&-idx);
33
34
+ return sum;
35
0 commit comments