萌新妹子60pts 求调 Orz Srz

P1253 扶苏的问题

lyc2006 @ 2023-04-07 21:06:54

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL Inf = 1e18;
const LL maxn = 1e6 + 10;
LL tr[maxn << 2], lazy1[maxn << 1], lazy2[maxn << 1];
LL lson[maxn << 1], rson[maxn << 1], tot;
LL a[maxn];
void pushup(LL k){
    tr[k] = max(tr[lson[k]], tr[rson[k]]);
}
void pushdown1(LL k){
    if(lazy1[k]){
        tr[lson[k]] += lazy1[k];
        tr[rson[k]] += lazy1[k];
        lazy1[lson[k]] += lazy1[k];
        lazy1[rson[k]] += lazy1[k];
        lazy1[k] = 0;
    }
}
void pushdown2(LL k){
    if(lazy2[k] != Inf){
        tr[lson[k]] = lazy2[k];
        tr[rson[k]] = lazy2[k];
        lazy2[lson[k]] = lazy2[k];
        lazy2[rson[k]] = lazy2[k];
        lazy1[k] = 0;
        lazy1[lson[k]] = 0;
        lazy1[rson[k]] = 0;
        lazy2[k] = Inf;
    }
} 
void build(LL l, LL r, LL &k){
    k = ++tot;
    lazy2[k] = Inf;
    if(l == r){
        tr[k] = a[l];
        return;
    }
    LL mid = (l + r) >> 1;
    build(l , mid, lson[k]);
    build(mid + 1, r, rson[k]);
    pushup(k);
}
void update1(LL l, LL r, LL L, LL R, LL k, LL x){
    if(l >= L && r <= R){
        tr[k] += x;
        lazy1[k] += x;
        return;
    }
    pushdown2(k);
    pushdown1(k);
    LL mid = (l + r) >> 1;
    if(L <= mid) update1(l, mid, L, R, lson[k], x);
    if(R > mid) update1(mid + 1, r, L, R, rson[k], x);
    pushup(k);
}
void update2(LL l, LL r, LL L, LL R, LL k, LL x){
    if(l >= L && r <= R){   
        tr[k] =  x;
        lazy2[k] = x;
        lazy1[k] = 0;
        return;
    }
    pushdown2(k);
    pushdown1(k);
    LL mid = (l + r) >> 1;
    if(L <= mid) update2(l, mid, L, R, lson[k], x);
    if(R > mid) update2(mid + 1, r, L, R, rson[k], x);
    pushup(k);
}

LL getsum(LL l, LL r, LL L, LL R, LL k){
    if(l >= L && r <= R){
        return tr[k];
    }
    pushdown2(k);
    pushdown1(k);
    LL mid = (l + r) >> 1;
    LL sum = -Inf;
    if(L <= mid) sum = max(sum, getsum(l, mid, L, R, lson[k]));
    if(R > mid) sum = max(sum, getsum(mid + 1, r, L, R, rson[k]));
    return sum;
}
LL n, q;
LL root;
int main(){
    scanf("%lld%lld", &n, &q);
    for(LL i = 1; i <= n; i++)
        scanf("%lld", &a[i]);    
    build(1, n, root);
    while(q--){
        LL op;
        scanf("%lld", &op);
        if(op == 1){
            LL L, R; LL x;
            scanf("%lld%lld%lld", &L, &R, &x);
            update2(1, n, L, R, root, x);          
        }
        if(op == 2){
            LL L, R; LL x;
            scanf("%lld%lld%lld", &L, &R, &x);
            update1(1, n, L, R, root, x);
        }
        if(op == 3){
            LL L, R;
            scanf("%lld%lld", &L, &R);
            printf("%lld\n", getsum(1, n, L, R, root));
        }
    }   
}

by Milthm @ 2023-04-07 21:21:39

@lyc2006 srz大草


by florence25 @ 2023-04-07 21:27:46

谨防新型电信诈骗,一间机房的,这个楼主是个大胖子


by lyc2006 @ 2023-04-07 22:25:54

@florence25 谢谢,以解决


by DAMDAM @ 2023-11-23 16:01:38

@lyc2006 6


|