先附上链接,https://www.cnblogs.com/findview/p/11281628.html 写的是真的言简意赅,平易近小白,强推。
树状数组板子//板子
#include
using namespace std;
int n;
int a[1000],c[1000];
int lowbit(int x){
return x&(-x);
}
int getsum(int x){
int ans=0;
while(x>0){
ans+=c[x];
x-=lowbit(x);//-,注意
}
return ans;
}
void update(int x,int add){
a[x]+=add;//注意
while(x>n;
for(int i=1;i>tmp;
update(i,tmp);//输入的过程就是更新的过程
}
int ans=getsum(n-1);
cout
关注
打赏