/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 336.0 KiB
#2 Wrong Answer 7ms 616.0 KiB
#3 Wrong Answer 7ms 532.0 KiB

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 * (r - l + 1);
  }
  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:27:54
Judged At
2025-09-02 16:27:54
Judged By
Score
2
Total Time
7ms
Peak Memory
616.0 KiB