模板:树状数组

时间:2021-09-02 15:42:21   收藏:0   阅读:15
#include<bits/stdc++.h>
using namespace std;
const int N=500;
int a[N];
int ask(int x){
	int ans=0;
	for(;x;x-=x&-x)ans+=a[x],x-=x&-x;
	return ans;
} 
void add(int x,int y){
	for(int i=x;i<=N;i+=x&-x)a[i]+=y;
}
int main(){
	int x=15;
	while(x){
		printf("%d %d\n",x-(x&-x)+1,x);
		x-=x&-x;
	}
} 

原文:https://www.cnblogs.com/codjjj/p/15213884.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!