Problem p02758 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

class DebugStream {
} LOG;
template <typename T> DebugStream &operator<<(DebugStream &s, const T &) {
  return s;
}
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 998244353, SQ = 335, lg = 20,
          bs = 29;

int T[maxN << 1], n;

int query(int l, int r) {
  int ret = 0;
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l & 1)
      ret = max(ret, T[l++]);
    if (r & 1)
      ret = max(ret, T[--r]);
  }
  return ret;
}

void update(int w, int x) {
  w += n;
  T[w] = x;
  while (w > 1) {
    w >>= 1;
    T[w] = max(T[w << 1], T[w << 1 | 1]);
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
#ifdef DEBUG
  freopen("input.txt", "r", stdin);
#endif

  cin >> n;
  vector<ii> arr(n);
  for (int i = 0; i < n; i++)
    cin >> arr[i].fi >> arr[i].se;
  sort(arr.begin(), arr.end());

  vector<int> xs(n), ds(n), reach(n), wys(n + 1);
  for (int i = 0; i < n; i++)
    xs[i] = arr[i].fi, ds[i] = arr[i].se;

  for (int i = n - 1; i >= 0; i--) {
    int lm = int(lower_bound(xs.begin(), xs.end(), xs[i] + ds[i]) - xs.begin());
    lm = max(lm, query(i + 1, lm));
    reach[i] = lm;
    update(i, lm);
  }

  wys[n] = 1;
  for (int i = n - 1; i >= 0; i--)
    wys[i] = (wys[i + 1] + wys[reach[i]]) % MOD;
  cout << wys[0] << '\n';
}


Fixed submission:
#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

class DebugStream {
} LOG;
template <typename T> DebugStream &operator<<(DebugStream &s, const T &) {
  return s;
}
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 2e5 + 9, maxV = 1e6 + 9, MOD = 998244353, SQ = 335, lg = 20,
          bs = 29;

int T[maxN << 1], n;

int query(int l, int r) {
  int ret = 0;
  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
    if (l & 1)
      ret = max(ret, T[l++]);
    if (r & 1)
      ret = max(ret, T[--r]);
  }
  return ret;
}

void update(int w, int x) {
  w += n;
  T[w] = x;
  while (w > 1) {
    w >>= 1;
    T[w] = max(T[w << 1], T[w << 1 | 1]);
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
#ifdef DEBUG
  freopen("input.txt", "r", stdin);
#endif

  cin >> n;
  vector<ii> arr(n);
  for (int i = 0; i < n; i++)
    cin >> arr[i].fi >> arr[i].se;
  sort(arr.begin(), arr.end());

  vector<int> xs(n), ds(n), reach(n), wys(n + 1);
  for (int i = 0; i < n; i++)
    xs[i] = arr[i].fi, ds[i] = arr[i].se;

  for (int i = n - 1; i >= 0; i--) {
    int lm = int(lower_bound(xs.begin(), xs.end(), xs[i] + ds[i]) - xs.begin());
    lm = max(lm, query(i + 1, lm));
    reach[i] = lm;
    update(i, lm);
  }

  wys[n] = 1;
  for (int i = n - 1; i >= 0; i--)
    wys[i] = (wys[i + 1] + wys[reach[i]]) % MOD;
  cout << wys[0] << '\n';
}