Problem p02758 (C++)

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

using ll = long long int;
using P = std::pair<int, int>;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rag(con) std::begin(con), std::end(con)

constexpr ll mod = 998244353;

ll pow(ll x, ll m) {

  ll re = 1, y = 1;

  for (int i = 0; i < 60; ++i) {
    if (m & y)
      re = re * x % mod;
    x = x * x % mod;
    y *= 2;
  }

  return re;
}

ll inv(ll x) { return pow(x, mod - 2); }

class mint {
  ll num = 0;

public:
  mint(ll x = 0) : num(x) {}

  mint operator+(const mint &rhs) const { return (num + rhs.num) % mod; }
  mint operator*(const mint &rhs) const { return num * rhs.num % mod; }
  mint operator-(const mint &rhs) const { return (num - rhs.num + mod) % mod; }
  mint operator/(const mint &rhs) const { return num * inv(rhs.num) % mod; }
  mint operator+=(const mint &rhs) { return *this = *this + rhs; }
  mint operator*=(const mint &rhs) { return *this = *this * rhs; }
  mint operator-=(const mint &rhs) { return *this - *this / rhs; }
  mint operator/=(const mint &rhs) { return *this = *this / rhs; }
  friend std::ostream &operator<<(std::ostream &os, const mint &rhs);
};

std::ostream &operator<<(std::ostream &os, const mint &rhs) {

  os << rhs.num;

  return os;
}

constexpr int MAX = 2 * 1e5 + 5;

mint dp[MAX];

constexpr int INF = 2 * 1e9 + 1;

int next[MAX];

std::vector<int> xs;
std::vector<P> ps;

int n;

int dfs(int v) {

  int m =
      std::lower_bound(rag(xs), ps[v].first + ps[v].second) - std::begin(xs);

  int res = v + 1;

  for (int i = v + 1; i < m; ++i) {
    if (res == n)
      return next[v] = res;
    res = std::max(res, dfs(i));
  }

  return next[v] = res;
}

int main() {

  std::cin >> n;

  ps.resize(n);
  xs.resize(n + 1);

  rep(i, n) {
    std::cin >> ps[i].first >> ps[i].second;
    xs[i] = ps[i].first;
  }
  xs[n] = INF;
  std::sort(rag(xs));
  std::sort(rag(ps));

  dp[n] = 1;

  for (int i = n - 1; i >= 0; --i) {
    dp[i] = dp[dfs(i)] + dp[i + 1];
    // std::cerr << dp[i] << std::endl;
  }

  std::cout << dp[0] << std::endl;

  return 0;
}

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

using ll = long long int;
using P = std::pair<int, int>;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rag(con) std::begin(con), std::end(con)

constexpr ll mod = 998244353;

ll pow(ll x, ll m) {

  ll re = 1, y = 1;

  for (int i = 0; i < 60; ++i) {
    if (m & y)
      re = re * x % mod;
    x = x * x % mod;
    y *= 2;
  }

  return re;
}

ll inv(ll x) { return pow(x, mod - 2); }

class mint {
  ll num = 0;

public:
  mint(ll x = 0) : num(x) {}

  mint operator+(const mint &rhs) const { return (num + rhs.num) % mod; }
  mint operator*(const mint &rhs) const { return num * rhs.num % mod; }
  mint operator-(const mint &rhs) const { return (num - rhs.num + mod) % mod; }
  mint operator/(const mint &rhs) const { return num * inv(rhs.num) % mod; }
  mint operator+=(const mint &rhs) { return *this = *this + rhs; }
  mint operator*=(const mint &rhs) { return *this = *this * rhs; }
  mint operator-=(const mint &rhs) { return *this - *this / rhs; }
  mint operator/=(const mint &rhs) { return *this = *this / rhs; }
  friend std::ostream &operator<<(std::ostream &os, const mint &rhs);
};

std::ostream &operator<<(std::ostream &os, const mint &rhs) {

  os << rhs.num;

  return os;
}

constexpr int MAX = 2 * 1e5 + 5;

mint dp[MAX];

constexpr int INF = 2 * 1e9 + 1;

int next[MAX];

std::vector<int> xs;
std::vector<P> ps;

int n;

int dfs(int v) {
  if (next[v] > 0)
    return next[v];

  int m =
      std::lower_bound(rag(xs), ps[v].first + ps[v].second) - std::begin(xs);

  int res = v + 1;

  for (int i = v + 1; i < m; ++i) {
    if (res == n)
      return next[v] = res;
    res = std::max(res, dfs(i));
  }

  return next[v] = res;
}

int main() {

  std::cin >> n;

  ps.resize(n);
  xs.resize(n + 1);

  rep(i, n) {
    std::cin >> ps[i].first >> ps[i].second;
    xs[i] = ps[i].first;
  }
  xs[n] = INF;
  std::sort(rag(xs));
  std::sort(rag(ps));

  dp[n] = 1;

  for (int i = n - 1; i >= 0; --i) {
    dp[i] = dp[dfs(i)] + dp[i + 1];
    // std::cerr << dp[i] << std::endl;
  }

  std::cout << dp[0] << std::endl;

  return 0;
}