Skip to content

Commit 33bcc50

Browse files
authored
Add files via upload
1 parent 68df2e5 commit 33bcc50

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

0000.test_project/bit.h

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)