/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Wrong Answer 7ms 532.0 KiB
#3 Wrong Answer 7ms 624.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

#define pb      push_back
#define debug   cout<<"check"<<endl;cout.flush();
#define all(x)  (x).begin(),(x).end()
#define endl    '\n'

const ll N=200005;
const ll mod=1000000007;
const ll INF=2e18L+5;
//template: cp algorithm website
ll t[N*4],lazy[N*4],a[N*4];
void build(int v, int tl, int tr) {
    if (tl == tr) {
        t[v] = a[tl];
    } else {
        int tm = (tl + tr) / 2;
        build( v*2, tl, tm);
        build( v*2+1, tm+1, tr);
        t[v] = max(t[v*2], t[v*2 + 1]);
    }
}

void push(int v) {
    t[v*2] += lazy[v];
    lazy[v*2] += lazy[v];
    t[v*2+1] += lazy[v];
    lazy[v*2+1] += lazy[v];
    lazy[v] = 0;
}

void update(int v, int tl, int tr, int l, int r, int addend) {
    if (l > r) 
        return;
    if (l == tl && tr == r) {
        t[v] += addend;
        lazy[v] += addend;
    } else {
        push(v);
        int tm = (tl + tr) / 2;
        update(v*2, tl, tm, l, min(r, tm), addend);
        update(v*2+1, tm+1, tr, max(l, tm+1), r, addend);
        t[v] = max(t[v*2], t[v*2+1]);
    }
}

int query(int v, int tl, int tr, int l, int r) {
    if (l > r)
        return -INF;
    if (l == tl && tr == r)
        return t[v];
    push(v);
    int tm = (tl + tr) / 2;
    return max(query(v*2, tl, tm, l, min(r, tm)), 
               query(v*2+1, tm+1, tr, max(l, tm+1), r));
}
void solve(){
    ll n;
    cin>>n;
    for(ll i=1;i<=n;i++){
        cin>>a[i];
    }
    build(1,1,n);
    ll q;
    
    cin>>q;
    while(q--){
        ll x;
        cin>>x;
        if(x==1){
            ll l,r,y;
            cin>>l>>r>>y;
            update(1,1,n,l,r,y);
        }
        else{
            ll l,r;
            cin>>l>>r;
            cout<<query(1,1,n,l,r)<<endl;
        }
    }
}

int32_t main(){  
    
    ios::sync_with_stdio(false);cin.tie(nullptr);
    
    int t=1;
    cin>>t;
    for(int i=1;i<=t;i++){
        solve();
    }
    
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1211 Range MAX
Contest
LUCC Presents Intra LU Junior Programming Contest - Replay
Language
C++17 (G++ 13.2.0)
Submit At
2025-09-02 16:39:56
Judged At
2025-09-02 16:39:56
Judged By
Score
2
Total Time
7ms
Peak Memory
624.0 KiB