/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 7ms 532.0 KiB
#3 Accepted 9ms 532.0 KiB
#4 Accepted 10ms 580.0 KiB
#5 Accepted 10ms 532.0 KiB
#6 Accepted 9ms 580.0 KiB
#7 Accepted 9ms 532.0 KiB
#8 Accepted 10ms 532.0 KiB
#9 Accepted 10ms 580.0 KiB
#10 Accepted 23ms 576.0 KiB
#11 Accepted 23ms 588.0 KiB
#12 Accepted 16ms 600.0 KiB
#13 Accepted 10ms 608.0 KiB
#14 Accepted 13ms 620.0 KiB
#15 Accepted 22ms 564.0 KiB
#16 Accepted 23ms 576.0 KiB
#17 Accepted 23ms 580.0 KiB
#18 Accepted 23ms 580.0 KiB
#19 Accepted 23ms 576.0 KiB
#20 Accepted 20ms 576.0 KiB
#21 Accepted 10ms 764.0 KiB
#22 Accepted 10ms 532.0 KiB
#23 Accepted 10ms 616.0 KiB
#24 Accepted 11ms 532.0 KiB
#25 Accepted 22ms 604.0 KiB
#26 Accepted 17ms 604.0 KiB
#27 Accepted 7ms 604.0 KiB
#28 Accepted 7ms 584.0 KiB
#29 Accepted 7ms 532.0 KiB
#30 Accepted 8ms 532.0 KiB
#31 Accepted 23ms 532.0 KiB
#32 Accepted 23ms 616.0 KiB
#33 Accepted 22ms 580.0 KiB
#34 Accepted 16ms 608.0 KiB
#35 Accepted 16ms 532.0 KiB
#36 Accepted 16ms 580.0 KiB
#37 Accepted 16ms 532.0 KiB
#38 Accepted 23ms 576.0 KiB
#39 Accepted 23ms 584.0 KiB
#40 Accepted 16ms 532.0 KiB
#41 Accepted 16ms 532.0 KiB
#42 Accepted 84ms 8.02 MiB
#43 Accepted 85ms 7.816 MiB
#44 Accepted 86ms 7.816 MiB
#45 Accepted 107ms 7.789 MiB
#46 Accepted 86ms 8.02 MiB
#47 Accepted 97ms 7.816 MiB
#48 Accepted 91ms 7.812 MiB
#49 Accepted 85ms 7.824 MiB
#50 Accepted 111ms 8.02 MiB

Code

#include <bits/stdc++.h>     //   All praise is due to Allah alone, and peace and blessings be
using namespace std;         //         upon him, after whom there is no other Prophet.

template<class T> class Stree { private: 
    vector<T> tree, lazy; int n; T op(T a, T b) { return max(a, b); }
    void push(int node, int l, int r) {
        if (!lazy[node]) return;
        tree[node] = tree[node] + lazy[node];
        if (l != r) {
            int64_t left = node * 2, right = left + 1;
            lazy[left] += lazy[node];
            lazy[right] += lazy[node];
        } lazy[node] = 0;
    }
    void build(int node, int l, int r, const vector<T>& ar) {
        lazy[node] = 0;
        if (l == r) { tree[node] = ar[l - 1]; return; }
        int mid = (r + l) / 2, left = node * 2, right = left + 1;
        build(left, l, mid, ar); build(right, mid + 1, r, ar);
        tree[node] = op(tree[left], tree[right]);
    }
    void update(int node, int l, int r, int qb, int qe, T v) {
        push(node, l, r); if (l > qe || r < qb) return;
        if (l >= qb && r <= qe) {
            lazy[node] += v; push(node, l, r); return;
        }
        int mid = (r + l) / 2, left = node * 2, right = left + 1;
        update(left, l, mid, qb, qe, v);
        update(right, mid + 1, r, qb, qe, v);
        tree[node] = op(tree[left], tree[right]);
    }
    T query(int node, int l, int r, int qb, int qe) {
        push(node, l, r);
        if (l > qe || r < qb) return LLONG_MIN;
        if (l >= qb && r <= qe) return tree[node];
        int mid = (r + l) / 2, left = node * 2, right = left + 1;
        return op(query(left, l, mid, qb, qe), query(right, mid + 1, r, qb, qe));
    }
public: Stree(int size){ n = size, tree.resize(4 * n, 0); lazy.resize(4 * n, 0); }
    void build(const vector<T>& ar) { build(1, 1, n, ar); }
    void update(int l, int r, T v) { update(1, 1, n, l, r, v); }
    T query(int l, int r) { return query(1, 1, n, l, r); }
};

int32_t main() {
    cin.tie(0)->sync_with_stdio(false);

    int32_t Case = 1;    cin >> Case;
    for (int T = 1; T <= Case; T++) {

        int n, q; cin >> n;
        vector<int64_t> ar(n);
        for(int i = 0; i < n; i++) cin >> ar[i];
        Stree<int64_t> st(n);
        st.build(ar);
        cin >> q;

        function<void()> Test_Case = [&]() {
            while(q--) {
                int t, l, r; cin >> t >> l >> r;
                if(t == 1) {
                    int x; cin >> x;
                    st.update(l, r, x);
                }
                else {
                    cout << st.query(l, r) << '\n';
                }
            }
        };
        Test_Case();
    }
    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:05:04
Judged At
2025-09-02 16:05:04
Judged By
Score
100
Total Time
111ms
Peak Memory
8.02 MiB