树状数组
#include<iostream>
using namespace std;
const int maxn = 1e5 + 5;
//树状数组
int A[maxn] = {};
int lowbit(int n) {
return n & -n;
}
int Get_sum(int index) {//1~index的和
int sum = 0;
while (index)
sum += A[index], index -= lowbit(index);
return sum;
}
void Add(int val, int index) {//index位置加上val
while (index < maxn)
A[index] += val, index += lowbit(index);
}
RMQ
//RMQ
int d[maxn][mn], A[maxn], n;
void RMQ_init() {//预处理求数组d[i][j]:min{[i,i+2^j)}
for (int i = 0; i < n; ++i)
d[i][0] = A[i];
for (int j = 1; (1 << j) <= n; ++j)
for (int i = 0; i + (1 << j) - 1 < n; ++i)
d[i][j] = min(d[i][j - 1], d[i + (1 << j - 1)][j - 1]);
}
int RMQ(int L, int R) {
int k = 0;
while ((1 << (1 + k)) <= R - L + 1) ++k;
return min(d[L][k], d[R - (1 << k) + 1][k]);
}