/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Wrong Answer 9ms 532.0 KiB
#3 Wrong Answer 10ms 640.0 KiB

Code

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

#define ll long long
#define endl '\n'

const int nn = 1e5 + 17, mod = 1e9 + 7;
int n, A[nn];

struct STL {
    #define lc (node << 1)
    #define rc ((node << 1) + 1)
    
    ll T[4 * nn], Lazy [4 * nn];
    
    inline void push(int node, int b, int e) {
        if (Lazy[node] == 0) {
            return;
        }
        T[node] = T[node] + Lazy[node] * (e - b + 1);
        if (b != e) {
            Lazy[lc] = Lazy[lc] + Lazy[node];
            Lazy[rc] = Lazy[rc] + Lazy[node];
        } 
        Lazy[node] = 0;
    }
    
    inline long long combine(ll a, ll b) {
        return max(a, b);
    }
    
    inline void pull(int node) {
        T[node] = max(T[lc], T[rc]);
    }
    
    void build(int node, int b, int e) {
        Lazy[node] = 0;
        if (b == e) {
            T[node] = A[b]; return;
        } 
        int mid = (b + e) / 2;
        build(lc, b, mid);
        build(rc, mid + 1, e);
        T[node] = max(T[lc], T[rc]);
    }
    
    void upd(int node, int b, int e, int i, int j, int x) {
        push(node, b, e);
        if (j < b || e < i) {
            return;
        }
        if (i <= b && e <= b) {
            Lazy[node] += x;
            push(node, b, e);
            return;
        }
        
        int mid = (e + b) / 2;
        upd(lc, b, mid, i, j, x);
        upd(rc, mid + 1, e, i, j, x);
        pull(node);
    }
    
    ll query(int node, int b, int e, int i, int j) {
        push(node, b, e);
        if (i > e || b > j) return 0;
        if (i <= b && e <= j) {
            return T[node];
        }
        int mid = (b + e) / 2;
        ll a = query(lc, b, mid, i, j);
        ll c = query(rc, mid + 1, e, i, j);
        return max(a, c);
    }
    
}T;

void Try() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> A[i];
    }
    
    T.build(1, 1, n);
    
    int q; 
    cin >> q;
    while(q--) {
        int t, l, r;
        cin >> t >> l >> r;
        if (t == 1) {
            int x; cin >> x;
            T.upd(1, 1, n, l, r, x);
        }
        else cout << T.query(1, 1, n, l, r) << endl;
    }
}

int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0);

    int t = 1;
    cin >> t;
    for (int i = 1; i <= t; i++) {
        Try();
    }

}

Information

Submit By
Type
Submission
Problem
P1211 Range MAX
Contest
LUCC Presents Kick & Code Intra LU Programming Contest
Language
C++17 (G++ 13.2.0)
Submit At
2025-09-01 06:50:04
Judged At
2025-09-01 06:50:04
Judged By
Score
2
Total Time
10ms
Peak Memory
640.0 KiB