码迷,mamicode.com
首页 > 编程语言 > 详细

树状数组模板

时间:2018-02-01 14:49:50      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:upd   lin   ace   std   post   ret   sum   int   get   

 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 //更新和查询的为前缀和

 

树状数组模板

标签:upd   lin   ace   std   post   ret   sum   int   get   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!