Problem p03033 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = (1 << 30);
constexpr ll L_INF = (1ll << 62);

//==================================

inline int get_iter(const Vl &vec, ll x) {
  return lower_bound(vec.begin(), vec.end(), x) - vec.begin();
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ifstream ifs("input.txt");
  cin.rdbuf(ifs.rdbuf());

  ll N, Q;
  cin >> N >> Q;
  Vl S(N), T(N), X(N);
  for (int i = 0; i < N; ++i) {
    cin >> S[i] >> T[i] >> X[i];
  }
  Vl D(Q);
  for (int i = 0; i < Q; ++i) {
    cin >> D[i];
  }

  Vl poss(N * 2);
  for (int i = 0; i < N; ++i) {
    poss[i * 2] = S[i] - X[i];
    poss[i * 2 + 1] = T[i] - X[i];
  }
  sort(poss.begin(), poss.end());
  poss.erase(unique(poss.begin(), poss.end()), poss.end());

  int lenPoss = (int)poss.size();

  vector<Vl> inval(lenPoss), outval(lenPoss);
  for (int i = 0; i < N; ++i) {
    inval[get_iter(poss, S[i] - X[i])].push_back(X[i]);
    outval[get_iter(poss, T[i] - X[i])].push_back(X[i]);
  }

  Vl dmins(lenPoss);
  multiset<ll> ms;
  for (int i = 0; i < lenPoss; ++i) {
    for (const auto &v : outval[i]) {
      auto itr = ms.find(v);
      if (itr != ms.end())
        ms.erase(itr);
    }

    for (const auto &v : inval[i]) {
      ms.insert(v);
    }

    if (ms.empty())
      dmins[i] = L_INF;
    else
      dmins[i] = *ms.begin();
  }

  for (int i = 0; i < Q; ++i) {
    int idx = upper_bound(poss.begin(), poss.end(), D[i]) - poss.begin() - 1;
    if (idx < 0 || idx >= lenPoss) {
      cout << -1 << "\n";
    } else {
      if (dmins[idx] == L_INF) {
        cout << -1 << "\n";
      } else {
        cout << dmins[idx] << "\n";
      }
    }
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = (1 << 30);
constexpr ll L_INF = (1ll << 62);

//==================================

inline int get_iter(const Vl &vec, ll x) {
  return lower_bound(vec.begin(), vec.end(), x) - vec.begin();
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll N, Q;
  cin >> N >> Q;
  Vl S(N), T(N), X(N);
  for (int i = 0; i < N; ++i) {
    cin >> S[i] >> T[i] >> X[i];
  }
  Vl D(Q);
  for (int i = 0; i < Q; ++i) {
    cin >> D[i];
  }

  Vl poss(N * 2);
  for (int i = 0; i < N; ++i) {
    poss[i * 2] = S[i] - X[i];
    poss[i * 2 + 1] = T[i] - X[i];
  }
  sort(poss.begin(), poss.end());
  poss.erase(unique(poss.begin(), poss.end()), poss.end());

  int lenPoss = (int)poss.size();

  vector<Vl> inval(lenPoss), outval(lenPoss);
  for (int i = 0; i < N; ++i) {
    inval[get_iter(poss, S[i] - X[i])].push_back(X[i]);
    outval[get_iter(poss, T[i] - X[i])].push_back(X[i]);
  }

  Vl dmins(lenPoss);
  multiset<ll> ms;
  for (int i = 0; i < lenPoss; ++i) {
    for (const auto &v : outval[i]) {
      auto itr = ms.find(v);
      if (itr != ms.end())
        ms.erase(itr);
    }

    for (const auto &v : inval[i]) {
      ms.insert(v);
    }

    if (ms.empty())
      dmins[i] = L_INF;
    else
      dmins[i] = *ms.begin();
  }

  for (int i = 0; i < Q; ++i) {
    int idx = upper_bound(poss.begin(), poss.end(), D[i]) - poss.begin() - 1;
    if (idx < 0 || idx >= lenPoss) {
      cout << -1 << "\n";
    } else {
      if (dmins[idx] == L_INF) {
        cout << -1 << "\n";
      } else {
        cout << dmins[idx] << "\n";
      }
    }
  }

  return 0;
}