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 68df2e5 commit 33bcc50Copy full SHA for 33bcc50
0000.test_project/bit.h
@@ -0,0 +1,47 @@
1
+#ifndef BIT
2
+#define BIT
3
+
4
+#include<vector>
5
+using namespace std;
6
7
+class bit {
8
+private:
9
+ vector<int> t;
10
+ int n;
11
+public:
12
+ bit() {
13
+ t.clear();
14
+ n=0;
15
+ }
16
17
+ bit(int n) {
18
+ t=vector<int>(n+1);
19
+ this->n=n;
20
21
22
+ int lowbit(int x)
23
+ {
24
+ return x&(-x);
25
26
27
+ void add(int x,int k)
28
29
+ for (;x<=n;x+=lowbit(x))
30
+ t.at(x)+=k;
31
32
33
+ int ask(int x)
34
35
+ int ans=0;
36
+ for (;x>0;x-=lowbit(x))
37
+ ans+=t.at(x);
38
+ return ans;
39
40
41
+ int interval_sum(int x,int y)
42
43
+ return ask(y)-ask(x-1);
44
45
+};
46
47
+#endif
0 commit comments