单点更新线段树

线段树是一种强(傻)大(逼)的数据结构,但博主实在是无聊,只好默默的玩一下这种强(傻)大(逼)的数据结构(博主N年前就已经掌握了这种数据结构)。但博主为了共产(工厂)主义事业,终于写下了这个代码(为NOIPPJ的水题奋斗)。

/*************************************************************************
    > File Name: \LJF\数据结构\树\线段树\单点更新模板.cpp
    > Author: ljf_cnyali
    > Mail: ljfcnyali@gmail.com 
    > Last modifiedz: 2017-02-2 11:49
    > Description: This is a large group of God's program information.
 ************************************************************************/

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>

using namespace std;

#define REP(i, a, b) for(int i = (a), _end_ = (b);i <= _end_; ++ i)
#define mem(a) memset((a), 0, sizeof(a))
#define str(a) strlen(a)
#define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1

const int maxn = 10000;

int n, m;

int Tree[maxn << 2];

void pushup(int rt) {
    Tree[rt] = Tree[rt << 1] + Tree[rt << 1 | 1];   
}

void Bulid(int l, int r, int rt) {
    if(l == r) {
        Tree[rt] = 0;
        return;
    }
    int mid = (l + r) >> 1;
    Bulid(lson);
    Bulid(rson);
    pushup(rt);
}

void update(int pos, int val, int l, int r, int rt) {
    if(l == r) {
        Tree[rt] += val;
        return;
    }   
    int mid = (l + r) >> 1;
    if(pos <= mid)
        update(pos, val, lson);
    else
        update(pos, val, rson);
    pushup(rt);
}

int query(int L, int R, int l, int r, int rt) {
    if(L <= r && r <= R)
        return Tree[rt];
    int mid = (l + r) >> 1;
    int ret = 0;
    if(L <= mid)
        ret += query(L, R, lson);
    if(R > mid)
        ret += query(L, R, rson);
    return ret;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif


    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值