제출 #1314654

#제출 시각아이디문제언어결과실행 시간메모리
1314654joshjuiceFuel Station (NOI20_fuelstation)C++20
100 / 100
288 ms47384 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define rep(x, a, b) for(auto x=a;(a<b?x<b:x>b);(a<b?x++:x--))
#define all(a) a.begin(), a.end()
#define srtvc(a) sort(all(a))
#define bcsrtvc(a) sort(all(a), greater<__typeof__(a[0])>())
#define ppf pop_front
#define ppb pop_back
#define pf push_front
#define pb push_back
#define ef emplace_front
#define eb emplace_back
#define fr first
#define sc second
#define pq priority_queue
#define pii pair<int, int>
#define vc vector
#define dq deque
#define sz(a) a.size()
#define mnto(x,y) x = min(x, (__typeof__(x))y)
#define mxto(x,y) x = max(x, (__typeof__(x))y)
#define setval(arr, x) memset(arr, x, sizeof(arr))

template<typename T>
using vv = vc<vc<T>>;

const int MAXN = 3e5+5;
int arr[MAXN];

struct SegTree {
  struct Node {
    int l, r, mid;
    int val = 0, lz = 0;
    Node *L = nullptr, *R = nullptr;
    Node(int _l, int _r) : l(_l), r(_r) {
      mid = (l + r) >> 1;
      if (l != r) {
        L = new Node(l, mid);
        R = new Node(mid+1, r);
      }
    }
    void apply(int v) {
      val += v;
      lz += v;
    }
    void push() {
      if (lz == 0 || l == r) return;
      L->apply(lz);
      R->apply(lz);
      lz = 0;
    }
    void pull() {
      val = min(L->val, R->val);
    }
    void build() {
      if (l == r) {
        val = arr[l];
        return;
      }
      L->build();
      R->build();
      pull();
    }
    void update(int ql, int qr, int v) {
      if (qr < l || r < ql) return;
      if (ql <= l && r <= qr) {
        apply(v);
        return;
      }
      push();
      L->update(ql, qr, v);
      R->update(ql, qr, v);
      pull();
    }
    int qryMin() { return val; }
  };
  Node* root;
  int n;
  SegTree(int _n) : n(_n) {
    root = new Node(0, n-1);
  }
  void build() { root->build(); }
  void update(int l, int r, int v) { root->update(l, r, v); }
  int qry() { return -root->qryMin(); }
};

int32_t main() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  int n, d;
  cin >> n >> d;
  tuple<int, int, int> st[n];
  rep(i, 0, n) {
    int x, a, b;
    cin >> x >> a >> b;
    st[i] = {x, a, b};
  }
  sort(st, st+n);
  rep(i, 0, n) {
    auto [x, a, b] = st[i];
    arr[i] = -x;
    st[i] = {b, a, i};
  }
  arr[n] = -d;
  sort(st, st+n, greater<>());
  SegTree seg(MAXN);
  seg.build();
  int mn = seg.qry();
  rep(i, 0, n) {
    auto [b, a, ix] = st[i];
    seg.update(ix+1, n, a);
    if (b >= seg.qry()) mnto(mn, seg.qry());
  }
  cout << mn;
}
#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...