推荐几个博客:https://blog.csdn.net/int64ago/article/details/7429868搞懂树状数组

https://blog.csdn.net/z309241990/article/details/9615259区间修改

https://blog.csdn.net/whereisherofrom/article/details/78922383完整版+题集

http://www.cnblogs.com/wuyiqi/archive/2011/12/25/2301071.html二进制思想求第k大数

http://www.cnblogs.com/oa414/archive/2011/07/21/2113234.html二分/二进制思想求第k大数

 

一维树状数组模板(区间求和、单点修改)

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 const int maxn=1e5+10;
 6 int bit[maxn],n;
 7 
 8 int lowbit(int x)
 9 {
10     return x&(-x);
11 }
12 
13 void add(int k,int num)
14 {
15     while ( k<=n ) {
16         bit[k]+=num;
17         k+=lowbit(k);
18     }
19 }
20 
21 int sum(int k)
22 {
23     int s=0;
24     while ( k ) {
25         s+=bit[k];
26         k-=lowbit(k);
27     }
28     return s;
29 }
树状数组模板(区间求和+单点修改)

相关文章: