首页 > 编程语言 > 详细

树状数组模板

时间:2018-02-01 14:23:47      阅读:217      评论:0      收藏:0      [点我收藏+]
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 //https://www.cnblogs.com/hsd-/p/6139376.html
 4 int a[MAXN],tree[MAXN];
 5 //低位一
 6 int lowbit(int t)
 7 {
 8     return t&(-t);
 9 }
10 
11 //区间更新
12 void update(int x,int y)
13 {
14     while(x<=maxn)
15     {
16         tree[x]+=y;
17         x+=lowbit(x);
18     }
19 
20 }
21 
22 //区间查询
23 int getsum(int x)
24 {
25     int ans=0;
26     while(x>=1)
27     {
28         ans+=tree[x];
29         x-=lowbit(x);
30     }
31     return ans;
32 }
33 //更新和查询的为前缀和

 

树状数组模板

原文:https://www.cnblogs.com/reminito/p/8398460.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!