/ 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 532.0 KiB

Code

// @rakibul-islam

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

using ll = long long;
const ll oo = 1e17;
const int N = 1e5 + 5;

struct node{
  ll lazy, sum;
  node() {
    lazy = sum = 0;
  }
};
 
struct seglazy{
  vector<node> tr;
  vector<ll> a;
  seglazy (ll N) {
    tr.resize(4 * N);
    a.resize(N);
  }
  void merge (node &res, node &l, node &r) {
    res.sum = max(l.sum, r.sum);
  }
  void push_down(int cur, int child) {
    if (tr[cur].lazy) {
      tr[child].lazy += tr[cur].lazy;
    }
  }
  void push(int u, int l, int r){
    if (l != r) {
      // Push down the current value
      int v = u << 1;
      push_down(u, v);
      push_down(u, v | 1);
    }
    // Add current value to the current node
    if (tr[u].lazy != 0) {
      tr[u].sum += tr[u].lazy;
      tr[u].lazy = 0;
    }
    // Clear the currect lazy value
    tr[u].lazy = 0;
  }
  void build (int u, int s, int e) {
    if (s == e) {
      // Build the tree
      tr[u].sum = a[s];
      return;
    }
    int v = u << 1, w = v | 1, m = (s + e) >> 1;
    build(v, s, m);
    build(w, m + 1, e);
    merge(tr[u], tr[v], tr[w]);
  }
  void update(int l, int r, ll val, int u, int s, int e) {
    push(u, s, e);
    if(e < l || s > r)return;
    if(s >= l && e <= r){
      // Update lazy here
      tr[u].lazy += val;
      push(u, s, e);
      return;
    }
    int v = u << 1, w = v | 1, m = (s + e) >> 1;
    update(l, r, val, v, s, m);
    update(l, r, val, w, m + 1, e);
    merge(tr[u], tr[v], tr[w]);
  }
  void update(int p, int u, int s, int e) {
    push(u, s, e);
    if (e < p || s > p) return;
    if (s == e) {
      // Point update
      tr[u].sum = a[u];
      return;
    }
    int v = u << 1, w = v | 1, m = (s + e) >> 1;
    update(p, v, s, m);
    update(p, w, m + 1, e);
    merge(tr[u], tr[v], tr[w]);
  }
  auto query(int l, int r, int u, int s, int e){
    push(u, s, e);
    if(e < l || s > r)return node();
    if(s >= l && e <= r){
      return tr[u];
    }
    int v = u << 1, w = v | 1, m = (s + e) >> 1;
    auto left = query(l, r, v, s, m);
    auto right = query(l, r, w, m + 1, e);
    auto ret = node();
    merge(ret, left, right);
    return ret;
  }
};

void solve() {
  int n;  cin >> n;
  seglazy seg(n + 1);
  for (int i = 0; i < n; i++) {
    cin >> seg.a[i];
  }
  seg.build(1, 0, n - 1);
  int q;  cin >> q;
  while (q--) {
    int t;  cin >> t;
    if (t == 1) {
      int l, r, x;  cin >> l >> r >> x;
      l--, r--;
      seg.update(l, r, x, 1, 0, n - 1);
    } else {
      int l, r; cin >> l >> r;  l--, r--;
      auto res = seg.query(l, r, 1, 0, n - 1);
      cout << res.sum << "\n";
    }
  }
} 

int main() {
  cin.tie(0)->sync_with_stdio(0);
  int t = 1;  cin >> t;
  for (int test = 1; test <= t; test++) {
    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:07:33
Judged At
2025-09-02 16:07:33
Judged By
Score
2
Total Time
7ms
Peak Memory
532.0 KiB