- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbit_tree.cpp
More file actions
Latest commit
30 lines (30 loc) · 415 Bytes
/
Copy pathbit_tree.cpp
File metadata and controls
30 lines (30 loc) · 415 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include<iostream>
usingnamespacestd;
constintMAX = 1e4+5;
intBIT[MAX];
int a[MAX];
int n;
intupdate(int x, int val)
{
for(;x <= n;x += x&-x)
BIT[x] += val;
}
intquery(int x)
{
int sum = 0;
for(;x>0;x -= x&-x)
sum += BIT[x];
return sum;
}
intmain(void)
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
update(i, a[i]);
}
//for(int i=0;i<=n;i++)
//cout<<BIT[i]<<endl;
cout<<query(2)<<endl;
}