求调毒瘤的问题

P1253 扶苏的问题

lhrfc @ 2023-04-30 10:05:56

一直10分,莫名WA

#include <bits/stdc++.h> 
using namespace std;
const int N=1e6+10,inf=0x3f3f3f3f;

struct node{
    int maxx,l,r;
    int add,change;
}tr[N*4];
int a[N];

inline void pushup(int x){
    tr[x].maxx=max(tr[x*2].maxx,tr[x*2+1].maxx);
}
inline void pushdown(int x){
    if(tr[x].change!=inf){
        tr[x*2].change=tr[x].change;
        tr[x*2+1].change=tr[x].change;
        tr[x].maxx=tr[x].change;
        tr[x].change=inf;
    }
    else if(tr[x].add){
        tr[x*2].add=tr[x].add;
        tr[x*2+1].add=tr[x].add;
        tr[x].maxx+=tr[x].add;
    }
    tr[x].add=0;
}

void build(int x,int l,int r){
    tr[x].l=l,tr[x].r=r;
    tr[x].add=0,tr[x].change=inf;
    if(l==r){
        tr[x].maxx=a[l];
        return;
    }
    int mid=(l+r)/2;
    build(x*2,l,mid),build(x*2+1,mid+1,r);
    pushup(x);
}
int query(int x,int l,int r){
    pushdown(x);
    if(l<=tr[x].l&&r>=tr[x].r) return tr[x].maxx;
    int mid=(tr[x].l+tr[x].r)/2,maxx=-inf;
    if(l<=mid) maxx=query(x*2,l,r);
    if(r>mid) maxx=max(maxx,query(x*2+1,l,r));
    return maxx;
}
void change(int x,int l,int r,int k){
    pushdown(x);
    if(l<=tr[x].l&&r>=tr[x].r) tr[x].change=k;
    else{
        int mid=(tr[x].l+tr[x].r)/2;
        if(l<=mid) change(x*2,l,r,k);
        if(r>mid) change(x*2+1,l,r,k);
    }
    pushup(x);
}

void add(int x,int l,int r,int k){
    pushdown(x);
    if(l<=tr[x].l&&r>=tr[x].r) tr[x].add+=k;
    else{
        int mid=(tr[x].l+tr[x].r)/2;
        if(l<=mid) change(x*2,l,r,k);
        if(r>mid) change(x*2+1,l,r,k);
    }
    pushup(x);
}
int n,q;
int main(){
    cin>>n>>q;
    for(int i=1;i<=n;i++) cin>>a[i];
    build(1,1,n);
    while(q--){
        int op,l,r,x;
        cin>>op>>l>>r;
        switch(op){
        case 1:
            cin>>x;
            change(1,l,r,x);
            break;
        case 2:
            cin>>x;
            add(1,l,r,x);
            break;
        case 3:
            cout<<query(1,l,r)<<endl;
            break;
        }
    }
}

by xyzqwq @ 2023-10-17 15:51:54

您开 long long 了吗


|