/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 7ms 596.0 KiB
#3 Accepted 7ms 532.0 KiB
#4 Accepted 8ms 608.0 KiB
#5 Accepted 8ms 532.0 KiB
#6 Accepted 8ms 600.0 KiB
#7 Accepted 15ms 532.0 KiB
#8 Accepted 15ms 532.0 KiB
#9 Accepted 8ms 580.0 KiB
#10 Accepted 8ms 532.0 KiB
#11 Accepted 9ms 576.0 KiB
#12 Accepted 9ms 580.0 KiB
#13 Accepted 9ms 600.0 KiB
#14 Accepted 9ms 532.0 KiB
#15 Accepted 9ms 532.0 KiB
#16 Accepted 9ms 600.0 KiB
#17 Accepted 9ms 536.0 KiB
#18 Accepted 12ms 532.0 KiB
#19 Accepted 12ms 588.0 KiB
#20 Accepted 12ms 572.0 KiB
#21 Accepted 12ms 576.0 KiB
#22 Accepted 12ms 532.0 KiB
#23 Accepted 22ms 596.0 KiB
#24 Accepted 15ms 596.0 KiB
#25 Accepted 15ms 532.0 KiB
#26 Accepted 15ms 532.0 KiB
#27 Accepted 13ms 592.0 KiB
#28 Accepted 14ms 532.0 KiB
#29 Accepted 14ms 616.0 KiB
#30 Accepted 14ms 620.0 KiB
#31 Accepted 17ms 600.0 KiB
#32 Accepted 22ms 608.0 KiB
#33 Accepted 22ms 592.0 KiB
#34 Accepted 22ms 600.0 KiB
#35 Accepted 20ms 532.0 KiB
#36 Accepted 8ms 532.0 KiB
#37 Accepted 8ms 604.0 KiB
#38 Accepted 9ms 532.0 KiB
#39 Accepted 9ms 532.0 KiB
#40 Accepted 9ms 532.0 KiB
#41 Accepted 9ms 532.0 KiB
#42 Accepted 83ms 8.02 MiB
#43 Accepted 83ms 7.77 MiB
#44 Accepted 83ms 8.02 MiB
#45 Accepted 83ms 7.77 MiB
#46 Accepted 82ms 7.828 MiB
#47 Accepted 82ms 7.82 MiB
#48 Accepted 88ms 8.02 MiB
#49 Accepted 80ms 8.02 MiB
#50 Accepted 88ms 7.812 MiB

Code

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using dt = array<int, 2>;

template<typename T, typename L = T>
struct SegmentTreeLazy {
  int n;
  vector<T> tree;
  vector<L> lazy;
  // ----------
  template<typename VAL_T>
  T get_tree_val(VAL_T& val) {
    return val;
  }
  T merge(T a, T b) {
    return max(a, b);
  }
  T lazy_apply(T val_curr, L val_lazy, int l, int r) {
    return val_curr + val_lazy;
  }
  L lazy_pull(L val_curr, L val_new) {
    return val_curr + val_new;
  }

  L DEF_LAZY = L();
  // ----------
  SegmentTreeLazy(int n = 0) : n(n) {
    tree.resize(n<<2);
    lazy.resize(n<<2);
    fill(tree.begin(), tree.end(), 0);
    fill(lazy.begin(), lazy.end(), DEF_LAZY);
  }
  template<typename VAL_T>
  SegmentTreeLazy(vector<VAL_T>& data) : SegmentTreeLazy((int)data.size()) {
    __build(0, 0, n-1, data);
  }
  template<typename VAL_T>
  void __build(int ti, int left, int right, vector<VAL_T>& data) {
    if (left == right) {
      tree[ti] = get_tree_val(data[left]);
      return;
    }
    int tl, tr, tm;
    tl = (ti<<1)+1;
    tr = (ti<<1)+2;
    tm = (left+right)>>1;
    __build(tl, left, tm, data);
    __build(tr, tm+1, right, data);
    tree[ti] = merge(tree[tl], tree[tr]);
  }
  void __push(int ti, int left, int right) {
    if (lazy[ti] == DEF_LAZY) return;
    tree[ti] = lazy_apply(tree[ti], lazy[ti], left, right);
    int tl, tr;
    tl = (ti<<1)+1;
    tr = (ti<<1)+2;
    if (left != right) {
      lazy[tl] = lazy_pull(lazy[tl], lazy[ti]);
      lazy[tr] = lazy_pull(lazy[tr], lazy[ti]);
    }
    lazy[ti] = DEF_LAZY;
  }
  void __update(int ti, int left, int right, int l, int r, L val) {
    __push(ti, left, right);
    if ((l > right) || (r < left)) return;
    if ((l <= left) && (right <= r)) {
      lazy[ti] = lazy_pull(lazy[ti], val);
      __push(ti, left, right);
      return;
    }
    int tl, tr, tm;
    tl = (ti<<1)+1;
    tr = (ti<<1)+2;
    tm = (left+right)>>1;
    __update(tl, left, tm, l, r, val);
    __update(tr, tm+1, right, l, r, val);
    tree[ti] = merge(tree[tl], tree[tr]);
  }
  T __query(int ti, int left, int right, int l, int r) {
    __push(ti, left, right);
    if ((l <= left) && (right <= r)) return tree[ti];
    int tl, tr, tm;
    tl = (ti<<1)+1;
    tr = (ti<<1)+2;
    tm = (left+right)>>1;
    if (l > tm) return __query(tr, tm+1, right, l, r);
    if (r <= tm) return __query(tl, left, tm, l, r);
    return merge(
      __query(tl, left, tm, l, r),
      __query(tr, tm+1, right, l, r)
    );
  }
  void update(int l, int r, L val) { __update(0, 0, n-1, l, r, val); }
  T query(int l, int r) { return __query(0, 0, n-1, l, r); }
};

void test() {
  int n;
  cin >> n;

  vector<ll> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }

  SegmentTreeLazy<ll> seg(v);

  int q;
  cin >> q;
  while (q--) {
  	int t;
  	cin >> t;
  	if (t == 1) {
  		ll l, r, x;
  		cin >> l >> r >> x;
  		l--, r--;
  		seg.update(l, r, x);
  	} else {
  		ll l, r;
  		cin >> l >> r;
  		l--, r--;
  		cout << seg.query(l, r) << "\n";
  	}
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int T = 1;  
  cin >> T;
  for (int i = 1; i <= T; i++) {
    test();
  }
  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:31:34
Judged At
2025-09-02 16:31:34
Judged By
Score
100
Total Time
88ms
Peak Memory
8.02 MiB