-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFenwickTree.cpp
More file actions
55 lines (50 loc) · 1.01 KB
/
Copy pathFenwickTree.cpp
File metadata and controls
55 lines (50 loc) · 1.01 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <bits/stdc++.h>
using namespace std;
#define ll long long
class FenwickTree{
vector<int> fen;
public:
FenwickTree(int n){
fen.resize(n+1, 0);
}
void update(int i, int add){
while(i < fen.size()){
fen[i] += add;
i += (i & (-i));
}
}
int sum(int i){
int s = 0;
while(i > 0){
s += fen[i];
i -= (i & (-i));
}
return s;
}
int range(int l, int r){
return sum(r) - sum(l-1);
}
//for lower bound
int find(int k){
int curr = 0, prevsum = 0;
int n = fen.size();
for(int i = log2(n); i>=0; i--){
if(prevsum + fen[curr + 1 << i] < k){
curr = curr + 1 << i;
prevsum += fen[curr];
}
}
return curr + 1;
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
}
return 0;
}