제출 #1340187

#제출 시각아이디문제언어결과실행 시간메모리
1340187avighna푸드 코트 (JOI21_foodcourt)C++20
21 / 100
426 ms39796 KiB
#include <bits/stdc++.h>

using namespace std;

// we'll support operations like a[i] = max(a[i] + s, m)
// let this be (s, m)
// then if we have (s1, m1) and then (s2, m2), that is
// max(a[i] + s1 + s2, max(m1 + s2, m2))

// so (s1, m1) then (s2, m2) => (s1 + s2, max(m1 + s2, m2))

// also if we have max over i max(a[i] + s, m)
// max((max over i (a[i])) + s, m)

template <typename T>
class lazy_segment_tree {
private:
  struct op {
    T s, m;
    op operator+(const op &other) {
      return op{s + other.s, max(m + other.s, other.m)};
    }
  };
  int n;
  vector<T> seg;
  vector<op> lazy;
  static const T idt = numeric_limits<T>::min() >> 2;

public:
  lazy_segment_tree(int n) : n(n), seg(4 * n), lazy(8 * n, {0, idt}) {}

  void push(int v, int tl, int tr) {
    seg[v] = max(seg[v] + lazy[v].s, lazy[v].m);
    lazy[2 * v] = lazy[2 * v] + lazy[v];
    lazy[2 * v + 1] = lazy[2 * v + 1] + lazy[v];
    lazy[v] = {0, idt};
  }

  void add(int v, int tl, int tr, int l, int r, T del) {
    push(v, tl, tr);
    if (tr < l || r < tl) {
      return;
    }
    if (l <= tl && tr <= r) {
      lazy[v] = lazy[v] + op{del, idt};
      push(v, tl, tr);
      return;
    }
    int tm = (tl + tr) / 2;
    add(2 * v, tl, tm, l, r, del);
    add(2 * v + 1, tm + 1, tr, l, r, del);
    seg[v] = max(seg[2 * v], seg[2 * v + 1]);
  }
  void add(int l, int r, T del) { add(1, 0, n - 1, l, r, del); }

  void chmax(int v, int tl, int tr, int l, int r) {
    push(v, tl, tr);
    if (tr < l || r < tl) {
      return;
    }
    if (l <= tl && tr <= r) {
      lazy[v] = lazy[v] + op{0, 0};
      push(v, tl, tr);
      return;
    }
    int tm = (tl + tr) / 2;
    chmax(2 * v, tl, tm, l, r);
    chmax(2 * v + 1, tm + 1, tr, l, r);
    seg[v] = max(seg[2 * v], seg[2 * v + 1]);
  }
  void chmax(int l, int r) { chmax(1, 0, n - 1, l, r); }

  T query(int v, int tl, int tr, int idx) {
    push(v, tl, tr);
    if (tr < idx || idx < tl) {
      return idt;
    }
    if (idx <= tl && tr <= idx) {
      return seg[v];
    }
    int tm = (tl + tr) / 2;
    return max(query(2 * v, tl, tm, idx), query(2 * v + 1, tm + 1, tr, idx));
  }
  T query(int idx) { return query(1, 0, n - 1, idx); }
};

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int n, m, q;
  cin >> n >> m >> q;

  lazy_segment_tree<int64_t> st(n);
  while (q--) {
    int t;
    cin >> t;
    if (t == 1) {
      int64_t l, r, c, k;
      cin >> l >> r >> c >> k;
      --l, --r;
      st.add(l, r, k);
    } else if (t == 2) {
      int64_t l, r, k;
      cin >> l >> r >> k;
      --l, --r;
      st.add(l, r, -k);
      st.chmax(l, r);
    } else {
      int64_t a, b;
      cin >> a >> b;
      --a, --b;
      int64_t sz = st.query(a);
      if (b < sz) {
        cout << "1\n";
      } else {
        cout << "0\n";
      }
    }
  }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...