L3-017 森森快递 (30 分)

文章目录

  • L3-017 森森快递 (30 分)

L3-017 森森快递 (30 分)

https://www.cnblogs.com/8023spz/p/10448361.html


#include
#define lson (o<<1)
#define rson (o<<1|1)
using namespace std;
const int maxn = 2e5+10;
typedef long long LL;
LL a[maxn];
LL tree[4*maxn];
LL add[4*maxn];
void build(int o,int l,int r){
    if(l == r){
        tree[o] = a[l];
        return ;
    }
    int mid = (l+r)/2;
    build(lson,l,mid);
    build(rson,mid+1,r);
    tree[o] = min(tree[lson],tree[rson]);
}
void Update(int o,int l,int r,int L,int R,int v){
    if(L <= l && r <= R){
        add[o] += v;
        return ;
    }
    int m = (l+r)/2;
    if(L <= m)
        Update(lson,l,m,L,R,v);
    if(R > m)
        Update(rson,m+1,r,L,R,v);
    tree[o] = min(tree[lson]+add[lson],tree[rson]+add[rson]);
}

LL  Query(int o,int l,int r,int L,int R){
    if(L <= l && r <= R){
        return tree[o]+add[o];
    }
    if(add[o]){
        add[lson] += add[o];
        add[rson] += add[o];
        tree[o]  += add[o];
        add[o] = 0;
    }
    int m = (l+r)/2;
    LL Min = 1e18;
    if(L <= m)
        Min = min(Min,Query(lson,l,m,L,R));
    if(R > m)
        Min = min(Min,Query(rson,m+1,r,L,R));
    return Min;
}


你可能感兴趣的:(L3-017 森森快递 (30 分))