Problem p03033 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout << (s) << endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void vprint(vector<ll> A) {
  ll L = A.size();
  FOR(i, 0, L) {
    if (i)
      cout << ' ';
    cout << A[i];
  }
  cout << endl;
}

struct Work {
  ll s;
  ll t;
  ll x;

  bool operator<(const Work &another) const { return x < another.x; }

  Work(ll _s, ll _t, ll _x) {
    s = _s;
    t = _t;
    x = _x;
  }
};

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

  // input
  ll N, Q;
  cin >> N >> Q;

  vector<Work> W;
  FOR(i, 0, N) {
    ll s, t, x;
    cin >> s >> t >> x;
    s -= x;
    t -= x;
    W.push_back(Work(s, t, x));
  }
  sort(ALL(W));

  vector<ll> Ans(Q, -1);

  set<pair<ll, ll>> se;
  FOR(i, 0, Q) {
    ll d;
    cin >> d;
    se.insert(make_pair(d, i));
  }

  FOR(i, 0, N) {
    auto work = W[i];
    auto it = se.lower_bound(make_pair(work.s, 0));
    while (it->first < work.t) {
      Ans[it->second] = work.x; // id
      se.erase(it++);
    }
  }

  for (ll ans : Ans) {
    p(ans);
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}

#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout << (s) << endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void vprint(vector<ll> A) {
  ll L = A.size();
  FOR(i, 0, L) {
    if (i)
      cout << ' ';
    cout << A[i];
  }
  cout << endl;
}

struct Work {
  ll s;
  ll t;
  ll x;

  bool operator<(const Work &another) const { return x < another.x; }

  Work(ll _s, ll _t, ll _x) {
    s = _s;
    t = _t;
    x = _x;
  }
};

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

  // input
  ll N, Q;
  cin >> N >> Q;

  vector<Work> W;
  FOR(i, 0, N) {
    ll s, t, x;
    cin >> s >> t >> x;
    s -= x;
    t -= x;
    W.push_back(Work(s, t, x));
  }
  sort(ALL(W));

  vector<ll> Ans(Q, -1);

  set<pair<ll, ll>> se;
  FOR(i, 0, Q) {
    ll d;
    cin >> d;
    se.insert(make_pair(d, i));
  }

  FOR(i, 0, N) {
    auto work = W[i];
    auto it = se.lower_bound(make_pair(work.s, 0));
    while (it != se.end() && it->first < work.t) {
      Ans[it->second] = work.x; // id
      se.erase(it++);
    }
  }

  for (ll ans : Ans) {
    p(ans);
  }

  return 0;
}