60求助

P1253 扶苏的问题

lian13817981484 @ 2023-03-04 14:35:33

#include<bits/stdc++.h>
using namespace std;
long long n,m,arr[1000005],tree[4000005],tag1[4000005],tag2[4000005],op,a,b,c;
bool tag[4000005];
long long max(long long a,long long b){
    return a < b ? b : a;
}
void pushup(long long x){
    tree[x] = max(tree[x<<1],tree[x<<1|1]);
}
void pushdown(long long z){
    if(tag[z]){
        tag1[z<<1] = tag1[z<<1];
        tag1[z<<1|1] = tag1[z<<1];
        tag2[z<<1] = tag2[z];
        tag2[z<<1|1] = tag2[z<<1|1];
        tree[z<<1] = tag1[z]+tag2[z];
        tree[z<<1|1] = tag1[z]+tag2[z];
        tag1[z<<1] = 0;
        tag1[z<<1|1] = 0;
        tag1[z] = 1;
        tag2[z] = 1;
        tag[z] = 0;
    }
    else{
        tag2[z<<1] += tag2[z];
        tag2[z<<1|1] += tag2[z];
        tree[z<<1] += tag2[z];
        tree[z<<1|1] += tag2[z];
        tag2[z] = 0;
    }
}
void build(long long l,long long r,long long z){
    if(l == r){
        scanf("%lld",&tree[z]);
        return;
    }
    long long mid = l+r >> 1;
    build(l,mid,z<<1);
    build(mid+1,r,z<<1|1);
    pushup(z);
}
void update1(long long l,long long r,long long z,long long x,long long y,long long rt){
    if(x <= l && r <= y){
        tree[z] = rt;
        tag[z] = 1;
        tag1[z] = rt;
        tag2[z] = 0;
        return;
    }
    pushdown(z);
    long long mid = l+r >> 1;
    if(x <= mid)update1(l,mid,z<<1,x,y,rt);
    if(y > mid)update1(mid+1,r,z<<1|1,x,y,rt);
    pushup(z);
}
void update2(long long l,long long r,long long z,long long x,long long y,long long rt){
    if(x <= l && r <= y){
        tree[z] += rt;
        tag2[z] += rt;
        return;
    }
    pushdown(z);
    long long mid = l+r >> 1;
    if(x <= mid)update2(l,mid,z<<1,x,y,rt);
    if(y > mid)update2(mid+1,r,z<<1|1,x,y,rt);
    pushup(z);
}
long long query(long long l,long long r,long long z,long long x,long long y){
    if(x <= l && r <= y){
        return tree[z];
    }
    long long sum = -99999999999999999,mid = l+r >> 1;
    pushdown(z);
    if(x <= mid)sum = max(sum,query(l,mid,z<<1,x,y));
    if(y > mid)sum = max(sum,query(mid+1,r,z<<1|1,x,y));
    return sum;
}
int main(){
    scanf("%lld %lld",&n,&m);
    build(1,n,1);
    for(long long i = 1;i <= m;i++){
        scanf("%lld %lld %lld",&op,&a,&b);
        if(op == 1){
            scanf("%lld",&c);
            update1(1,n,1,a,b,c);
        }
        else if(op == 2){
            scanf("%lld",&c);
            update2(1,n,1,a,b,c); 
        }
        else{
            printf("%lld\n",query(1,n,1,a,b));
        }
    }
    return 0;
}
//GodMode.{ED7BA470-8E54-465E-825C-99712043E01C}

by yinianxingkong @ 2023-03-04 22:45:30

等我调一下……
pushdown操作很迷,完全不能理解(如tag1[z<<1] = tag1[z<<1]
验证码666c寄


|