标签:get its int 数组 c++ 树状数组 cin fine main
本博客仅贴出树状数组模板
#include <bits/stdc++.h>
#define lowbit(x) (x & -x)
using namespace std;
const int N = 10010;
int a[N], n;
//a[x] += c
void insert(int x, int c){
for(;x <= n; x += lowbit(x))a[x] += c;
}
// sum([1, x])
int get(int x){
int res = 0;
for(;x > 0; x -= lowbit(x))res += a[x];
return res;
}
int main(){
int t;
cin >> n;
for(int i = 1;i <= n; i++)cin >> t, insert(i, t);
}
标签:get its int 数组 c++ 树状数组 cin fine main
原文地址:https://www.cnblogs.com/waitti/p/13183723.html