常用板子

yduck / 2023-08-07 / 原文

树状数组

点击查看代码
int c[N];
int ask(int x){
  int res = 0;
  for(; x; x -= x & -x) ans += c[i];
  return ans;
}

void add(int i, int x){
  for(; x <= n; x += x & -x) c[x] += y;
}

int pre(int l, int r){
  return ask(r) - ask(l - 1);
}