Problem p03033 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define all(a) a.begin(), a.end()
#define forn(l, r) for (int i = l; i < (r); ++i)
#define F first
#define S second
#define $ ios::sync_with_stdio(0);
/// #define int long long int

using namespace std;
using namespace __gnu_pbds;
using ll = long long int;
using ii = pair<int, int>;
using li = pair<ll, int>;
using vi = vector<int>;
using graph = vector<vi>;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag,
                         tree_order_statistics_node_update>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll mod = 1000000007;
const int INF = 0x3f3f3f3f;
const int MAXN = 212345;
// const double pi = 3.14159265359;
const double eps = 0.00000001;

pair<ll, pair<ll, ll>> arr[MAXN];
vector<pair<ll, int>> d;
vector<ll> ans;

int32_t main() {

  int n, q;
  cin >> n >> q;
  ans.assign(q, -10);
  ll x;
  ll s, t;
  forn(0, n) {
    scanf("%lld %lld %lld", &s, &t, &x);
    x *= 10ll;
    s *= 10ll;
    t *= 10ll;
    arr[i] = {x, {s - 5ll - x, t - 5ll - x}};
  }
  sort(arr, arr + n);
  set<pair<ll, ll>> st;
  forn(0, q) {
    scanf("%lld", &x);
    x *= 10ll;
    st.insert({x, i});
  }
  set<pair<ll, ll>>::iterator it, kp;
  forn(0, n) {
    if (!st.size())
      break;
    s = arr[i].S.F;
    t = arr[i].S.S;
    x = arr[i].F;
    kp = it = st.lower_bound({s, 0});
    // cout << "X: " << x << ' ' << ' ' << s << ' ' << t << endl;
    while ((*it).F <= t) {
      // cout << (*it).S << ' ';
      ans[(*it).S] = x;
      ++it;
    }
    // cout << endl;
    st.erase(kp, it);
  }
  forn(0, q) { cout << ans[i] / 10ll << '\n'; }
}


Fixed submission:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define all(a) a.begin(), a.end()
#define forn(l, r) for (int i = l; i < (r); ++i)
#define F first
#define S second
#define $ ios::sync_with_stdio(0);
/// #define int long long int

using namespace std;
using namespace __gnu_pbds;
using ll = long long int;
using ii = pair<int, int>;
using li = pair<ll, int>;
using vi = vector<int>;
using graph = vector<vi>;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag,
                         tree_order_statistics_node_update>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll mod = 1000000007;
const int INF = 0x3f3f3f3f;
const int MAXN = 212345;
// const double pi = 3.14159265359;
const double eps = 0.00000001;

pair<ll, pair<ll, ll>> arr[MAXN];
vector<pair<ll, int>> d;
vector<ll> ans;

int32_t main() {

  int n, q;
  cin >> n >> q;
  ans.assign(q, -10);
  ll x;
  ll s, t;
  forn(0, n) {
    scanf("%lld %lld %lld", &s, &t, &x);
    x *= 10ll;
    s *= 10ll;
    t *= 10ll;
    arr[i] = {x, {s - 5ll - x, t - 5ll - x}};
  }
  sort(arr, arr + n);
  set<pair<ll, ll>> st;
  forn(0, q) {
    scanf("%lld", &x);
    x *= 10ll;
    st.insert({x, i});
  }
  set<pair<ll, ll>>::iterator it, kp;
  forn(0, n) {
    if (!st.size())
      break;
    s = arr[i].S.F;
    t = arr[i].S.S;
    x = arr[i].F;
    kp = it = st.lower_bound({s, 0});
    // cout << "X: " << x << ' ' << ' ' << s << ' ' << t << endl;
    while (it != st.end() && (*it).F <= t) {
      // cout << (*it).S << ' ';
      ans[(*it).S] = x;
      ++it;
    }
    // cout << endl;
    st.erase(kp, it);
  }
  forn(0, q) { cout << ans[i] / 10ll << '\n'; }
}