树状数组-百度百科

Contributor:肥婆纳妾 Type:代码 Date time:2020-01-02 00:09:21 Favorite:3 Score:0
返回上页 Report
请选择举报理由:




Collection Modify the typo
#include<iostream>
#include<vector>
using namespace std;
class BinTree:vector<int>
{
public:
explicit BinTree(int k=0)
{
assign(k+1,0);
}
int lowbit(int k)
{
return k&-k;
}
int sum(int k)
{
return k>0?sum(k-lowbit(k))+(*this)[k]:0;
}
int last()
{
return size()-1;
}
void add(int k,int w)
{
if(k>last())return;
(*this)[k]+=w;
add(k+lowbit(k),w);
}
};
int main()
{
BinTree test(123);
test.add(27,72);
cout<<test.sum(26)<<' '<<test.sum(27)<<' '<<test.sum(123);
}
声明:以上文章均为用户自行添加,仅供打字交流使用,不代表本站观点,本站不承担任何法律责任,特此声明!如果有侵犯到您的权利,请及时联系我们删除。
Hot degree:
Difficulty:
quality:
Description: the system according to the heat, the difficulty, the quality of automatic certification, the certification of the article will be involved in typing!

This paper typing ranking TOP20

登录后可见

用户更多文章推荐