Problem p03033 (C++)

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

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
// #define MOD 998244353
#define MEM_SIZE 100010
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template <typename T> void DEBUG(T e) {
  if (DEBUG_OUT == false)
    return;
  std::cout << e << " ";
}
template <typename T> void DEBUG(const std::vector<T> &v) {
  if (DEBUG_OUT == false)
    return;
  for (const auto &e : v) {
    std::cout << e << " ";
  }
  std::cout << std::endl;
}
template <typename T> void DEBUG(const std::vector<std::vector<T>> &vv) {
  if (DEBUG_OUT == false)
    return;
  for (const auto &v : vv) {
    DEBUG(v);
  }
}
template <class T, class... Ts> void DEBUG(T d, Ts... e) {
  if (DEBUG_OUT == false)
    return;
  DEBUG(d);
  DEBUG(e...);
}
template <class T> void corner(bool flg, T hoge) {
  if (flg) {
    cout << hoge << endl;
    abort();
  }
}
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}

void solve(void) {
  int N, Q;
  cin >> N;
  cin >> Q;
  vector<tuple<int, int, int>> event;
  for (int i = 0; i < N; i++) {
    int S, T, X;
    cin >> S >> T >> X;
    event.emplace_back(S - X, 1, X);
    event.emplace_back(T - X, -1, X);
  }
  vector<int> D(Q);
  for (int i = 0; i < Q; i++) {
    cin >> D[i];
  }

  sort(ALL(event));
  vector<int> ANS(N);
  set<int> se;
  int t = 0;
  int id = 0;
  for (int i = 0; i < Q; i++) {
    t = D[i];
    for (; id < (int)event.size() && get<0>(event[id]) <= t; id++) {
      if (get<1>(event[id]) == 1) {
        se.insert(get<2>(event[id]));
      } else {
        se.erase(get<2>(event[id]));
      }
    }
    if (se.empty()) {
      ANS[i] = -1;
    } else {
      ANS[i] = *se.begin();
    }

    // DEBUG(ANS);
  }
  for (int i = 0; i < Q; i++) {
    cout << ANS[i] << endl;
  }

  return;
}
int32_t main(int32_t argc, const char *argv[]) {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}


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

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
// #define MOD 998244353
#define MEM_SIZE 100010
#define DEBUG_OUT true
#define ALL(x) (x).begin(), (x).end()

template <typename T> void DEBUG(T e) {
  if (DEBUG_OUT == false)
    return;
  std::cout << e << " ";
}
template <typename T> void DEBUG(const std::vector<T> &v) {
  if (DEBUG_OUT == false)
    return;
  for (const auto &e : v) {
    std::cout << e << " ";
  }
  std::cout << std::endl;
}
template <typename T> void DEBUG(const std::vector<std::vector<T>> &vv) {
  if (DEBUG_OUT == false)
    return;
  for (const auto &v : vv) {
    DEBUG(v);
  }
}
template <class T, class... Ts> void DEBUG(T d, Ts... e) {
  if (DEBUG_OUT == false)
    return;
  DEBUG(d);
  DEBUG(e...);
}
template <class T> void corner(bool flg, T hoge) {
  if (flg) {
    cout << hoge << endl;
    abort();
  }
}
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}

void solve(void) {
  int N, Q;
  cin >> N;
  cin >> Q;
  vector<tuple<int, int, int>> event;
  for (int i = 0; i < N; i++) {
    int S, T, X;
    cin >> S >> T >> X;
    event.emplace_back(S - X, 1, X);
    event.emplace_back(T - X, -1, X);
  }
  vector<int> D(Q);
  for (int i = 0; i < Q; i++) {
    cin >> D[i];
  }

  sort(ALL(event));
  vector<int> ANS(Q);
  set<int> se;
  int t = 0;
  int id = 0;
  for (int i = 0; i < Q; i++) {
    t = D[i];
    for (; id < (int)event.size() && get<0>(event[id]) <= t; id++) {
      if (get<1>(event[id]) == 1) {
        se.insert(get<2>(event[id]));
      } else {
        se.erase(get<2>(event[id]));
      }
    }
    if (se.empty()) {
      ANS[i] = -1;
    } else {
      ANS[i] = *se.begin();
    }

    // DEBUG(ANS);
  }
  for (int i = 0; i < Q; i++) {
    cout << ANS[i] << endl;
  }

  return;
}
int32_t main(int32_t argc, const char *argv[]) {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(11);
  solve();

  return 0;
}