Template Library
Fenwick Tree #include<bits/stdc++.h>using namespace std; template<typename T> class FenwickTree { vector<T> BIT; int n; public: FenwickTree(int n,vector<T>& arr,T def) { BIT.assign(n + 1, def); this->n = n; } void update(int i,T v) { while (i <= n) BIT[i] += v, i += i & -i; } T query(int i,T def) { //get from 0 to i T sum = def; while(i>0) sum += BIT[i], i -= i & -i; return sum; } }; class RangeFenwickTree { int n; vector<int> BIT1; vector<int> BIT2; public: RangeFenwickTree(int n,vector<int>& arr) { this->n = n; BIT1.