DataStructure/Fenwick/Fenwick.h
Depends on
Verified with
Code
#include "../../template.h"
template <typename T>
struct Fenwick{
int n;
vector<T> fen;
Fenwick() {}
Fenwick(int _n): n(_n), fen(_n+1) {}
void update(int pos, T val) {
for (; pos <= n; pos += pos & -pos) {
fen[pos] += val;
}
}
T get(int pos) {
T ans = 0;
for (; pos > 0; pos -= pos & -pos) {
ans += fen[pos];
}
return ans;
}
T get(int l, int r) {
return get(r) - get(l - 1);
}
void update_range(int l, int r, T val){
update(l, val);
update(r+1, -val);
}
void reset() {
fill(all(fen), T(0));
}
};
#line 2 "template.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD (ll)(1e9+7)
#define all(x) (x).begin(),(x).end()
#define unique(x) x.erase(unique(all(x)), x.end())
#define INF32 ((1ull<<31)-1)
#define INF64 ((1ull<<63)-1)
#define inf (ll)1e18
#define vi vector<int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
const int mod = 998244353;
void solve();
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
// cin.exceptions(cin.failbit);
// int t; cin >> t;
// while(t--)
solve();
cerr << "\nTime run: " << 1000 * clock() / CLOCKS_PER_SEC << "ms" << '\n';
return 0;
}
#line 2 "DataStructure/Fenwick/Fenwick.h"
template <typename T>
struct Fenwick{
int n;
vector<T> fen;
Fenwick() {}
Fenwick(int _n): n(_n), fen(_n+1) {}
void update(int pos, T val) {
for (; pos <= n; pos += pos & -pos) {
fen[pos] += val;
}
}
T get(int pos) {
T ans = 0;
for (; pos > 0; pos -= pos & -pos) {
ans += fen[pos];
}
return ans;
}
T get(int l, int r) {
return get(r) - get(l - 1);
}
void update_range(int l, int r, T val){
update(l, val);
update(r+1, -val);
}
void reset() {
fill(all(fen), T(0));
}
};
Back to top page