-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFenwick_Tree.cpp
More file actions
78 lines (61 loc) · 1.4 KB
/
Fenwick_Tree.cpp
File metadata and controls
78 lines (61 loc) · 1.4 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#ifdef LOCAL
#include <debug.h>
#else
#define dbg(x...)
#endif
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using ll = long long;
const ll mod = 1e9 + 7;
const ll modd = 998244353;
template<typename T>
struct Fenwick {
ll n;
vector<T> bit;
Fenwick(ll size = 0) {
this->n = size;
bit.assign(size + 1, T(0));
}
template<typename U>
Fenwick(const vector<U> &a) : Fenwick((ll)a.size()) {
for (ll i = 0; i < (ll)a.size(); i++) {
add(i, T(a[i]));
}
}
void add(ll idx, const T &val) {
for (ll i = idx + 1; i <= n; i += i & -i)
bit[i] += val;
}
T query(ll idx) const {
T ans = 0;
for (ll i = idx + 1; i > 0; i -= i & -i)
ans += bit[i];
return ans;
}
T query(ll l, ll r) const {
return query(r) - (l > 0 ? query(l - 1) : T(0));
}
};
template<typename U>
Fenwick(const vector<U>&) -> Fenwick<U>;
void solve()
{
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
for (int i = 1; i <= t; i++) {
cerr << "Testcase No. - " << i << "\n";
solve();
}
return 0;
}