/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 8ms 576.0 KiB
#3 Accepted 24ms 564.0 KiB
#4 Accepted 16ms 576.0 KiB
#5 Accepted 16ms 576.0 KiB
#6 Accepted 24ms 608.0 KiB
#7 Accepted 16ms 532.0 KiB
#8 Accepted 12ms 532.0 KiB
#9 Accepted 21ms 596.0 KiB
#10 Accepted 8ms 604.0 KiB
#11 Accepted 8ms 580.0 KiB
#12 Accepted 23ms 592.0 KiB
#13 Accepted 22ms 532.0 KiB
#14 Accepted 12ms 532.0 KiB
#15 Accepted 12ms 596.0 KiB
#16 Accepted 12ms 576.0 KiB
#17 Accepted 12ms 608.0 KiB
#18 Accepted 24ms 588.0 KiB
#19 Accepted 20ms 532.0 KiB
#20 Accepted 10ms 592.0 KiB
#21 Accepted 12ms 532.0 KiB
#22 Accepted 13ms 596.0 KiB
#23 Accepted 22ms 572.0 KiB
#24 Accepted 12ms 580.0 KiB
#25 Accepted 22ms 532.0 KiB
#26 Accepted 12ms 532.0 KiB
#27 Accepted 12ms 576.0 KiB
#28 Accepted 12ms 584.0 KiB
#29 Accepted 12ms 584.0 KiB
#30 Accepted 24ms 584.0 KiB
#31 Accepted 21ms 532.0 KiB
#32 Accepted 10ms 588.0 KiB
#33 Accepted 10ms 600.0 KiB
#34 Accepted 10ms 608.0 KiB
#35 Accepted 10ms 532.0 KiB
#36 Accepted 10ms 600.0 KiB
#37 Accepted 10ms 576.0 KiB
#38 Accepted 11ms 536.0 KiB
#39 Accepted 12ms 580.0 KiB
#40 Accepted 12ms 596.0 KiB
#41 Accepted 12ms 596.0 KiB
#42 Accepted 90ms 5.438 MiB
#43 Accepted 117ms 5.27 MiB
#44 Accepted 114ms 5.441 MiB
#45 Accepted 113ms 5.52 MiB
#46 Accepted 93ms 5.52 MiB
#47 Accepted 93ms 5.438 MiB
#48 Accepted 94ms 5.434 MiB
#49 Accepted 93ms 5.523 MiB
#50 Accepted 97ms 5.52 MiB

Code

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

const long long INF = 1.1e17;
struct node {
  long long mx, lazy_add;
  node() {
    mx = -INF;
    lazy_add = INF;
  }
};
struct SegmentTreeLazy {
  int size = 1;
  vector<node> st;
  SegmentTreeLazy() {}
  SegmentTreeLazy(int n) { Initial(n); }
  SegmentTreeLazy(vector<int>& a) {
    Initial((int)a.size() - 1);
    Build(1, 0, size, a);
  }
  void Initial(int _n) {
    size = _n;
    int tree_size = 1;
    while (tree_size <= size) tree_size *= 2;
    st.resize(tree_size * 2);
  }
  node Make_node(long long val) {
    node res;
    res.mx = val;
    res.lazy_add = INF;
    return res;
  }
  node Merge(node& l, node& r) {
    node res;
    res.mx = max(l.mx, r.mx);
    return res;
  }
  void Push(int u, int l, int r) {
    if (st[u].lazy_add == INF) return;
    if (l != r) {
      int v = 2 * u, w = 2 * u + 1;
      if (st[v].lazy_add != INF) st[v].lazy_add += st[u].lazy_add;
      else st[v].lazy_add = st[u].lazy_add;
      if (st[w].lazy_add != INF) st[w].lazy_add += st[u].lazy_add;
      else st[w].lazy_add = st[u].lazy_add;
    }
    st[u].mx += st[u].lazy_add;
    st[u].lazy_add = INF;
  }
  void Build(int u, int s, int e, vector<int>& a) {
    if (s == e) {
      st[u] = Make_node(a[s]);
      return;
    }
    int v = 2 * u, w = 2 * u + 1, m = (s + e) / 2;
    Build(v, s, m, a);
    Build(w, m + 1, e, a);
    st[u] = Merge(st[v], st[w]);
  }
  void Update(int u, int s, int e, int l, int r, long long val) {
    Push(u, s, e);
    if (e < l || r < s) return;
    if (l <= s && e <= r) {
      if (st[u].lazy_add != INF) st[u].lazy_add += val;
      else st[u].lazy_add = val;
      Push(u, s, e);
      return;
    }
    int v = 2 * u, w = 2 * u + 1, m = (s + e) / 2;
    Update(v, s, m, l, r, val);
    Update(w, m + 1, e, l, r, val);
    st[u] = Merge(st[v], st[w]);
  }
  void Update(int l, int r, long long val) {
    Update(1, 0, size, l, r, val);
  }
  node Query(int u, int s, int e, int l, int r) {
    Push(u, s, e);
    if (e < l || r < s) {
      return node();
    }
    if (l <= s && e <= r) return st[u];
    int v = 2 * u, w = 2 * u + 1, m = (s + e) / 2;
    node lsum = Query(v, s, m, l, r);
    node rsum = Query(w, m + 1, e, l, r);
    return Merge(lsum, rsum);
  }
  node Query(int l, int r) {
    return Query(1, 0, size, l, r);
  }
};
 
void solve() {
  int n;
  cin >> n;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  SegmentTreeLazy sg(a);
  int q;
  cin >> q;
  while (q--) {
    int type;
    cin >> type;
    if (type == 1) {
      int l, r, x;
      cin >> l >> r >> x;
      sg.Update(l, r, x);
    } else {
      int l, r;
      cin >> l >> r;
      cout << sg.Query(l, r).mx << '\n';
    }
  }
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  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 15:41:01
Judged At
2025-09-02 15:41:01
Judged By
Score
100
Total Time
117ms
Peak Memory
5.523 MiB